Skip to content

fix: resolve --validate flag conflict with kustomize in Helm 4 - #2362

Merged
yxxhero merged 9 commits into
helmfile:mainfrom
aditmeno:fix/issue-2355-validate-kustomize-helm4
Jan 18, 2026
Merged

yxxhero merged 9 commits into
helmfile:mainfrom
aditmeno:fix/issue-2355-validate-kustomize-helm4

Conversation

@aditmeno

@aditmeno aditmeno commented Jan 15, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Note for Reviewers

The pkg/state/state.go change 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.Validate check) was incorporated into PR #2363 to ensure compatibility between the two fixes.


Summary

Fixes #2355

This PR resolves the --validate flag conflict when using kustomize/chartify charts with Helm 4.

Problem

In Helm 4, the --validate and --dry-run flags are mutually exclusive. When running helmfile diff --validate with a kustomize chart, helmfile was adding both --validate AND --dry-run=server to the helm template command, causing:

Error: if any flags in the group [validate dry-run] are set none of the others can be; [dry-run validate] were all set

Root Cause

In processChartification() (pkg/state/state.go), the code was:

  1. Setting chartifyOpts.Validate = opts.Validate (line 1475)
  2. Unconditionally adding --dry-run=server for cluster-requiring commands like diff (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.Validate before adding --dry-run=server:

// Before (broken in Helm 4):
if requiresCluster {

// After (fixed):
if requiresCluster && !opts.Validate {

This works because:

  • --validate already provides server-side validation
  • In Helm 4, --validate is deprecated in favor of --dry-run=server (they do the same thing)
  • Adding --dry-run=server when --validate is set is redundant

Changes

File Description
pkg/state/state.go Add && !opts.Validate condition to skip adding --dry-run=server when validate is set (Note: Already merged in PR #2363)
pkg/state/issue_2355_test.go Add 19 unit tests for validate/dry-run mutual exclusion logic
test/integration/test-cases/issue-2355.sh Add integration test with kustomize chart
test/integration/test-cases/issue-2355/input/ Add test fixtures (helmfile.yaml, kustomization.yaml, deployment.yaml)
test/integration/run.sh Register new integration test

Test Plan

  • Unit tests pass: go test ./pkg/state/... -run "TestValidateAndDryRun" -v
  • All package tests pass: go test ./pkg/... (note: pre-existing TestStorage_resolveFile failure is unrelated)
  • Integration test: cd test/integration && ./run.sh (requires minikube)
  • Manual verification with reproduction case from issue

Test Coverage

The new unit tests cover:

  • All cluster-requiring commands (diff, apply, sync, destroy, delete, test, status) with and without --validate
  • All non-cluster commands (template, lint, build) with and without --validate
  • Edge cases: existing template args, pre-existing --dry-run flag

Reproduction Case (from issue)

# helmfile.yaml
releases:
  - name: test
    chart: ./kubernetes
    namespace: default

# kubernetes/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - deployment.yaml
# Before fix: ERROR
helmfile diff --validate

# After fix: SUCCESS
helmfile diff --validate

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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=server when --validate flag 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

Comment thread pkg/state/issue_2355_test.go Resolved
Comment thread pkg/state/issue_2355_test.go Resolved
- 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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread pkg/state/issue_2355_test.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread pkg/state/issue_2355_test.go Resolved
- 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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread pkg/state/issue_2355_test.go Resolved
@yxxhero

yxxhero commented Jan 16, 2026

Copy link
Copy Markdown
Member

@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 aditmeno self-assigned this Jan 17, 2026
@yxxhero

yxxhero commented Jan 17, 2026

Copy link
Copy Markdown
Member

@aditmeno is it ready for reiview?

@aditmeno

Copy link
Copy Markdown
Contributor Author

@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

@yxxhero

yxxhero commented Jan 18, 2026

Copy link
Copy Markdown
Member

@aditmeno I didn't see pkg/state/state.go file.

@aditmeno

Copy link
Copy Markdown
Contributor Author

@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

@yxxhero
yxxhero merged commit c71648c into helmfile:main Jan 18, 2026
16 checks passed
@aditmeno
aditmeno deleted the fix/issue-2355-validate-kustomize-helm4 branch January 18, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate flag does not work when using kustomize after helm 4 upgrade

3 participants