kubectl: Kubectl completion zsh error
Is this a request for help? (If yes, you should use our troubleshooting guide and community support channels, see http://kubernetes.io/docs/troubleshooting/.): No
What keywords did you search in Kubernetes issues before filing this one? (If you have found any duplicates, you should instead reply there.): Kubectl completion zsh
Is this a BUG REPORT or FEATURE REQUEST? (choose one): BUG REPORT
Kubernetes version (use kubectl version
):
Client Version: version.Info{Major:“1”, Minor:“8”, GitVersion:“v1.8.2”, GitCommit:“bdaeafa71f6c7c04636251031f93464384d54963”, GitTreeState:“clean”, BuildDate:“2017-10-24T19:48:57Z”, GoVersion:“go1.8.3”, Compiler:“gc”, Platform:“darwin/amd64”}
Server Version: version.Info{Major:“1”, Minor:“7+”, GitVersion:“v1.7.8-gke.0”, GitCommit:“a7061d4b09b53ab4099e3b5ca3e80fb172e1b018”, GitTreeState:“clean”, BuildDate:“2017-10-10T18:48:45Z”, GoVersion:“go1.8.3”, Compiler:“gc”, Platform:“linux/amd64”}
Environment:
- Cloud provider or hardware configuration: Cloud
- OS (e.g. from /etc/os-release): Mac OS High Sierra 10.13.2 Beta
- Kernel (e.g.
uname -a
): - Install tools: Iterm2 shell zsh 5.2
- Others:
What happened: source <(Kubectl completion zsh) -> returns a SIG 127 when .zshrc completes The autocomplete seems to work but I get an error every time I start an Iterm2 zsh terminal
What you expected to happen: No error
How to reproduce it (as minimally and precisely as possible): source <(Kubectl completion zsh)
Anything else we need to know:
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 17
- Comments: 50 (17 by maintainers)
Links to this issue
Commits related to this issue
- Stop warning on sourcing. https://github.com/kubernetes/kubectl/issues/125 — committed to nicdoye/dotfiles by nicdoye 6 years ago
Tried on MacOS Sierra with zsh 5.3.1 installed via brew in a new user’s homedir:
Works fine.
Based on the previous comments I used the following to have the completions running without throwing error or using
clear
FWIW I ended up using the oh-my-zsh plugin which doesn’t seem to cause the issue.
Can you load the zsh auto-completion frameworks? I guess you have no other autocompletion enabled, so they are not launched already:
You have to put that into your zsh startup scripts. We should probably add them to the generated completions as well.
Let me know whether that helps.
At least with the rest of my configuration
works fine while swapping those two lines
results in 127 🤔
I’m having this same trouble on PureOS (a Debiant variant). I’m using this in my
~/.zshrc
file as a workaround:I get 127 returned from sourcing this, but completion actually works.
I do load
before sourcing a pre-generated copy of
kubectl completion zsh
.None of helm, kops or minikube autocompletion exhibit this behaviour.
My current workaround:
In
.zshrc
:Once (or also in
.zshrc
if you want it to be always up to date):I’m getting a mix of these errors:
(eval):1: command not found: _bash_complete
And(anon):4: command not found: __start_kubectl
Using the Prezto framework and using the
kubectl
completions installed bybrew
. The content of/usr/local/share/zsh/site-functions/_kubectl
is the same as the output fromkubectl completion zsh
.I looked inside of
~/.zcompdump
and found'kubectl' '_bash_complete -o default -F __start_kubectl'
. I also found'jx' '_bash_complete -o default -F __start_jx'
which is another project that I think uses the same framework askubectl
for generating CLI with completions. If I ransource <(kubectl completion zsh)
then completions forjx
stopped working.What I was doing was rebuilding completion cache via various forms of this:
rm -f ~/.zcompdump; rm -rf ~/.zcompcache && autoload -U compinit && compinit
- this is apparently wrong!What fixed completions for me was to run
rm -f ~/.zcompdump; rm -rf ~/.zcompcache
and then immediately open a new terminal tab which allowed Prezto to regenerate the completion cache. Those two cache file paths are defined by Prezto, so yours might be different. Unsure what sorcery Prezto is doing, but the brave can look here.Now when I look inside of
~/.zcompdump
, I have'jx' '_jx'
and'kubectl' '_kubectl'
like 90%+ of the other entries in there.Hope this helps others! Cheers!
Confirmed with me as well, with zsh 5.7.1. For anyone unaware, @mbtamuli 's
sed
command just comments out line 20:alias _complete=_bash_comp
. Along with arm -f ~/.zcompdump; rm -rf ~/.zcompcache
to clear the completions cache, I was able to resolve the “command not found” error.It looks like https://github.com/kubernetes/kubernetes/pull/79079 was closed due to inactivity 😦
Are there any plans to fix this issue? It breaks the common pattern of
source <(kubectl completion zsh) && echo success || echo failure
. I’ve worked around the issue by using && for fail and || for true, but it’s very ugly.Ironically if the bug does get fixed I’ll have to switch the && and || again: https://xkcd.com/1172/
Same error here
_bash_comp
unknownI normally just do a +1 on the opening post, but in this case explicitly:
Thank you all for fixing this. This was a really a pain in the behind for way too long.
I updated the PR based on discussion in the PR since my previous comment on this issue. Now, I’m just removing the line entirely, and the two aliases as well: _bash_comp and _bash_expand.
@brainbug89 do you have any insight about the purpose of _bash_comp and who would need it? I looked through the code history and couldn’t find anything. I even tried googling for it and only found references to kubectl’s code, so I don’t even know what that is supposed to be.
Over on the PR some people (other than me) have tested it with the lines removed it seems to work fine, it and will close this issue which has been open for 2+ years.
I am happy to revisit the proposed change though if I can better understand the purpose of _bash_comp.
Actually _bash_complete is an internal of bashcompinit that I don’t think is needed (and errors when called like that). I think the last line and alias should just be removed, because it’s broken and seemingly a no-op.