fix: loadBases overrodeEnv issue (#838)

This commit is contained in:
yxxhero 2023-05-08 05:24:32 +08:00 committed by GitHub
parent b6dd7122f9
commit 643f888703
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 106 additions and 1 deletions

View File

@ -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) { 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{} layers := []*HelmState{}
for _, b := range st.Bases { 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -76,6 +76,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes
# TEST CASES---------------------------------------------------------------------------------------------------------- # TEST CASES----------------------------------------------------------------------------------------------------------
. ${dir}/test-cases/v1-subhelmfile-multi-bases-with-array-values.sh
. ${dir}/test-cases/kustomized-fetch.sh . ${dir}/test-cases/kustomized-fetch.sh
. ${dir}/test-cases/happypath.sh . ${dir}/test-cases/happypath.sh
. ${dir}/test-cases/regression.sh . ${dir}/test-cases/regression.sh

View File

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

View File

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

View File

@ -0,0 +1,13 @@
bases:
- environments.yaml.gotmpl
---
helmfiles:
- path: subhelmfile.yaml.gotmpl
selectorsInherited: true
values:
{{- with .Values.myExample }}
- specificValues:
{{ toYaml . | nindent 8 }}
{{- end }}

View File

@ -0,0 +1,3 @@
repositories:
- name: incubator
url: https://charts.helm.sh/incubator/

View File

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

View File

@ -0,0 +1,10 @@
resources:
- apiVersion: v1
kind: Pod
metadata:
name: test
spec:
{{- with .Values.specificValues.myContainers }}
containers:
{{ toYaml . | nindent 8 }}
{{- end }}

View File

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

View File

@ -0,0 +1 @@
https://github.com/helmfile/helmfile/issues/835