-
Notifications
You must be signed in to change notification settings - Fork 316
feat: add --kube-context flag support #924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,38 +130,50 @@ func compatibleHelm3Version() error { | |
| return nil | ||
| } | ||
|
|
||
| func getRelease(release, namespace string) ([]byte, error) { | ||
| func getRelease(release, namespace, kubeContext string) ([]byte, error) { | ||
| args := []string{"get", "manifest", release} | ||
| if namespace != "" { | ||
| args = append(args, "--namespace", namespace) | ||
| } | ||
| if kubeContext != "" { | ||
| args = append(args, "--kube-context", kubeContext) | ||
| } | ||
| cmd := exec.Command(os.Getenv("HELM_BIN"), args...) | ||
| return outputWithRichError(cmd) | ||
| } | ||
|
|
||
| func getHooks(release, namespace string) ([]byte, error) { | ||
| func getHooks(release, namespace, kubeContext string) ([]byte, error) { | ||
| args := []string{"get", "hooks", release} | ||
| if namespace != "" { | ||
| args = append(args, "--namespace", namespace) | ||
| } | ||
| if kubeContext != "" { | ||
| args = append(args, "--kube-context", kubeContext) | ||
| } | ||
| cmd := exec.Command(os.Getenv("HELM_BIN"), args...) | ||
| return outputWithRichError(cmd) | ||
| } | ||
|
|
||
| func getRevision(release string, revision int, namespace string) ([]byte, error) { | ||
| func getRevision(release string, revision int, namespace, kubeContext string) ([]byte, error) { | ||
| args := []string{"get", "manifest", release, "--revision", strconv.Itoa(revision)} | ||
| if namespace != "" { | ||
| args = append(args, "--namespace", namespace) | ||
| } | ||
| if kubeContext != "" { | ||
| args = append(args, "--kube-context", kubeContext) | ||
| } | ||
| cmd := exec.Command(os.Getenv("HELM_BIN"), args...) | ||
| return outputWithRichError(cmd) | ||
| } | ||
|
|
||
| func getChart(release, namespace string) (string, error) { | ||
| func getChart(release, namespace, kubeContext string) (string, error) { | ||
| args := []string{"get", "all", release, "--template", "{{.Release.Chart.Name}}"} | ||
| if namespace != "" { | ||
| args = append(args, "--namespace", namespace) | ||
| } | ||
| if kubeContext != "" { | ||
| args = append(args, "--kube-context", kubeContext) | ||
| } | ||
| cmd := exec.Command(os.Getenv("HELM_BIN"), args...) | ||
| out, err := outputWithRichError(cmd) | ||
| if err != nil { | ||
|
|
@@ -190,6 +202,9 @@ func (d *diffCmd) template(isUpgrade bool) ([]byte, error) { | |
| if d.namespace != "" { | ||
| flags = append(flags, "--namespace", d.namespace) | ||
| } | ||
| if d.kubeContext != "" { | ||
| flags = append(flags, "--kube-context", d.kubeContext) | ||
| } | ||
|
Comment on lines
191
to
+207
|
||
| if d.postRenderer != "" { | ||
| flags = append(flags, "--post-renderer", d.postRenderer) | ||
| } | ||
|
|
@@ -412,6 +427,12 @@ func (d *diffCmd) writeExistingValues(f *os.File, all bool) error { | |
| if all { | ||
| args = append(args, "--all") | ||
| } | ||
| if d.namespace != "" { | ||
| args = append(args, "--namespace", d.namespace) | ||
| } | ||
| if d.kubeContext != "" { | ||
| args = append(args, "--kube-context", d.kubeContext) | ||
|
Comment on lines
+430
to
+434
|
||
| } | ||
| cmd := exec.Command(os.Getenv("HELM_BIN"), args...) | ||
| debugPrint("Executing %s", strings.Join(cmd.Args, " ")) | ||
| defer func() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
kubeContextplumbing in the Helm CLI helper functions (e.g.,getRelease/getHooks/getRevision/getChart) is not covered by tests, even though we use a fakeHELM_BINinmain_test.goto assert exact argument lists. It would be good to add tests that run a diff command with--kube-contextand extend the stubs to expect the--kube-contextflag so regressions in how the context is forwarded to Helm are caught early.