diff --git a/util/helm/helm.go b/util/helm/helm.go index e5e3c5e9f999e..2c93ceab08a74 100644 --- a/util/helm/helm.go +++ b/util/helm/helm.go @@ -78,6 +78,7 @@ func (h *helm) Template(appName, namespace, kubeVersion string, opts *argoappv1. } templateOpts.values = append(templateOpts.values, p) } + cleanHelmParameters(opts.Parameters) for _, p := range opts.Parameters { if p.ForceString { templateOpts.setString[p.Name] = p.Value @@ -183,9 +184,13 @@ func flatVals(input map[string]interface{}, output map[string]string, prefixes . } } -func cleanHelmParameters(params []string) { +func cleanHelmParameters(params []argoappv1.HelmParameter) { re := regexp.MustCompile(`([^\\]),`) for i, param := range params { - params[i] = re.ReplaceAllString(param, `$1\,`) + params[i] = argoappv1.HelmParameter{ + Name: param.Name, + Value: re.ReplaceAllString(param.Value, `$1\,`), + ForceString: param.ForceString, + } } } diff --git a/util/helm/helm_test.go b/util/helm/helm_test.go index eb91efede14ef..4356477a3b127 100644 --- a/util/helm/helm_test.go +++ b/util/helm/helm_test.go @@ -170,21 +170,28 @@ func TestHelmTemplateReleaseName(t *testing.T) { } func TestHelmArgCleaner(t *testing.T) { - cleanArgs := []string{`--these-args`, `are-clean`, `--foo`, `bar`} - argsToBeCleaned := make([]string, len(cleanArgs)) + cleanArgs := []argoappv1.HelmParameter{ + {Name: "app", Value: `val`, ForceString: true}, + {Name: "foo", Value: `bar`, ForceString: false}, + } + argsToBeCleaned := make([]argoappv1.HelmParameter, len(cleanArgs)) copy(argsToBeCleaned, cleanArgs) cleanHelmParameters(argsToBeCleaned) - assert.Equal(t, cleanArgs, argsToBeCleaned) + assert.EqualValues(t, cleanArgs, argsToBeCleaned) - dirtyArgs := []string{`--these-args`, `are-not, clean`, `--foo`, `b\,a,r`} - argsToBeCleaned = make([]string, len(dirtyArgs)) + dirtyArgs := []argoappv1.HelmParameter{ + {Name: "app", Value: `val`, ForceString: true}, + {Name: "test", Value: `not, clean`, ForceString: false}, + {Name: "foo", Value: `a\,b,c`, ForceString: true}, + } + argsToBeCleaned = make([]argoappv1.HelmParameter, len(dirtyArgs)) copy(argsToBeCleaned, dirtyArgs) cleanHelmParameters(argsToBeCleaned) - assert.NotEqual(t, cleanArgs, argsToBeCleaned) - assert.Contains(t, argsToBeCleaned, `are-not\, clean`) - assert.Contains(t, argsToBeCleaned, `b\,a\,r`) + assert.False(t, assert.ObjectsAreEqualValues(cleanArgs, argsToBeCleaned)) + assert.Contains(t, argsToBeCleaned, argoappv1.HelmParameter{Name: "test", Value: `not\, clean`, ForceString: false}) + assert.Contains(t, argsToBeCleaned, argoappv1.HelmParameter{Name: "foo", Value: `a\,b\,c`, ForceString: true}) }