fix: nested helmfile values should replace arrays, not merge element-by-element (#2458)

PR #2367 introduced CLIOverrides to give --state-values-set element-by-element
array merge semantics. However, nested helmfile values (helmfiles[].values:)
were also routed into CLIOverrides, causing their arrays to merge instead of
replace. This broke the pre-v1.3.0 behavior where passing an array via
helmfiles[].values: would fully replace the child's default array.

Add OverrideValuesAreCLI flag to SubhelmfileEnvironmentSpec so the loader can
distinguish CLI flags from nested helmfile values. CLI values continue using
CLIOverrides (element-by-element merge); nested helmfile values now use Values
(Sparse merge strategy → full array replacement).

Fixes #2451

Signed-off-by: Aditya Menon <amenon@canarytechnologies.com>
This commit is contained in:
Aditya Menon
2026-03-09 18:31:21 +08:00
committed by GitHub
parent 26646ebd31
commit c375b48550
11 changed files with 75 additions and 4 deletions
+1
View File
@@ -121,6 +121,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes
. ${dir}/test-cases/state-values-set-cli-args-in-environments.sh
. ${dir}/test-cases/issue-2281-array-merge.sh
. ${dir}/test-cases/issue-2353-layer-array-replace.sh
. ${dir}/test-cases/issue-2451-nested-helmfile-array-replace.sh
. ${dir}/test-cases/issue-2247.sh
. ${dir}/test-cases/issue-2097.sh
. ${dir}/test-cases/issue-2291.sh
@@ -0,0 +1,13 @@
issue_2451_nested_helmfile_array_replace_input_dir="${cases_dir}/issue-2451-nested-helmfile-array-replace/input"
issue_2451_nested_helmfile_array_replace_output_dir="${cases_dir}/issue-2451-nested-helmfile-array-replace/output"
issue_2451_nested_helmfile_array_replace_tmp=$(mktemp -d)
issue_2451_nested_helmfile_array_replace_result="${issue_2451_nested_helmfile_array_replace_tmp}/issue.2451.nested.helmfile.array.replace.yaml"
test_start "issue 2451 - nested helmfile array replace (not merge)"
info "Comparing issue 2451 nested helmfile array replace output ${issue_2451_nested_helmfile_array_replace_result} with ${issue_2451_nested_helmfile_array_replace_output_dir}/output.yaml"
${helmfile} -f "${issue_2451_nested_helmfile_array_replace_input_dir}/helmfile.yaml" template --skip-deps > "${issue_2451_nested_helmfile_array_replace_result}" || fail "\"helmfile template\" shouldn't fail"
./dyff between -bs "${issue_2451_nested_helmfile_array_replace_output_dir}/output.yaml" "${issue_2451_nested_helmfile_array_replace_result}" || fail "nested helmfile array values should replace default arrays entirely, not merge element-by-element"
test_pass "issue 2451 - nested helmfile array replace (not merge)"
@@ -0,0 +1,17 @@
values:
- defaults.yaml
---
releases:
- name: test
chart: ../../../charts/raw
values:
- templates:
- |
{{- range $item := .Values.list }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $item.name }}
{{- end }}
@@ -0,0 +1,3 @@
list:
- name: default1
- name: default2
@@ -0,0 +1,5 @@
helmfiles:
- path: child.yaml.gotmpl
values:
- list:
- name: override1
@@ -0,0 +1,7 @@
---
# Source: raw/templates/resources.yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: override1