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)

Commits related to this issue

Most upvoted comments

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.

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/^#*/#/')

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:

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.

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 🤔

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 get 127 returned from sourcing this, but completion actually works.

  • macOS 10.13.4
  • zsh 5.3
  • antibody 3.4.6
  • kubectl v1.10.2

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.

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

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!

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 😦

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 unknown

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.

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.