Skip to content

Conversation

@yxxhero
Copy link
Collaborator

@yxxhero yxxhero commented Feb 1, 2026

Summary

  • Add native --kube-context flag to all helm-diff commands (upgrade, revision, rollback, release)
  • Allow users to specify kubeconfig context directly instead of using HELM_KUBECONTEXT environment variable
  • Pass the context through to helm commands for consistent behavior

Changes

  • Added kubeContext field to command structs (diffCmd, revision, rollback, release)
  • Updated getRelease, getHooks, getRevision, and getChart functions to accept and use kubeContext parameter
  • Added --kube-context flag to all commands
  • Pass context to helm commands and action configuration

Fixes #603

Add native --kube-context flag to all helm-diff commands (upgrade, revision,
rollback, release) to allow users to specify kubeconfig context directly
instead of relying on HELM_KUBECONTEXT environment variable workaround.

Fixes #603

Signed-off-by: yxxhero <[email protected]>
Copy link

Copilot AI left a comment

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 adds first-class support for a --kube-context flag across helm-diff commands so users can select a kubeconfig context without relying solely on the HELM_KUBECONTEXT workaround, and ensures that this context is consistently propagated to underlying Helm operations.

Changes:

  • Extend diffCmd, revision, rollback, and release structs to carry a kubeContext field and expose a --kube-context flag on upgrade, revision, rollback, and release commands.
  • Thread kubeContext through helper functions (getRelease, getHooks, getRevision, getChart), the templating path, and value-reuse logic so Helm CLI invocations receive --kube-context (and --namespace where appropriate).
  • For three-way-merge/ownership flows, set envSettings.KubeContext before initializing action.Configuration so the Helm SDK also respects the chosen context.

Reviewed changes

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

Show a summary per file
File Description
cmd/upgrade.go Adds kubeContext to diffCmd, wires a --kube-context flag into helm diff upgrade, and passes the context through to getRelease, getHooks, template, and the Helm SDK action configuration where three-way merge/ownership is used.
cmd/rollback.go Adds a kubeContext field and --kube-context flag to the rollback command and passes that context into getRelease/getRevision calls so rollbacks use the selected kube context.
cmd/revision.go Extends the revision command with a kubeContext field and flag and forwards it into getRelease/getRevision so revision comparisons run against the correct context.
cmd/release.go Adds kubeContext support and flag to the release comparison command and threads it into getRelease/getChart for both releases being compared.
cmd/helm.go Updates Helm helper functions to accept and append --kube-context (and now --namespace for some calls) and ensures template and writeExistingValues propagate the selected context to the underlying helm CLI.

Comment on lines +145 to 149
func getHooks(release, namespace, kubeContext string) ([]byte, error) {
args := []string{"get", "hooks", release}
if namespace != "" {
args = append(args, "--namespace", namespace)
}
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

The new kubeContext plumbing in the Helm CLI helper functions (e.g., getRelease/getHooks/getRevision/getChart) is not covered by tests, even though we use a fake HELM_BIN in main_test.go to assert exact argument lists. It would be good to add tests that run a diff command with --kube-context and extend the stubs to expect the --kube-context flag so regressions in how the context is forwarded to Helm are caught early.

Copilot uses AI. Check for mistakes.
Comment on lines 191 to +207
flags = append(flags, "--namespace", d.namespace)
}
if d.kubeContext != "" {
flags = append(flags, "--kube-context", d.kubeContext)
}
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

template now appends --kube-context (and --namespace) to the Helm CLI flags, but there is no test asserting that these flags are actually passed through. Please add coverage (using the fake HELM_BIN harness) for a helm diff upgrade invocation with --kube-context so changes to this flag wiring do not silently break context selection.

Copilot uses AI. Check for mistakes.
Comment on lines +430 to +434
if d.namespace != "" {
args = append(args, "--namespace", d.namespace)
}
if d.kubeContext != "" {
args = append(args, "--kube-context", d.kubeContext)
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

writeExistingValues now forwards --namespace and --kube-context to helm get values, but this behavior is not exercised by tests. Consider adding a test path that triggers value reuse (e.g., --reuse-values/--reset-then-reuse-values) with --kube-context set and updating the fake Helm stubs to expect these flags, to ensure existing-values resolution stays aligned with the selected kube context.

Copilot uses AI. Check for mistakes.
Add tests to verify that --kube-context flag is properly passed to
helm commands, addressing review comments from PR #924:

- Test basic --kube-context flag propagation to helm commands
- Test --kube-context with --reuse-values flag
- Test that --namespace is also passed when using --kube-context
- Add wildcard argument matching for dynamic temp file paths

Signed-off-by: yxxhero <[email protected]>
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.

[feature request] support for --kube-context

2 participants