diff --git a/pkg/config/config.go b/pkg/config/config.go index 7bfe1aca..f49ec705 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -1,21 +1,23 @@ package config import ( + "regexp" "strings" "github.com/helmfile/helmfile/pkg/maputil" ) func NewCLIConfigImpl(g *GlobalImpl) error { + re := regexp.MustCompile(`(?:,|^)([^\s=]+)=(['"][^'"]*['"]|[^,]+)`) optsSet := g.RawStateValuesSetString() if len(optsSet) > 0 { set := map[string]any{} for i := range optsSet { - ops := strings.Split(optsSet[i], ",") + ops := re.FindAllStringSubmatch(optsSet[i], -1) for j := range ops { - op := strings.SplitN(ops[j], "=", 2) - k := maputil.ParseKey(op[0]) - v := op[1] + op := ops[j] + k := maputil.ParseKey(op[1]) + v := op[2] maputil.Set(set, k, v, true) } diff --git a/test/integration/test-cases/cli-overwrite-environment-values.sh b/test/integration/test-cases/cli-overwrite-environment-values.sh index 2835b849..48d9f2de 100644 --- a/test/integration/test-cases/cli-overwrite-environment-values.sh +++ b/test/integration/test-cases/cli-overwrite-environment-values.sh @@ -11,7 +11,7 @@ if [[ ${HELMFILE_V1MODE} = true ]]; then info "Comparing ${case_title} for v1 output ${cli_overwrite_environment_values_reverse} with ${cli_overwrite_environment_values_output_dir}/overwritten.yaml" for i in $(seq 10); do info "Comparing build/cli-overwrite-environment-values #$i" - ${helmfile} -f ${cli_overwrite_environment_values_input_dir}/input_v1.yaml.gotmpl template --state-values-set ns=test3 > ${cli_overwrite_environment_values_reverse} || fail "\"helmfile template\" shouldn't fail" + ${helmfile} -f ${cli_overwrite_environment_values_input_dir}/input_v1.yaml.gotmpl template --state-values-set ns=test3 --state-values-set-string imageTag=1.23.3,zone="zone1,zone2" > ${cli_overwrite_environment_values_reverse} || fail "\"helmfile template\" shouldn't fail" diff -u ${cli_overwrite_environment_values_output_dir}/output_v1.yaml ${cli_overwrite_environment_values_reverse} || fail "\"helmfile template\" should be consistent" echo code=$? done @@ -21,9 +21,9 @@ else info "Comparing ${case_title} output ${cli_overwrite_environment_values_reverse} with ${cli_overwrite_environment_values_output_dir}/overwritten.yaml" for i in $(seq 10); do info "Comparing build/cli-overwrite-environment-values #$i" - ${helmfile} -f ${cli_overwrite_environment_values_input_dir}/input_v1.yaml.gotmpl template --state-values-set ns=test3 > ${cli_overwrite_environment_values_reverse} || fail "\"helmfile template\" shouldn't fail" + ${helmfile} -f ${cli_overwrite_environment_values_input_dir}/input_v1.yaml.gotmpl template --state-values-set ns=test3 --state-values-set-string imageTag=1.23.3,zone="zone1,zone2" > ${cli_overwrite_environment_values_reverse} || fail "\"helmfile template\" shouldn't fail" diff -u ${cli_overwrite_environment_values_output_dir}/output_v1.yaml ${cli_overwrite_environment_values_reverse} || fail "\"helmfile template\" should be consistent" echo code=$? done test_pass "${case_title}" -fi \ No newline at end of file +fi diff --git a/test/integration/test-cases/cli-overwrite-environment-values/input/values.yaml.gotmpl b/test/integration/test-cases/cli-overwrite-environment-values/input/values.yaml.gotmpl index afc1af27..a1635c7b 100644 --- a/test/integration/test-cases/cli-overwrite-environment-values/input/values.yaml.gotmpl +++ b/test/integration/test-cases/cli-overwrite-environment-values/input/values.yaml.gotmpl @@ -1,2 +1,5 @@ image: - tag: {{ .Values.ns }} \ No newline at end of file + tag: {{ .Values.imageTag }} + +podAnnotations: + zone: {{ .Values.zone }} diff --git a/test/integration/test-cases/cli-overwrite-environment-values/output/output_v1.yaml b/test/integration/test-cases/cli-overwrite-environment-values/output/output_v1.yaml index 04eafff0..ba0f5cd7 100644 --- a/test/integration/test-cases/cli-overwrite-environment-values/output/output_v1.yaml +++ b/test/integration/test-cases/cli-overwrite-environment-values/output/output_v1.yaml @@ -51,6 +51,7 @@ spec: app.kubernetes.io/instance: test app.kubernetes.io/managed-by: Helm annotations: + zone: "zone1,zone2" spec: automountServiceAccountToken: false @@ -75,7 +76,7 @@ spec: initContainers: containers: - name: nginx - image: docker.io/bitnami/nginx:test3 + image: docker.io/bitnami/nginx:1.23.3 imagePullPolicy: "IfNotPresent" env: - name: BITNAMI_DEBUG