Skip to content

Commit c2c1385

Browse files
committed
add initCommand to git plugin
1 parent 3b08812 commit c2c1385

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

config/samples/cs_v1alpha1_codeserverdeployment.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ metadata:
99
app.kubernetes.io/created-by: code-server-operator
1010
name: codeserverdeployment-sample
1111
spec:
12-
replicas: 3
12+
replicas: 2
1313
template:
1414
spec:
1515
storageSize: 512Mi
1616
initPlugins:
1717
git:
1818
repourl: "github.com/walnuts1018/http-dump"
1919
branch: "master"
20+
initCommand: "go mod download"
2021
copyDefaultConfig: {}
2122
copyHome: {}
2223
envs:

internal/initplugins/gitplugin/gitplugin.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import (
99
)
1010

1111
type gitPlugin struct {
12-
Repourl string `required:"true" json:"repourl"`
13-
Branch string `json:"branch"`
14-
VolumeName string `required:"true" json:"volumeName"`
12+
Repourl string `required:"true" json:"repourl"`
13+
Branch string `json:"branch"`
14+
VolumeName string `required:"true" json:"volumeName"`
15+
InitCommand string `json:"initCommand"`
1516
}
1617

1718
func New(params map[string]string) (common.PluginInterface, error) {
@@ -32,14 +33,17 @@ func New(params map[string]string) (common.PluginInterface, error) {
3233
}
3334

3435
func (g *gitPlugin) GenerateInitContainerApplyConfiguration() *corev1apply.ContainerApplyConfiguration {
35-
command := `
36+
initCommand := fmt.Sprintf("cd /persistent/work && %v", g.InitCommand)
37+
38+
command := fmt.Sprintf(`
3639
if [ ! -d /persistent/work ]; then
3740
mkdir -p /persistent/work;
38-
git clone -b ` + g.Branch + ` ` + g.Repourl + ` /persistent/work;
41+
git clone -b `+g.Branch+` `+g.Repourl+` /persistent/work;
42+
%v
3943
else
4044
echo 'work directory already exists';
4145
fi
42-
`
46+
`, initCommand)
4347

4448
initcontainer := corev1apply.Container().
4549
WithName("git").

0 commit comments

Comments
 (0)