diff --git a/pkg/state/create.go b/pkg/state/create.go index ee888cfe..58b57d49 100644 --- a/pkg/state/create.go +++ b/pkg/state/create.go @@ -196,9 +196,14 @@ func (c *StateCreator) ParseAndLoad(content []byte, baseDir, file string, envNam } func (c *StateCreator) loadBases(envValues, overrodeEnv *environment.Environment, st *HelmState, baseDir string) (*HelmState, error) { + var newOverrodeEnv *environment.Environment + if overrodeEnv != nil { + overrodeEnvCopier := overrodeEnv.DeepCopy() + newOverrodeEnv = &overrodeEnvCopier + } layers := []*HelmState{} for _, b := range st.Bases { - base, err := c.LoadFile(envValues, overrodeEnv, baseDir, b, false) + base, err := c.LoadFile(envValues, newOverrodeEnv, baseDir, b, false) if err != nil { return nil, err } diff --git a/test/integration/run.sh b/test/integration/run.sh index 14d3eaa4..5c32e3ab 100755 --- a/test/integration/run.sh +++ b/test/integration/run.sh @@ -76,6 +76,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes # TEST CASES---------------------------------------------------------------------------------------------------------- +. ${dir}/test-cases/v1-subhelmfile-multi-bases-with-array-values.sh . ${dir}/test-cases/kustomized-fetch.sh . ${dir}/test-cases/happypath.sh . ${dir}/test-cases/regression.sh diff --git a/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values.sh b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values.sh new file mode 100644 index 00000000..a234fb19 --- /dev/null +++ b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values.sh @@ -0,0 +1,19 @@ +if [[ ${HELMFILE_V1MODE} = true ]]; then + v1_subhelmfile_multi_bases_with_array_values_input_dir="${cases_dir}/v1-subhelmfile-multi-bases-with-array-values/input" + v1_subhelmfile_multi_bases_with_array_values_output_dir="${cases_dir}/v1-subhelmfile-multi-bases-with-array-values/output" + + yaml_overwrite_tmp=$(mktemp -d) + yaml_overwrite_reverse=${yaml_overwrite_tmp}/helmfile_template_result + + test_start "v1 subhelmfile multi bases with array values" + info "Comparing v1 subhelmfile multi bases with array values output ${yaml_overwrite_reverse} with ${v1_subhelmfile_multi_bases_with_array_values_output_dir}/result" + for i in $(seq 10); do + info "Comparing build/v1-subhelmfile-multi-bases-with-array-values #$i" + ${helmfile} -f ${v1_subhelmfile_multi_bases_with_array_values_input_dir}/helmfile.yaml.gotmpl template -e dev &> ${yaml_overwrite_reverse} || fail "\"helmfile template\" shouldn't fail" + diff -u ${v1_subhelmfile_multi_bases_with_array_values_output_dir}/result ${yaml_overwrite_reverse} || fail "\"helmfile template\" should be consistent" + echo code=$? + done + test_pass "v1 subhelmfile multi bases with array values" +else + test_pass "[skipped] v1 subhelmfile multi bases with array values" +fi \ No newline at end of file diff --git a/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/environments.yaml.gotmpl b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/environments.yaml.gotmpl new file mode 100644 index 00000000..5fa3dee5 --- /dev/null +++ b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/environments.yaml.gotmpl @@ -0,0 +1,14 @@ +environments: + dev: + values: + - myExample: + myContainers: + - name: test-container + image: registry.k8s.io/busybox + command: [ "/bin/sh", "-c", "env" ] +--- +helmDefaults: + verify: false + wait: true + timeout: 1800 + tls: false diff --git a/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/helmfile.yaml.gotmpl b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/helmfile.yaml.gotmpl new file mode 100644 index 00000000..fc568768 --- /dev/null +++ b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/helmfile.yaml.gotmpl @@ -0,0 +1,13 @@ +bases: + - environments.yaml.gotmpl + +--- + +helmfiles: + - path: subhelmfile.yaml.gotmpl + selectorsInherited: true + values: + {{- with .Values.myExample }} + - specificValues: + {{ toYaml . | nindent 8 }} + {{- end }} diff --git a/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/repositories.yaml b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/repositories.yaml new file mode 100644 index 00000000..8ee19e5e --- /dev/null +++ b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/repositories.yaml @@ -0,0 +1,3 @@ +repositories: + - name: incubator + url: https://charts.helm.sh/incubator/ diff --git a/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/subhelmfile.yaml.gotmpl b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/subhelmfile.yaml.gotmpl new file mode 100644 index 00000000..c3b90575 --- /dev/null +++ b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/subhelmfile.yaml.gotmpl @@ -0,0 +1,15 @@ +bases: + - environments.yaml.gotmpl + - repositories.yaml +--- + +releases: + - name: helmfile-test + namespace: namespace-test + labels: + release: "{{`{{ .Release.Name }}`}}" + namespace: "{{`{{ .Release.Namespace }}`}}" + chart: incubator/raw + version: 0.1.0 + values: + - "./values.yaml.gotmpl" diff --git a/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/values.yaml.gotmpl b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/values.yaml.gotmpl new file mode 100644 index 00000000..1f2a05e6 --- /dev/null +++ b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/input/values.yaml.gotmpl @@ -0,0 +1,10 @@ +resources: + - apiVersion: v1 + kind: Pod + metadata: + name: test + spec: + {{- with .Values.specificValues.myContainers }} + containers: + {{ toYaml . | nindent 8 }} + {{- end }} diff --git a/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/output/result b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/output/result new file mode 100644 index 00000000..a8869435 --- /dev/null +++ b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/output/result @@ -0,0 +1,24 @@ +Adding repo incubator https://charts.helm.sh/incubator/ +"incubator" has been added to your repositories + +Templating release=helmfile-test, chart=incubator/raw +--- +# Source: raw/templates/resources.yaml +apiVersion: v1 +kind: Pod +metadata: + labels: + app: raw + chart: raw-0.1.0 + heritage: Helm + release: helmfile-test + name: test +spec: + containers: + - command: + - /bin/sh + - -c + - env + image: registry.k8s.io/busybox + name: test-container + diff --git a/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/readme b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/readme new file mode 100644 index 00000000..56db5239 --- /dev/null +++ b/test/integration/test-cases/v1-subhelmfile-multi-bases-with-array-values/readme @@ -0,0 +1 @@ +https://github.com/helmfile/helmfile/issues/835 \ No newline at end of file