Repository navigation
fix: resolve --validate flag conflict with kustomize in Helm 4 - #2362
Conversation
Fixes helmfile#2355 In Helm 4, the --validate and --dry-run flags are mutually exclusive. When using kustomize/chartify charts with helmfile diff --validate, the code was adding both --validate AND --dry-run=server to the helm template command, causing the error: Error: if any flags in the group [validate dry-run] are set none of the others can be; [dry-run validate] were all set The fix checks if --validate is already set before adding --dry-run=server. Since --validate already provides server-side validation (it was deprecated in favor of --dry-run=server in Helm 4), adding --dry-run=server is redundant when --validate is present. Changes: - Add !opts.Validate condition to processChartification() in state.go - Add comprehensive unit tests for validate/dry-run mutual exclusion - Add integration test with kustomize chart to prevent regression Signed-off-by: Aditya Menon <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #2355 by resolving a flag conflict when using --validate with kustomize/chartify charts in Helm 4. In Helm 4, the --validate and --dry-run flags are mutually exclusive. The fix prevents helmfile from adding --dry-run=server when --validate is already set, since --validate already provides server-side validation.
Changes:
- Modified the cluster access logic in
processChartification()to skip adding--dry-run=serverwhen--validateflag is set - Added comprehensive unit tests covering various command/validate flag combinations
- Added integration test to verify the fix with actual kustomize charts
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
pkg/state/state.go |
Added condition && !opts.Validate to prevent adding --dry-run=server when validate is set |
pkg/state/issue_2355_test.go |
Added 19 unit test cases covering validate/dry-run mutual exclusion logic with helper function |
test/integration/test-cases/issue-2355.sh |
Added integration test script to verify the fix with kustomize charts |
test/integration/test-cases/issue-2355/input/helmfile.yaml |
Test fixture: helmfile configuration using local kustomize chart |
test/integration/test-cases/issue-2355/input/kubernetes/kustomization.yaml |
Test fixture: kustomize configuration file |
test/integration/test-cases/issue-2355/input/kubernetes/deployment.yaml |
Test fixture: Kubernetes deployment manifest |
test/integration/run.sh |
Registered the new integration test in the test suite |
- Add missing test cases for destroy, delete, test, status WITH --validate - Update integration test to use 'diff' instead of 'template' to properly exercise the cluster-requiring code path that triggers --dry-run=server - Add sync warning comments to the test helper function noting it must be kept in sync with processChartification() in state.go Signed-off-by: Aditya Menon <[email protected]>
Signed-off-by: Aditya Menon <[email protected]>
- Fix integration test to capture output and exit code in single execution instead of running helmfile twice (more efficient) - Add detailed documentation explaining why test helper duplication is intentional: extracting shared function would require exposing internal API and complex refactoring of processChartification dependencies - Note that integration test exercises actual code path end-to-end Signed-off-by: Aditya Menon <[email protected]>
Signed-off-by: Aditya Menon <[email protected]>
Signed-off-by: Aditya Menon <[email protected]>
|
@aditmeno thanks so much. there are some conflicts. |
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]>
|
@aditmeno is it ready for reiview? |
Yes, the previous PR had the same changes to prevent conflicts (didn't work out so well as anticipated 😅) This PR has the tests |
|
@aditmeno I didn't see pkg/state/state.go file. |
I've updated the PR description to clarify why it's no longer there in this PR |
The
pkg/state/state.gochange in this PR has already been included in the merged PR #2363. After rebasing on main, this PR only contains tests and integration test fixtures. The core fix (adding&& !opts.Validatecheck) was incorporated into PR #2363 to ensure compatibility between the two fixes.Summary
Fixes #2355
This PR resolves the
--validateflag conflict when using kustomize/chartify charts with Helm 4.Problem
In Helm 4, the
--validateand--dry-runflags are mutually exclusive. When runninghelmfile diff --validatewith a kustomize chart, helmfile was adding both--validateAND--dry-run=serverto the helm template command, causing:Root Cause
In
processChartification()(pkg/state/state.go), the code was:chartifyOpts.Validate = opts.Validate(line 1475)--dry-run=serverfor cluster-requiring commands likediff(lines 1514-1520)This caused chartify to run
helm template --validate --dry-run=server, which fails in Helm 4.Solution
Add a check for
!opts.Validatebefore adding--dry-run=server:This works because:
--validatealready provides server-side validation--validateis deprecated in favor of--dry-run=server(they do the same thing)--dry-run=serverwhen--validateis set is redundantChanges
pkg/state/state.go&& !opts.Validatecondition to skip adding--dry-run=serverwhen validate is set (Note: Already merged in PR #2363)pkg/state/issue_2355_test.gotest/integration/test-cases/issue-2355.shtest/integration/test-cases/issue-2355/input/test/integration/run.shTest Plan
go test ./pkg/state/... -run "TestValidateAndDryRun" -vgo test ./pkg/...(note: pre-existingTestStorage_resolveFilefailure is unrelated)cd test/integration && ./run.sh(requires minikube)Test Coverage
The new unit tests cover:
--validate--validate--dry-runflagReproduction Case (from issue)