Skip to content

Commit

Permalink
Make flag order deterministic for helm's --setFiles (#4779)
Browse files Browse the repository at this point in the history
* Fix flaky helm UT

* remove duplicate code
  • Loading branch information
gsquared94 authored Sep 14, 2020
1 parent 4ab605b commit 990b0cb
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions pkg/skaffold/deploy/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,20 +556,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 @@ -588,12 +583,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 @@ -619,6 +609,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

0 comments on commit 990b0cb

Please sign in to comment.