mirror of
https://github.com/helmfile/helmfile.git
synced 2026-09-30 08:00:19 +02:00
* fix: eliminate os.Chdir in sequential helmfiles to fix relative path resolution The sequential code path used within() → os.Chdir() to change the process-wide working directory when processing helmfile.d files. This broke relative environment variable paths (e.g. KUBECONFIG=kubeconfig.yaml) because they resolved from the wrong directory after chdir. Replace the chdir-based approach with the same baseDir parameter pattern used by the parallel code path, passing explicit directory context through loadDesiredStateFromYamlWithBaseDir() instead of mutating global process state. Closes #2409 Signed-off-by: Aditya Menon <amenon@canarytechnologies.com> * fix: restore within() for single-file sequential to preserve chart path format The previous approach used baseDir for all sequential processing, which changed chart path format in output (e.g. from "../../../../charts/raw" to "test/integration/charts/raw"). This broke integration tests that compare chart paths in expected output. Now the sequential branch uses two strategies: - Single file: use os.Chdir via within() to preserve backward-compatible relative chart paths in output - Multiple files with --sequential-helmfiles: use baseDir parameter to avoid os.Chdir, fixing relative env var paths like KUBECONFIG (#2409) Signed-off-by: Aditya Menon <amenon@canarytechnologies.com> * fix: revert e2e snapshot outputs to match within() behavior The previous commit restored within() for single-file sequential processing, which produces relative chart paths (e.g. ../../charts/raw) and filename-only FilePath. Revert the e2e snapshot expected outputs to match main branch since single-file behavior is now identical. Signed-off-by: Aditya Menon <amenon@canarytechnologies.com> * fix: restructure integration test for multi-file sequential processing - Point -f at helmfile.d/ directly (not parent dir) so findDesiredStateFiles discovers the yaml files - Add second helmfile to trigger baseDir path (len > 1) - Inline environment config to avoid base file relative path issues - Verify both releases appear in output instead of comparing with parallel (which may differ in ordering) Signed-off-by: Aditya Menon <amenon@canarytechnologies.com> * fix: reduce cognitive complexity and improve accuracy of sequential helmfiles Replace inline visitSubHelmfiles closure with calls to the existing processNestedHelmfiles() method, matching the parallel path. This eliminates duplicated nested logic and reduces gocognit complexity below the CI threshold of 110. Also fixes help text and docs to accurately describe that single-file processing still uses within(), and adds kubeContext verification to the integration test. Signed-off-by: Aditya Menon <amenon@canarytechnologies.com> * test: validate kubeContext resolution in sequential helmfiles integration test Restructure the integration test to replicate the exact user scenario from issue #2409: - Multiple files in helmfile.d/ using bases: with relative paths (../bases/) for environments and defaults - Environment values set kubeContext via .Environment.Values - helmDefaults.kubeContext rendered from gotmpl - Local chart references (../../../../charts/raw) from helmfile.d/ - Run diff against the minikube cluster to exercise kubeContext resolution, which would fail with "context does not exist" if os.Chdir() broke relative path resolution - Also verify template output for both releases and relative values file (values/common.yaml) resolution Fix normalizeChart() in util.go to be idempotent — skip re-prefixing when the chart path already starts with basePath. This prevents double-prefixing of local chart paths (e.g. helmfile.d/test/.../raw) when normalizeChart is called multiple times (once during chart preparation and again during diff/sync). Signed-off-by: Aditya Menon <amenon@canarytechnologies.com> --------- Signed-off-by: Aditya Menon <amenon@canarytechnologies.com>
43 lines
2.1 KiB
Bash
43 lines
2.1 KiB
Bash
# Issue #2409: Test that --sequential-helmfiles works with kubeContext from bases
|
|
# https://github.com/helmfile/helmfile/issues/2409
|
|
#
|
|
# This test replicates the exact user scenario:
|
|
# - Multiple files in helmfile.d/
|
|
# - bases: with relative paths (../bases/) for environments and defaults
|
|
# - Environment values set kubeContext (resolved via .Environment.Values.kubeContext)
|
|
# - Running diff against the minikube cluster to exercise kubeContext resolution
|
|
#
|
|
# Before the fix, os.Chdir() in the sequential path could break relative path
|
|
# resolution, causing kubeContext or KUBECONFIG to not resolve correctly.
|
|
|
|
issue_2409_input_dir="${cases_dir}/issue-2409-sequential-kubecontext/input/helmfile.d"
|
|
issue_2409_tmp=$(mktemp -d)
|
|
|
|
test_start "issue 2409 sequential helmfiles with kubeContext"
|
|
|
|
# Run diff with --sequential-helmfiles to verify kubeContext resolves correctly
|
|
# against the minikube cluster. This would fail with "context does not exist"
|
|
# if path resolution were broken by os.Chdir().
|
|
info "Running helmfile --sequential-helmfiles diff with kubeContext from bases"
|
|
bash -c "${helmfile} --sequential-helmfiles -f ${issue_2409_input_dir} diff --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" \
|
|
|| fail "\"helmfile --sequential-helmfiles diff\" should exit 2 (changes detected)"
|
|
|
|
# Also verify template output contains both releases and the relative values file
|
|
info "Running helmfile --sequential-helmfiles template"
|
|
${helmfile} --sequential-helmfiles -f ${issue_2409_input_dir} template \
|
|
> ${issue_2409_tmp}/sequential.log 2>&1 \
|
|
|| fail "\"helmfile --sequential-helmfiles template\" shouldn't fail"
|
|
|
|
grep -q "test-release-2409" ${issue_2409_tmp}/sequential.log \
|
|
|| fail "release test-release-2409 from 01-app.yaml.gotmpl should be in output"
|
|
|
|
grep -q "test-infra-2409" ${issue_2409_tmp}/sequential.log \
|
|
|| fail "release test-infra-2409 from 02-infra.yaml.gotmpl should be in output"
|
|
|
|
grep -q "common-values-2409" ${issue_2409_tmp}/sequential.log \
|
|
|| fail "relative values file values/common.yaml should be resolved in sequential mode"
|
|
|
|
rm -rf ${issue_2409_tmp}
|
|
|
|
test_pass "issue 2409 sequential helmfiles with kubeContext"
|