Conversation
….APIVersions For Helm v4, --dry-run=server should be used by default to get the correct .Capabilities.APIVersions.Has behavior. This is only applied when the user hasn't explicitly set --dry-run=client. Fixes #894 Signed-off-by: yxxhero <aiopsclub@163.com>
Signed-off-by: yxxhero <aiopsclub@163.com>
Add unit tests for PR #928 to verify the dry-run flag behavior for Helm v4, which uses --dry-run=server by default to get correct .Capabilities.APIVersions. Signed-off-by: yxxhero <aiopsclub@163.com>
There was a problem hiding this comment.
Pull request overview
This pull request fixes issue #894 where .Capabilities.APIVersions.Has is incorrectly evaluated when using Helm v4. The fix changes the default dry-run mode from client to server for Helm v4 to ensure that API version capabilities are correctly populated during template rendering. The change is scoped to Helm v4 only, maintaining backward compatibility with Helm v3.
Changes:
- Modified
cmd/helm.goto use--dry-run=serverby default for Helm v4 when cluster access is allowed and the user hasn't explicitly set--dry-run=client - Added comprehensive test coverage in
cmd/helm_test.goto verify the new dry-run flag behavior across different Helm versions and modes - Updated import formatting in
cmd/upgrade_test.goto follow codebase conventions
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| cmd/helm.go | Implements the core fix by defaulting to --dry-run=server for Helm v4 to populate .Capabilities.APIVersions correctly, while avoiding duplicate dry-run flags |
| cmd/helm_test.go | Adds test helper function and comprehensive test cases covering Helm v3/v4 behavior with different dry-run modes |
| cmd/upgrade_test.go | Minor import formatting change to use multi-line import style consistent with other test files |
| .github/workflows/ci.yaml | Adds HELM_DEBUG environment variable to one integration test for debugging output |
| }) | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
The test suite is missing coverage for dryRunMode="true" and dryRunMode="false" cases. According to cmd/upgrade.go, these are valid values that users can pass (line 25: validDryRunValues includes "true" and "false"). The behavior is documented as: "true" should behave like "client" and "false" should behave like "none". Test cases should be added to verify that these values are handled correctly for both Helm v3 and Helm v4, especially since the current implementation has a bug where dryRunMode="true" results in no dry-run flags being added for Helm v4.
| func TestGetTemplateDryRunFlagsBoolModes(t *testing.T) { | |
| cases := []struct { | |
| name string | |
| config dryRunFlagsConfig | |
| expected []string | |
| }{ | |
| { | |
| name: "Helm v3 dryRunMode=true behaves like client", | |
| config: dryRunFlagsConfig{ | |
| isHelmV4: false, | |
| supportsDryRunLookup: true, | |
| clusterAccessAllowed: true, | |
| disableValidation: false, | |
| dryRunMode: "true", | |
| }, | |
| expected: []string{"--validate", "--dry-run=client"}, | |
| }, | |
| { | |
| name: "Helm v3 dryRunMode=false behaves like none", | |
| config: dryRunFlagsConfig{ | |
| isHelmV4: false, | |
| supportsDryRunLookup: true, | |
| clusterAccessAllowed: true, | |
| disableValidation: false, | |
| dryRunMode: "false", | |
| }, | |
| expected: []string{"--validate"}, | |
| }, | |
| { | |
| name: "Helm v4 dryRunMode=true behaves like client", | |
| config: dryRunFlagsConfig{ | |
| isHelmV4: true, | |
| supportsDryRunLookup: true, | |
| clusterAccessAllowed: true, | |
| disableValidation: false, | |
| dryRunMode: "true", | |
| }, | |
| expected: []string{"--dry-run=client"}, | |
| }, | |
| { | |
| name: "Helm v4 dryRunMode=false behaves like none", | |
| config: dryRunFlagsConfig{ | |
| isHelmV4: true, | |
| supportsDryRunLookup: true, | |
| clusterAccessAllowed: true, | |
| disableValidation: false, | |
| dryRunMode: "false", | |
| }, | |
| expected: []string{}, | |
| }, | |
| } | |
| for _, tc := range cases { | |
| t.Run(tc.name, func(t *testing.T) { | |
| actual := getTemplateDryRunFlags(tc.config) | |
| if !reflect.DeepEqual(actual, tc.expected) { | |
| t.Errorf("Expected %v, got %v", tc.expected, actual) | |
| } | |
| }) | |
| } | |
| } |
cmd/helm_test.go
Outdated
| if cfg.dryRunMode != "client" { | ||
| flags = append(flags, "--dry-run=server") | ||
| } | ||
| } else { | ||
| flags = append(flags, "--validate") | ||
| } | ||
| } | ||
|
|
||
| if cfg.supportsDryRunLookup { | ||
| if !(cfg.isHelmV4 && cfg.dryRunMode != "client") { | ||
| if cfg.dryRunMode == "server" { | ||
| flags = append(flags, "--dry-run=server") | ||
| } else { | ||
| flags = append(flags, "--dry-run=client") | ||
| } | ||
| } |
There was a problem hiding this comment.
The test helper function getTemplateDryRunFlags has the same bug as the actual implementation in cmd/helm.go. The conditions on lines 23 and 32 don't handle dryRunMode="true" correctly. This needs to be fixed along with the actual implementation. The conditions should check for both "client" and "true" when deciding whether to skip server mode for Helm v4.
.github/workflows/ci.yaml
Outdated
| env: | ||
| HELM_DEBUG: "true" |
There was a problem hiding this comment.
The HELM_DEBUG environment variable is being set for this specific test. HELM_DEBUG only controls debug logging output and is not required for the test to pass. Unless there's a specific reason to debug this particular test (which should be documented), this appears to be a leftover from development/debugging and should be removed to keep the CI configuration clean and consistent.
8c2bb0d to
1995d0f
Compare
- Fix conditions to properly handle dryRunMode="true" (behaves like client) - Fix conditions to properly handle dryRunMode="false" (behaves like none) - Add test cases for boolean dry-run modes - Remove leftover HELM_DEBUG from CI workflow Signed-off-by: yxxhero <aiopsclub@163.com>
1995d0f to
5fe2d8d
Compare
Summary
Fixes #894
For Helm v4,
--dry-run=servershould be used by default to get the correct.Capabilities.APIVersions.Hasbehavior. Without this, conditions like{{ if .Capabilities.APIVersions.Has "monitoring.coreos.com/v1/PrometheusRule" }}are incorrectly evaluated by helm-diff when using Helm v4.0.0.Changes
cmd/helm.goto use--dry-run=serverby default for Helm v4 when the user hasn't explicitly set--dry-run=client--dry-runarguments for Helm v4Testing
All existing tests pass.