Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make flag order deterministic for helm's --setFiles #4779

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions pkg/skaffold/deploy/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,20 +548,15 @@ func installArgs(r latest.HelmRelease, builds []build.Artifact, valuesSet map[st

// constructOverrideArgs creates the command line arguments for overrides
func constructOverrideArgs(r *latest.HelmRelease, builds []build.Artifact, args []string, record func(string)) ([]string, error) {
sortedKeys := make([]string, 0, len(r.SetValues))
for k := range r.SetValues {
sortedKeys = append(sortedKeys, k)
}
sort.Strings(sortedKeys)
for _, k := range sortedKeys {
for _, k := range sortKeys(r.SetValues) {
record(r.SetValues[k])
args = append(args, "--set", fmt.Sprintf("%s=%s", k, r.SetValues[k]))
}

for k, v := range r.SetFiles {
exp, err := homedir.Expand(v)
for _, k := range sortKeys(r.SetFiles) {
exp, err := homedir.Expand(r.SetFiles[k])
if err != nil {
return nil, fmt.Errorf("unable to expand %q: %w", v, err)
return nil, fmt.Errorf("unable to expand %q: %w", r.SetFiles[k], err)
}
record(exp)
args = append(args, "--set-file", fmt.Sprintf("%s=%s", k, exp))
Expand All @@ -580,12 +575,7 @@ func constructOverrideArgs(r *latest.HelmRelease, builds []build.Artifact, args
}
logrus.Debugf("EnvVarMap: %+v\n", envMap)

sortedKeys = make([]string, 0, len(r.SetValueTemplates))
for k := range r.SetValueTemplates {
sortedKeys = append(sortedKeys, k)
}
sort.Strings(sortedKeys)
for _, k := range sortedKeys {
for _, k := range sortKeys(r.SetValueTemplates) {
v, err := util.ExpandEnvTemplate(r.SetValueTemplates[k], envMap)
if err != nil {
return nil, err
Expand All @@ -611,6 +601,16 @@ func constructOverrideArgs(r *latest.HelmRelease, builds []build.Artifact, args
return args, nil
}

// sortKeys returns the map keys in sorted order
func sortKeys(m map[string]string) []string {
s := make([]string, 0, len(m))
for k := range m {
s = append(s, k)
}
sort.Strings(s)
return s
}

// getArgs calculates the correct arguments to "helm get"
func getArgs(v semver.Version, releaseName string, namespace string) []string {
args := []string{"get"}
Expand Down