diff --git a/pkg/skaffold/deploy/helm.go b/pkg/skaffold/deploy/helm.go index f75fd58baef..9d80e4eda03 100644 --- a/pkg/skaffold/deploy/helm.go +++ b/pkg/skaffold/deploy/helm.go @@ -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)) @@ -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 @@ -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"}