Use a regex to match --state-values-set-string arguments (#1902)

Signed-off-by: Guillaume Le Blanc <gleblanc@proton.me>
This commit is contained in:
Guillaume Le Blanc 2025-02-04 00:59:31 +01:00 committed by GitHub
parent 8e188960eb
commit 09c9ceb075
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 9 deletions

View File

@ -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)
}

View File

@ -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
fi

View File

@ -1,2 +1,5 @@
image:
tag: {{ .Values.ns }}
tag: {{ .Values.imageTag }}
podAnnotations:
zone: {{ .Values.zone }}

View File

@ -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