Closed AlexandreRoba closed 4 years ago
The autocomplete seems to work but I get an error every time I start an Iterm2 zsh terminal
What is the error?
Please specify the error. I'll close in two weeks if not updated. Thanks.
Seems this is hitting me as well. How do I see errors when sourcing a zsh file? I just get the return error of 127. Writing to a file and then running zsh completions-file
is not the same as sourcing even for syntax checking, if I remember zsh internals correctly.
I did verify that 1.7.11 did not have this, and 1.8.5 still does.
I am also experiencing this issue, on Manjaro Linux.
% uname -a
Linux pinta 4.14.3-1-MANJARO #1 SMP PREEMPT Thu Nov 30 14:22:30 UTC 2017 x86_64 GNU/Linux
% zsh --version
zsh 5.4.2 (x86_64-unknown-linux-gnu)
% kubectl version
Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.0", GitCommit:"6e937839ac04a38cac63e6a7a306c5d035fe7b0a", GitTreeState:"clean", BuildDate:"2017-09-28T22:57:57Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
This is still accurate for me two. I learned to live with it :(. I do not have more information on the error. The only thing I know is that I'm getting a SIG 127. I tried to have more info but this is as far as my knowledge can lead me to.
What happens if you run kubectl completion zsh
? Can somebody maybe post that? (maybe use a paste-bin :-)
when I run
kubectl completion zsh
it generates the completion scrips.
You can find the generated script in the attached file. output.log
Thank you @AlexandreRoba
I've run that script, just changed that last line from _complete kubectl >/dev/null
to _complete kubectl
to see why it fails. For the record, here is the error: complete.sh:8680: command not found: _bash_comp
.
I'll punt to @sttts since I think he knows much more about that.
Excellent. I did the same modification and I get the same error. Thanks @apelisse for your swift reply.
Can you load the zsh auto-completion frameworks? I guess you have no other autocompletion enabled, so they are not launched already:
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
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.
Hi,
thanks for the help.
I have edited and added the two lines at the top of my .zshrc script files as:
# Autoload the ZSH completion to avoid kubectl autocomplete error
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
Those new lines execute properly (no error) but the kubctl autocomplete script still raise same error. The command _bash_comp is still unknow. Do I have to install a "zsh autocomplete framework"?
I tried to install the zsh-completions framework and activated the plugin on my oh-my-zsh but still the same error.
Tried on MacOS Sierra with zsh 5.3.1 installed via brew in a new user's homedir:
autoload -U +X compinit && compinit
source <(./kubectl completion zsh)
Works fine.
I tried with:
I'm still getting the error. Should I remove this as GCloud component and install it with brew?
Same error here _bash_comp
unknown
FWIW I ended up using the oh-my-zsh plugin which doesn't seem to cause the issue.
Same error here but I was able to solve it.
That error appeared after upgrade some packages via brew upgrade
and update kubernetes for mac
brew install kubernetes-cli
And then
brew link kubernetes-cli
because this warning:
Warning: kubernetes-cli 1.9.3 is already installed, it's just not linked.
I don't know if this is going to help you but just in case.
PS: I don't know if it is necessary but I've installed zsh-completions framework and activated the plugin.
I get 127 returned from sourcing this, but completion actually works.
I do load
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
before sourcing a pre-generated copy of kubectl completion zsh
.
None of helm, kops or minikube autocompletion exhibit this behaviour.
Spot on,
17 __kubectl_bash_source() {
19 alias _expand=_bash_expand
20 alias _complete=_bash_comp
25 }
_bash_expand
and _bash_comp
are undefined.
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/
/sig cli /area kubectl
/priority P2
I can confirm I have the same problem:
➜ k8s-deploy git:(master) ✗ which kubectl
/Users/plauri/.applications/google-cloud-sdk/bin/kubectl
➜ k8s-deploy git:(master) ✗ kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.7", GitCommit:"0c38c362511b20a098d7cd855f1314dad92c2780", GitTreeState:"clean", BuildDate:"2018-08-20T10:09:03Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"10+", GitVersion:"v1.10.6-gke.11", GitCommit:"42df8ec7aef509caba40b6178616dcffca9d7355", GitTreeState:"clean", BuildDate:"2018-11-08T20:06:00Z", GoVersion:"go1.9.3b4", Compiler:"gc", Platform:"linux/amd64"}
➜ k8s-deploy git:(master) ✗ zsh --version
zsh 5.6.2 (x86_64-apple-darwin18.0.0)
Same error when sourcing 'kubectl completion zsh':
command not found: _bash_comp
I don't know much about zsh completions, but since this thread (and the code) is the only reference I can find to _bash_comp on the internet I'm pretty sure it's a typo for _bash_complete (which exits 0 for me).
I can file a PR to fix it later.
I tripped over this trying to debug my antigen setup where it won't autocomplete (it does when I manually source it), but fixing this didn't seem to help.
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.
My workaround on my MacOS Mojave was to install kubectl via homebrew, and now all works like a charm.
I'm having this same trouble on PureOS (a Debiant variant). I'm using this in my ~/.zshrc
file as a workaround:
source <(kubectl completion zsh)
clear
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 by brew
. The content of /usr/local/share/zsh/site-functions/_kubectl
is the same as the output from kubectl 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 as kubectl
for generating CLI with completions. If I ran source <(kubectl completion zsh)
then completions for jx
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!
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
/remove-lifecycle stale
I tried this on a Ubuntu and MacOS High Sierra 10.13.6 machine and my Ubuntu machine VERSION="18.04.2 LTS (Bionic Beaver)"
I did not have zsh installed on either so I installed on both and ran source <(kubectl completion bash)
. On my Ubuntu I ran into zero issues. On the MacOS I simply got a command not found compinit
error (as did @sttts).
Looking through this thread, it seems as if users have issues when they have different and unique use cases (beta version of Sierra, Prezto framework, using PureOS, etc).
I had kubectl installed from running brew install minikube
, but I also tested when building from source make WHAT=./cmd/kubectl
I set my PR https://github.com/kubernetes/kubernetes/pull/79079 to close this issue. This PR simply loads compinit
as this seems to be the only consistent and reproducible error I can get from this thread, and my own experience.
@seans3 When you have a chance (I know you are super busy), let me know what you think of my above triage. I can always set my PR above to leave this open but I think it is good to close.
Just had this issue, and played with it a bit.
When I've placed the auto completion in the end of my .zshrc
file I got the same exit code 127 (that is after adding some stuff to my fresh installation.
Once I've moved the autocomplete command to be right after sourcing zsh
# zsh
export ZSH="/Users/omer/.oh-my-zsh"
ZSH_THEME=powerlevel10k/powerlevel10k
plugins=(git)
source $ZSH/oh-my-zsh.sh
# kubernetes
source <(kubectl completion zsh)
I get exit 0 and all is ok. I didn't had time to investigate what's going on that cause this, but it is for me.
In case this helps someone else down the line; I was running into a similar error where autocomplete would only work if I ran the command twice and it returned error 127. I resolved this by ensuring that the latest version of kubectl was installed and first in my path.
As of this writing docker for Mac installs an outdated version of kubectl that appears to have been causing my problems
kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:38:32Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
brew install kubectl
revealed that docker for Mac had done the following
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
....
Possible conflicting files are:
/usr/local/bin/kubectl -> /Applications/Docker.app/Contents/Resources/bin/kubectl
After running brew's suggested command it resolved the issue for me
# To force the link and overwrite all conflicting files:
brew link --overwrite kubernetes-cli
kubectl version
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.1", GitCommit:"4485c6f18cee9a5d3c3b4e523bd27972b1b53892", GitTreeState:"clean", BuildDate:"2019-07-18T14:25:20Z", GoVersion:"go1.12.7", Compiler:"gc", Platform:"darwin/amd64"}
Based on the previous comments I used the following to have the completions running without throwing error or using clear
source <(kubectl completion zsh | sed '/_bash_comp/ s/^#*/#/')
At least with the rest of my configuration
source <(kubectl completion zsh)
alias k=kubectl
works fine while swapping those two lines
alias k=kubectl
source <(kubectl completion zsh)
results in 127 :thinking:
Based on the previous comments I used the following to have the completions running without throwing error or using
clear
source <(kubectl completion zsh | sed '/_bash_comp/ s/^#*/#/')
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 a rm -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 :-(
My current workaround:
In .zshrc
:
fpath=(~/.zsh/completions $fpath)
autoload -U compinit && compinit
Once (or also in .zshrc
if you want it to be always up to date):
kubectl completion zsh > ~/.zsh/completions/_kubectl
/assign Going to try to fix this :crossed_fingers:
Take a look at this PR: https://github.com/kubernetes/kubernetes/pull/88165
I just removed the last line that called _complete like @pmkc suggested. That seemed to fix it for me using zsh on ubuntu 19.10.
Some discussion over on the PR... I may actually just suppress the exit code of the _complete call. I don't seem to need that call, but I'm not quite sure why it is being made, so I hate to completely remove it in case someone needs it.
So basically the only change is:
_complete kubectl 2>/dev/null
To this:
_complete kubectl 2>/dev/null || true
Thoughts?
How does this fix the zsh: command not found: _bash_comp
error?
Isn't the real problem that there is no _bash_comp
?
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.
I 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.
The instructions on https://kubernetes.io/docs/tasks/tools/install-kubectl/ to use
echo 'complete -F __start_kubectl k' >>~/.zshrc
seem wrong for the same reason. Anyone know how to setup completion for an alias?
Update: seems like those instructions might be unnecessary.
@MikaelSmith So eventually it works for you?
Else I could have a look in my install why it works OOTB with antibody+ ohmyzsh plugin for kubectl.
Yeah, seems to work for me. I'm not sure where to update the instructions.
@MikaelSmith you mean make a PR for the docs? repo is here right? https://github.com/kubernetes/website/blob/master/content/en/docs/tasks/tools/install-kubectl.md#user-content-enable-kubectl-autocompletion-1
Yeah, seems to work for me. I'm not sure where to update the instructions.
In the past when I found things in the docs that need to be updated, I just used the edit this page button at the bottom of the page and it will let you make a pull request from there.
I just ran in to this, my problem was I had recently created a backup file at ~/.kube.config.bak
- renaming the file to something else fixed it.
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:
uname -a
):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: