Add integration tests for #1749 (#1766)

* Add integration tests for #1749

Signed-off-by: Matthias Baur <m.baur@syseleven.de>

* Reset extra args on a higher level to only affect subsequent helmfiles

With the implementation before, extra args has been reset after each
helm.exec which leads to problems with multiple charts in a helmfile
since the correct args are only set once in Template(). But Template()
calls helm.exec(template) multiple times.

Signed-off-by: Matthias Baur <m.baur@syseleven.de>

---------

Signed-off-by: Matthias Baur <m.baur@syseleven.de>
This commit is contained in:
Matthias Baur 2024-11-06 01:12:20 +01:00 committed by GitHub
parent 8ee56f13f3
commit d23dc8a9de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 66 additions and 8 deletions

View File

@ -597,10 +597,6 @@ func (helm *execer) exec(args []string, env map[string]string, overrideEnableLiv
enableLiveOutput = *overrideEnableLiveOutput
}
outBytes, err := helm.runner.Execute(helm.helmBinary, cmdargs, env, enableLiveOutput)
// Reset extra args after each helm execution
helm.SetExtraArgs()
return outBytes, err
}
@ -618,10 +614,6 @@ func (helm *execer) execStdIn(args []string, env map[string]string, stdin io.Rea
cmd := fmt.Sprintf("exec: %s %s", helm.helmBinary, strings.Join(cmdargs, " "))
helm.logger.Debug(cmd)
outBytes, err := helm.runner.ExecuteStdIn(helm.helmBinary, cmdargs, env, stdin)
// Reset extra args after each helm execution
helm.SetExtraArgs()
return outBytes, err
}

View File

@ -1439,6 +1439,11 @@ func (st *HelmState) runHelmDepBuilds(helm helmexec.Interface, concurrency int,
// So we shouldn't use goroutines like we do for other helm operations here.
//
// See https://github.com/roboll/helmfile/issues/1521
// Reset helm extra args to not pollute BuildDeps() on subsequent helmfiles
// https://github.com/helmfile/helmfile/issues/1749
helm.SetExtraArgs()
for _, r := range builds {
buildDepsFlags := getBuildDepsFlags(r)
if err := helm.BuildDeps(r.releaseName, r.chartPath, buildDepsFlags...); err != nil {

View File

@ -69,6 +69,7 @@ function cleanup() {
set -e
trap cleanup EXIT
info "Using namespace: ${test_ns}"
info "Using Helm version:" $(${helm} version --short | grep -o 'v[0-9.]\+')
${helm} plugin ls | grep diff || ${helm} plugin install https://github.com/databus23/helm-diff --version v${HELM_DIFF_VERSION}
info "Using Kustomize version: $(kustomize version --short | grep -o 'v[0-9.]\+')"
${kubectl} get namespace ${test_ns} &> /dev/null && warn "Namespace ${test_ns} exists, from a previous test run?"
@ -96,6 +97,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes
. ${dir}/test-cases/deps-mr-1011.sh
. ${dir}/test-cases/deps-kustomization-i-1402.sh
. ${dir}/test-cases/hcl-secrets.sh
. ${dir}/test-cases/issue-1749.sh
# ALL DONE -----------------------------------------------------------------------------------------------------------

View File

@ -0,0 +1,12 @@
issue_1749_input_dir="${cases_dir}/issue-1749/input"
helmfile_real="$(pwd)/${helmfile}"
test_start "issue 1749 helmfile.d template --args --dry-run=server"
cd "${issue_1749_input_dir}"
${helmfile_real} template --args --dry-run=server || fail "\"issue 1749 helmfile.d template --args --dry-run=server\" shouldn't fail"
cd -
test_pass "issue 1749 helmfile.d template --args --dry-run=server"
test_start "issue 1749 helmfile.yaml template --args --dry-run=server"
${helmfile_real} template -f "${issue_1749_input_dir}/helmfile-2in1.yaml.gotmpl" --args --dry-run=server || fail "\"issue 1749 helmfile.yaml template --args --dry-run=server\" shouldn't fail"
test_pass "issue 1749 helmfile.yaml template --args --dry-run=server"

View File

@ -0,0 +1,23 @@
releases:
- name: test1
chart: ../../../charts/raw
values:
- templates:
- |
apiVersion: v1
kind: ConfigMap
metadata:
name: {{`{{ .Release.Name }}`}}
data:
foo: {{`{{ (first (lookup "v1" "Namespace" "" "").items).metadata.name }}`}}
- name: test2
chart: ../../../charts/raw
values:
- templates:
- |
apiVersion: v1
kind: ConfigMap
metadata:
name: {{`{{ .Release.Name }}`}}
data:
foo: {{`{{ (first (lookup "v1" "Namespace" "" "").items).metadata.name }}`}}

View File

@ -0,0 +1,12 @@
releases:
- name: test1
chart: ../../../../charts/raw
values:
- templates:
- |
apiVersion: v1
kind: ConfigMap
metadata:
name: {{`{{ .Release.Name }}`}}
data:
foo: {{`{{ (first (lookup "v1" "Namespace" "" "").items).metadata.name }}`}}

View File

@ -0,0 +1,12 @@
releases:
- name: test2
chart: ../../../../charts/raw
values:
- templates:
- |
apiVersion: v1
kind: ConfigMap
metadata:
name: {{`{{ .Release.Name }}`}}
data:
foo: {{`{{ (first (lookup "v1" "Namespace" "" "").items).metadata.name }}`}}