Skip to content

Commit

Permalink
Merge pull request #2895 from marti1125/2678
Browse files Browse the repository at this point in the history
 Add `setFiles` to `HelmDeploy.HelmRelease` skaffold config which will be add `--set-files` argument to helm CLI
  • Loading branch information
tejal29 authored Sep 24, 2019
2 parents 4af79d5 + 23d0519 commit 885827d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/content/en/schemas/v1beta15.json
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,15 @@
"x-intellij-html-description": "specifies whether the chart path is remote, or exists on the host filesystem. <code>remote: true</code> implies <code>skipBuildDependencies: true</code>.",
"default": "false"
},
"setFiles": {
"additionalProperties": {
"type": "string"
},
"type": "object",
"description": "key-value pairs. If present, Skaffold will send `--set-file` flag to Helm CLI and append all pairs after the flag.",
"x-intellij-html-description": "key-value pairs. If present, Skaffold will send <code>--set-file</code> flag to Helm CLI and append all pairs after the flag.",
"default": "{}"
},
"setValueTemplates": {
"additionalProperties": {
"type": "string"
Expand Down Expand Up @@ -1148,6 +1157,7 @@
"version",
"setValues",
"setValueTemplates",
"setFiles",
"wait",
"recreatePods",
"skipBuildDependencies",
Expand Down
12 changes: 12 additions & 0 deletions pkg/skaffold/deploy/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ func (h *HelmDeployer) deployRelease(ctx context.Context, out io.Writer, r lates
args = append(args, "--set", fmt.Sprintf("%s=%s", k, v))
}

// SetFiles
args = append(args, generateGetFilesArgs(r.SetFiles, valuesSet)...)

envMap := map[string]string{}
for idx, b := range builds {
suffix := ""
Expand Down Expand Up @@ -461,6 +464,15 @@ func (h *HelmDeployer) joinTagsToBuildResult(builds []build.Artifact, params map
return paramToBuildResult, nil
}

func generateGetFilesArgs(m map[string]string, valuesSet map[string]bool) []string {
args := make([]string, 0, len(m))
for k, v := range m {
valuesSet[v] = true
args = append(args, "--set-file", fmt.Sprintf("%s=%s", k, v))
}
return args
}

func (h *HelmDeployer) Render(context.Context, io.Writer, []build.Artifact, string) error {
return errors.New("not yet implemented")
}
Expand Down
47 changes: 47 additions & 0 deletions pkg/skaffold/deploy/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,53 @@ func TestHelmRender(t *testing.T) {
}
}

func TestGetSetFileValues(t *testing.T) {
tests := []struct {
description string
files map[string]string
expected []string
expectedMap map[string]bool
}{
{
description: "multiple value",
files: map[string]string{
"multiline_text": "path/to/textfile",
"another_file": "path/to/another",
},
expected: []string{
"--set-file",
"multiline_text=path/to/textfile",
"--set-file",
"another_file=path/to/another",
},
expectedMap: map[string]bool{
"path/to/textfile": true,
"path/to/another": true,
},
},
{
description: "empty value",
files: map[string]string{},
expected: []string{},
expectedMap: map[string]bool{},
},
{
description: "nil",
files: nil,
expected: []string{},
expectedMap: map[string]bool{},
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
inMap := map[string]bool{}
actual := generateGetFilesArgs(test.files, inMap)
t.CheckDeepEqual(test.expected, actual)
t.CheckDeepEqual(test.expectedMap, inMap)
})
}
}

func makeRunContext(deploy latest.HelmDeploy, force bool) *runcontext.RunContext {
pipeline := latest.Pipeline{}
pipeline.Deploy.DeployType.HelmDeploy = &deploy
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ type HelmRelease struct {
// all parsed pairs after the flag.
SetValueTemplates map[string]string `yaml:"setValueTemplates,omitempty"`

// SetFiles are key-value pairs.
// If present, Skaffold will send `--set-file` flag to Helm CLI and append all pairs after the flag.
SetFiles map[string]string `yaml:"setFiles,omitempty"`

// Wait if `true`, Skaffold will send `--wait` flag to Helm CLI.
// Defaults to `false`.
Wait bool `yaml:"wait,omitempty"`
Expand Down

0 comments on commit 885827d

Please sign in to comment.