mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-17 20:07:08 +02:00
fix: pass --kube-context to helm template when using jsonPatches (#2309) When using jsonPatches or strategicMergePatches in helmfile, the `helm template` command was not receiving the `--kube-context` flag. This caused issues when `--dry-run=server` was used (introduced in PR #2271 to support lookup() functions), because helm would connect to the wrong cluster context. Root Cause: 1. `flagsForTemplate()` did not call `appendConnectionFlags()`, unlike `flagsForUpgrade()` and `flagsForDiff()` which both include this call. 2. `processChartification()` did not include `--kube-context` when setting `chartifyOpts.TemplateArgs` for internal helm template calls. Fix: 1. Added `appendConnectionFlags()` call to `flagsForTemplate()` to ensure kube-context and other connection flags are passed to helm template. 2. Added `getKubeContext()` helper function that resolves kube-context with proper priority: release > environment > helmDefaults. 3. Modified `processChartification()` to include `--kube-context` in chartifyOpts.TemplateArgs when chartify needs to run helm template. 4. Added compatibility check for `--validate` flag to avoid Helm 4 mutual exclusion error between --validate and --dry-run (Issue #2355). Fixes #2309 Signed-off-by: Aditya Menon <amenon@canarytechnologies.com>
33 lines
1.4 KiB
Bash
33 lines
1.4 KiB
Bash
# Issue #2309: Test that helm template receives --kube-context when using jsonPatches
|
|
# https://github.com/helmfile/helmfile/issues/2309
|
|
#
|
|
# This test verifies that helmfile correctly passes --kube-context to helm template
|
|
# when helmDefaults.kubeContext is set and jsonPatches are used.
|
|
|
|
issue_2309_case_input_dir="${cases_dir}/issue-2309-kube-context-template/input"
|
|
issue_2309_case_output_dir="${cases_dir}/issue-2309-kube-context-template/output"
|
|
|
|
config_file="helmfile.yaml.gotmpl"
|
|
issue_2309_tmp=$(mktemp -d)
|
|
issue_2309_template_output=${issue_2309_tmp}/issue_2309.template.log
|
|
|
|
test_start "helmfile template with kube-context and jsonPatches (issue #2309)"
|
|
|
|
info "Running helmfile template with kubeContext and jsonPatches"
|
|
${helmfile} -f ${issue_2309_case_input_dir}/${config_file} template > ${issue_2309_template_output} || fail "\"helmfile template\" shouldn't fail"
|
|
|
|
info "Checking template output"
|
|
cat ${issue_2309_template_output}
|
|
|
|
# Verify the output contains the patched ConfigMap
|
|
if grep -q "patched: \"true\"" ${issue_2309_template_output}; then
|
|
info "Found patched value in output - jsonPatches applied successfully"
|
|
else
|
|
fail "jsonPatches were not applied - missing 'patched: true' in output"
|
|
fi
|
|
|
|
# Compare with expected output
|
|
./dyff between -bs ${issue_2309_case_output_dir}/template ${issue_2309_template_output} || fail "\"helmfile template\" output should match expected"
|
|
|
|
test_pass "helmfile template with kube-context and jsonPatches (issue #2309)"
|