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

add bash-completion for comma separated list on kubectl get #98301

Merged

Conversation

phil9909
Copy link
Contributor

@phil9909 phil9909 commented Jan 22, 2021

What type of PR is this?
/kind feature

What this PR does / why we need it:

kubectl get supports specifying a comma separated list of resource types. E.g.:

kubectl get pods,secrets

Will list all pods and secrets in the current namespace.

This commit adds support to the kubectl bash completion for this feature.
Which means if you type kubectl get pods,sec + tab it will be auto-completed to kubectl get pods,secrets (assuming the cluster does not have a CRD starting with sec).

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

After running make kubectl you need to run source <(./_output/bin/kubectl completion bash) then you can try the new completion.

In theory other kubectl commands support comma separated lists of resources. One can do kubectl edit secret,configmap test which will open an editor with both resources (or fail if one or both don't exist).
As I think the use-cases for other commands are limited, I don't think we need completion for this.
Should this be proven wrong one can simply change the case block.

Does this PR introduce a user-facing change?:

kubectl: add support for bash-completion for comma separated list on `kubectl get`

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


@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. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 22, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @phil9909. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 22, 2021
@phil9909
Copy link
Contributor Author

/sig cli

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. area/kubectl and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jan 22, 2021
@dougsland
Copy link
Member

/assign

@dougsland
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 22, 2021
Copy link
Member

@dougsland dougsland left a comment

Choose a reason for hiding this comment

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

In general looks good the patch also tested. I have few comments.

./_output/local/go/bin/kubectl completion bash > ~/.kube/completion.bash.inc
./_output/local/go/bin/kubectl get pods,sec<TAB>

staging/src/k8s.io/kubectl/pkg/cmd/cmd.go Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/cmd.go Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/cmd.go Outdated Show resolved Hide resolved
@dougsland
Copy link
Member

/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 22, 2021
@dougsland
Copy link
Member

@phil9909 could you please squash the patches?

`kubectl get` supports specifying a comma separated list of resource types. E.g.:

```bash
kubectl get pods,secrets
```

Will list all pods and secrets in the current namespace.

This commit adds support to the kubectl bash completion for this feature. Which means if you type `kubectl get pods,sec<tab>` it will be auto-completed to `kubectl get pods,secrets` (assuming the cluster does not have a CRD starting with `sec`).
@phil9909 phil9909 force-pushed the bash-completion-multiple-resources branch from 0af4784 to 51671ec Compare January 28, 2021 15:45
@phil9909
Copy link
Contributor Author

could you please squash the patches?

Done. While I was on it, I also rebased onto master.

@dougsland
Copy link
Member

/test pull-kubernetes-node-e2e

@dougsland
Copy link
Member

Looks sane to me. We need one more people to review/approve.
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 28, 2021
@phil9909
Copy link
Contributor Author

phil9909 commented Jan 29, 2021

We need one more people to review/approve.

@brianpursley would you mind having a look?

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: phil9909, soltysh

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

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 19, 2021
@phil9909
Copy link
Contributor Author

/test pull-kubernetes-e2e-kind

@k8s-ci-robot k8s-ci-robot merged commit 25aa6cf into kubernetes:master Feb 19, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.21 milestone Feb 19, 2021
@phil9909 phil9909 deleted the bash-completion-multiple-resources branch February 19, 2021 16:43
@marckhouzam
Copy link
Member

This is a nice change! Note that it does not seem to work for zsh.

But I have included this feature in the conversion from bash to Go code of #96087 which allows us to no longer worry about such differences.

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. release-note-none Denotes a PR that doesn't merit a release note. labels Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. 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. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. 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. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants