Skip to content
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

fix: add namespace autocompletion for kubectl config set-context command #124994

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TessaIO
Copy link
Contributor

@TessaIO TessaIO commented May 20, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR aims to add the namespace autocompletion for kubectl config set-context command

Which issue(s) this PR fixes:

Fixes kubernetes/kubectl#1564

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Added namespace autocompletion for kubectl config set-context command

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

N/A

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. labels May 20, 2024
@k8s-ci-robot k8s-ci-robot requested a review from seans3 May 20, 2024 12:46
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/cli Categorizes an issue or PR as relevant to SIG CLI. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels May 20, 2024
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label May 20, 2024
@TessaIO
Copy link
Contributor Author

TessaIO commented May 22, 2024

@ah8ad3 wanna take a look at this?

@dharmit
Copy link

dharmit commented Jun 7, 2024

I can confirm that it works as expected:

$ _output/bin/kubectl config set-context --current --namespace
-- completions --
default          kube-node-lease  kube-public      kube-system

@@ -79,6 +79,12 @@ func NewCmdConfigSetContext(out io.Writer, configAccess clientcmd.ConfigAccess)
cmd.Flags().Var(&options.cluster, clientcmd.FlagClusterName, clientcmd.FlagClusterName+" for the context entry in kubeconfig")
cmd.Flags().Var(&options.authInfo, clientcmd.FlagAuthInfoName, clientcmd.FlagAuthInfoName+" for the context entry in kubeconfig")
cmd.Flags().Var(&options.namespace, clientcmd.FlagNamespace, clientcmd.FlagNamespace+" for the context entry in kubeconfig")
cmdutil.CheckErr(cmd.RegisterFlagCompletionFunc(
Copy link
Member

Choose a reason for hiding this comment

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

I think, simplified version would be like in here

ValidArgsFunction: completion.ResourceNameCompletionFunc(f, "pod"),
;

ValidArgsFunction:     completion.ResourceNameCompletionFunc(f, "namespace"),

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're actually setting:

ValidArgsFunction: completion.ContextCompletionFunc

We can't override it right?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that's possible to replace these two, because the added behavior only runs completion for namespace flag. But i think it's more cleaner IMO to move this section inside ContextCompletionFunc, this looks good too.

staging/src/k8s.io/kubectl/pkg/cmd/config/config.go Outdated Show resolved Hide resolved
@TessaIO TessaIO force-pushed the fix-autocompletion-for-set-context-namespace branch from 262ef48 to 5a8be05 Compare June 8, 2024 17:41
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 8, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: TessaIO
Once this PR has been reviewed and has the lgtm label, please assign apelisse for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Signed-off-by: TessaIO <ahmedgrati1999@gmail.com>
@TessaIO TessaIO force-pushed the fix-autocompletion-for-set-context-namespace branch from 5a8be05 to 53746db Compare June 8, 2024 17:44
@TessaIO
Copy link
Contributor Author

TessaIO commented Jun 8, 2024

@ardaguclu thanks for the review! I updated the code and left some replies.

@TessaIO
Copy link
Contributor Author

TessaIO commented Jun 8, 2024

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

Completion not working for kubectl config set-context --current <namespace>
5 participants