Repository navigation
fix: pass --kube-context to helm template when using jsonPatches - #2363
Merged
yxxhero merged 1 commit intoJan 16, 2026
Merged
Conversation
aditmeno
requested review from
itscaro,
mumoshu,
xiaomudk,
yxxhero and
zhaque44
as code owners
January 15, 2026 08:38
aditmeno
force-pushed
the
fix/issue-2309-kube-context-jsonpatches
branch
from
January 15, 2026 14:39
a76d97b to
5798d9f
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where the helm template command does not receive the --kube-context flag when using jsonPatches or strategicMergePatches. This became problematic after PR #2271 introduced --dry-run=server to support lookup() functions, which requires correct cluster context to connect to the right cluster.
Changes:
- Added
appendConnectionFlags()call toflagsForTemplate()to include kube-context in template flags - Added
getKubeContext()helper function to resolve kube-context with proper priority (release > environment > helmDefaults) - Modified
processChartification()to pass--kube-contextto chartify's internal helm template call - Added compatibility check for
--validateflag to avoid Helm 4 mutual exclusion error with--dry-run
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/state/state.go | Added getKubeContext() helper, modified processChartification() to include --kube-context in chartify template args, added appendConnectionFlags() to flagsForTemplate() |
| pkg/state/state_test.go | Added unit tests for flagsForTemplate() kube-context handling and getKubeContext() priority logic |
| pkg/app/app_test.go | Updated test expectations to include new --kube-context flag |
| pkg/app/app_template_test.go | Updated test expectations to include new --kube-context flag |
| test/integration/test-cases/issue-2309-kube-context-template.sh | Added integration test verifying jsonPatches work with kube-context |
| test/integration/test-cases/issue-2309-kube-context-template/input/helmfile.yaml.gotmpl | Test configuration file with kubeContext and jsonPatches |
| test/integration/test-cases/issue-2309-kube-context-template/output/template | Expected template output for integration test |
| test/integration/run.sh | Registered new integration test in test runner |
…mfile#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 helmfile#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 helmfile#2355). Fixes helmfile#2309 Signed-off-by: Aditya Menon <[email protected]>
aditmeno
force-pushed
the
fix/issue-2309-kube-context-jsonpatches
branch
from
January 15, 2026 15:18
5798d9f to
1418911
Compare
yxxhero
approved these changes
Jan 16, 2026
aditmeno
added a commit
to aditmeno/helmfile
that referenced
this pull request
Jan 16, 2026
Resolves merge conflicts from PR helmfile#2363 (kube-context fix): - Accepted main's comprehensive processChartification() implementation which includes both the kube-context fix and the validate flag check - Added both integration tests to run.sh Signed-off-by: Aditya Menon <[email protected]>
4 tasks done
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2309
When using
jsonPatchesorstrategicMergePatchesin helmfile, thehelm templatecommand was not receiving the--kube-contextflag. This caused issues when--dry-run=serverwas used (introduced in PR #2271 to supportlookup()functions), because helm would connect to the wrong cluster context instead of the one specified inhelmDefaults.kubeContext.Example that was failing:
Running
helmfile diffwould fail because the internalhelm templatecall (used by chartify for jsonPatches) did not receive--kube-context=minikube.Root Cause
flagsForTemplate()missing connection flags: The function did NOT callappendConnectionFlags(), unlikeflagsForUpgrade()andflagsForDiff()which both include this call.processChartification()missing kube-context: When--dry-run=serveris added tochartifyOpts.TemplateArgs, the--kube-contextflag was not included.Changes
pkg/state/state.goappendConnectionFlags()call toflagsForTemplate()pkg/state/state.gogetKubeContext()helper function with priority: release > environment > helmDefaultspkg/state/state.goprocessChartification()to include--kube-contextin chartify's TemplateArgspkg/state/state_test.goflagsForTemplate()kube-context handlingpkg/state/state_test.gogetKubeContext()priority logicpkg/app/app_test.go--kube-contextflagpkg/app/app_template_test.go--kube-contextflagtest/integration/test-cases/Compatibility with PR #2362 (Issue #2355)
This PR includes a compatibility check for the
--validateflag to avoid Helm 4's mutual exclusion error between--validateand--dry-run. Whenopts.Validateis set, we skip adding--dry-run=serverto prevent the conflict.Test Coverage
Unit Tests Added
TestHelmState_flagsForTemplate- 3 new test cases:helmDefaults.kubeContextrelease.kubeContext(override)TestHelmState_getKubeContext- 5 test cases:Integration Test Added
test/integration/test-cases/issue-2309-kube-context-template.shhelmfile templatewithkubeContextandjsonPatchesHow to Test
Checklist