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

kubectl: Allow namespaces with prefix #123142

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

Conversation

iCiaran
Copy link

@iCiaran iCiaran commented Feb 5, 2024

What type of PR is this?

/kind bug
/kind regression

What this PR does / why we need it:

Strip the prefix from the namespace flag if it starts with "namespace/", "namespaces/", or "ns/" (case insensitive), allowing the output of kubectl get ns -o name to be used directly in subsequent commands.

This was previously addressed in #50579, but lost in a refactor to config flag parsing (#63373).

Which issue(s) this PR fixes:

Fixes #29271

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fixed a regression in flag parsing, to allow using prefixed namespaces (kubectl -n namespace/example)

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


Strip the prefix from the namespace flag if it starts with "namespace/",
"namespaces/", or "ns/" (case insensitive). This allows the output of
`kubectl get ns -o name` to be used directly in subsequent commands.
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/regression Categorizes issue or PR as related to a regression from a prior release. labels Feb 5, 2024
Copy link

linux-foundation-easycla bot commented Feb 5, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: iCiaran / name: Ciaran Moran (680dd36)

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. 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 Feb 5, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @iCiaran!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

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

@k8s-ci-robot
Copy link
Contributor

Hi @iCiaran. 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. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Feb 5, 2024
@iCiaran
Copy link
Author

iCiaran commented Feb 6, 2024

/sig cli

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 6, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: iCiaran
Once this PR has been reviewed and has the lgtm label, please assign eddiezane 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

@yankay
Copy link
Member

yankay commented Feb 6, 2024

/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 Feb 6, 2024
@iCiaran
Copy link
Author

iCiaran commented Feb 9, 2024

Hi @pwittrock, @seans3, would be great to get some feedback on this, thanks!

@bo0ts
Copy link

bo0ts commented Apr 15, 2024

Any reason why this hasn't been merged yet? That fix would be really appreciated.

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.

/hold

At this point in time, I don't consider this regression anymore.
/remove-kind regression

The <resource>/<name> pattern is good as an argument, where we need to explicitly specify resource type, for explicit flags, like -n or especially better visible with --namespace namespace/xyz it's overly verbose. Also this part can easily managed through some sort of cut invocation to skip the namespace part.

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. and removed kind/regression Categorizes issue or PR as related to a regression from a prior release. labels Apr 17, 2024
@bo0ts
Copy link

bo0ts commented Apr 18, 2024

@soltysh I really consider this a worthwhile QOL change that improves many of use cases.

@iCiaran
Copy link
Author

iCiaran commented Apr 21, 2024

For me it's about having kubectl work in an intuitive way, in most (all?) other cases the get xyz -o name output can be used directly in another command. While the workaround is simple, having to remember that namespaces are an exception is a minor nuisance.

As to the long gap - it's something that's bugged me for a couple of years, I just didn't get round to trying to do something about it until now.

If not merging then a comment on #29271 noting that the original fix no longer works would be appreciated, it's where I (and I'm sure many others) ended up when searching for why you can't use -n namespace/foo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/bug Categorizes issue or PR as related to a bug. 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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: In Progress
Development

Successfully merging this pull request may close these issues.

kubectl -n should support both -n namespace/yournamespace and -n yournamespace
5 participants