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 parsing of local flags with no args appearing before the command name is broken or at best, confusing #93432

Open
thockin opened this issue Jul 24, 2020 · 8 comments
Assignees
Labels
area/kubectl kind/bug Categorizes issue or PR as related to a bug. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/backlog Higher priority than priority/awaiting-more-evidence. sig/cli Categorizes an issue or PR as relevant to SIG CLI.

Comments

@thockin
Copy link
Member

thockin commented Jul 24, 2020

What happened:

Running a kubectl get with --all-namespaces in the wrong place consumes one extra argument, resulting in a confusing error.

What you expected to happen:

A sane error.

How to reproduce it (as minimally and precisely as possible):

$ k get pods
NAME                         READY   STATUS    RESTARTS   AGE
hostnames-6956d6795f-lgv5m   1/1     Running   0          14d

$ k -n default get pods
NAME                         READY   STATUS    RESTARTS   AGE
hostnames-6956d6795f-lgv5m   1/1     Running   0          14d

$ k --all-namespaces get pods
Error: unknown command "pods" for "kubectl"

Did you mean this?
	logs

Run 'kubectl --help' for usage.

$ k get pods --all-namespaces 
NAMESPACE     NAME                                                       READY   STATUS             RESTARTS   AGE
# lots of result

Environment:

This is a kubectl build at HEAD

/sig cli

@thockin thockin added kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence. area/kubectl labels Jul 24, 2020
@k8s-ci-robot k8s-ci-robot added the sig/cli Categorizes an issue or PR as relevant to SIG CLI. label Jul 24, 2020
@liggitt
Copy link
Member

liggitt commented Jul 25, 2020

This isn't specific to --all-namespaces, it applies to any non-global flag (or unknown flag) that comes before the command name. The following produce the same error:

kubectl --test get pods
kubectl --watch get pods

I guess when cobra encounters unknown/non-global flags it assumes they consume one following arg, while locating the command to run

@liggitt liggitt changed the title Kubectl parsing of --all-namespaces flag is broken or at best, confusing Kubectl parsing of local flags with no args appearing before the command name is broken or at best, confusing Jul 25, 2020
@eladm26
Copy link

eladm26 commented Jul 26, 2020

new contributor, would like tot take this one
/assign

@liggitt
Copy link
Member

liggitt commented Jul 26, 2020

I think this probably has to be fixed upstream in spf13/cobra

@zhouya0
Copy link
Contributor

zhouya0 commented Jul 27, 2020

/cc @knight42 I remember you have worked on this before.

@knight42
Copy link
Member

knight42 commented Jul 27, 2020

@zhouya0 I think this issue is slightly different from kubernetes/kubectl#884. As @liggitt described in #93432 (comment), I believe this is more likely to be a cobra issue.

@eladm26
Copy link

eladm26 commented Jul 28, 2020

ok, so @thockin this indeed seems like a cobra issue

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 26, 2020
@seans3
Copy link
Contributor

seans3 commented Oct 27, 2020

/remove-lifecycle stale
/lifecycle frozen

@k8s-ci-robot k8s-ci-robot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl kind/bug Categorizes issue or PR as related to a bug. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/backlog Higher priority than priority/awaiting-more-evidence. sig/cli Categorizes an issue or PR as relevant to SIG CLI.
Projects
Status: Needs Triage
Development

Successfully merging a pull request may close this issue.

8 participants