-
Notifications
You must be signed in to change notification settings - Fork 925
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 autocompletion does not work when using --context flag with a context that contains a colon #1157
Comments
@frederik-b: This issue is currently awaiting triage. SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the The 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. |
The problem is with the However, I believe that if you quote your context it will work. You could try something like this:
As for a permanent fix, we would either need to fix Cobra, or |
Actually, I was wrong, the bug is present, but it is not a regression. The same problem happens with kubectl 1.21.8 which had not yet moved to Go completions. |
After a little bit more testing it does only work when using equal signs and not when using spaces.
and today it worked even with that aws arn:aws:eks stuff with all the colons I believe my first test case was wrong (only namespace without equal sign). I would like to understand why the alias only works with the also a function apparently works the same as an alias |
/assign @brianpursley |
You're right about what is happening regarding cobra's completion function considering I confirmed that @marckhouzam Is there any reason you know of that it would not be a good idea to move to V2? It should be a very simple fix. In the meantime, anyone who needs to use a context name that has a colon can either quote it, like |
@frederik-b Your observation is correct, that completions work when an alias contains This is a known issue an also affects plugin invocations as well. The cause is in this code, where it interprets the first word not starting with a I know it may not be immediately clear what this has to do with completions, but here is what is happening to cause this: When a completion is requested for
In this case, However if you have an alias like:
And then if you do
But the alias expands to:
Now kubectl sees In fact, if you invoke this command you can see the error that occurs, which is hidden when the completion call is made:
So, while I realize this is not ideal, it is an explanation of what is happening and why you have to use |
@brianpursley Bash completion v2 has a couple of benefits beyond this bug fix, but you should be aware of them to know exactly what the change implies:
If you wish to enable descriptions of completion choices kubectl should first move to Cobra 1.3 to get this fix: spf13/cobra#1509 Helm has been using the bash completion v2 in the wild for 4 months (helm 3.7.0) and the only bug report was for this fix that's part of Cobra 1.3. Podman has been using it for even longer than that. |
/retitle kubectl autocompletion does not work when using --context flag with a context that contains a colon |
@marckhouzam Thanks for the info! I'll take a look at upgrading Cobra to 1.3 and turning on descriptions too. We might as well take advantage of the descriptions if we can, since it would be available with V2 completions. |
What happened:
tab autocompletion does not work when explicitly declaring the context
What you expected to happen:
tab autocompletion does work when explicitly declaring the context
How to reproduce it (as minimally and precisely as possible):
does work for me:
does not work for me:
Anything else we need to know?:
I found: #1119
and thought it might fix it, but if I understand correctly this is included in v1.23.0 (not sure though)
and this is still not working
Environment:
kubectl version
): client: v1.23.0, server: 1.20.7-eks-d88609 (and others)cat /etc/os-release
): Fedora Linux 35The text was updated successfully, but these errors were encountered: