ohmyzsh: kubectl namespace autocompletion not working

Describe the bug

Hello,

After a recent update to ohmyzsh, i notice this command’s autocomplete no longer seems to work.

Steps to reproduce

  • enable kubectl plugin in .zshrc
  • use this alias or command, expect to attempt to autocomplete namespaces, however just getting local file list currently. kcn which is aliased to
    kubectl config set-context --current --namespace'

Expected behavior

Be able to auto-complete kubernetes namespaces. Currently just get local files

Screenshots and recordings

No response

OS / Linux distribution

osx 11.6.2

Zsh version

5.8

Oh My Zsh version

master (9c84c344)

Terminal emulator

iTerm2

If using WSL on Windows, which version of WSL

No response

Additional context

This worked before my latest update to OhMyZsh, unsure which version i was using before though.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 23 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Just as a note, after I installed rancher desktop this happened to me. I found out I needed to move

### MANAGED BY RANCHER DESKTOP START (DO NOT EDIT)
export PATH="/Users/davidbenson/.rd/bin:$PATH"
### MANAGED BY RANCHER DESKTOP END (DO NOT EDIT)

from the end of my .zshrc to before the line for sourcing oh-my-zsh:

source $ZSH/oh-my-zsh.sh

I still have this problem…

kubectl --namespace <TAB> config set-context --current shows the namespace list,

butn kcn <TAB> shows only the local files list?

Upgrading kubectl to 1.24 didn’t solve this for me.

Works:

  • kgp TAB
  • kgp --namespace TAB
  • kubectl --namespace <TAB> config set-context --current as @mcornella suggested

Doesn’t work:

  • kcn TAB

I am experiencing the same issue unfortunately. sourcing the completions file seems to work just fine though.

No, i am just getting local file names as options for tab completing. But i’m wondering if this is an upstream issue perhaps. Looking at https://github.com/kubernetes/kubernetes/pull/106739

I am using kubectl 1.22 from brew. I checked with 1.23 also from brew and used source <(kubectl completion zsh) but still lack the completion it seems. So maybe this is not a zsh issue since other completions work fine.

Testing in a docker container and some old kubectl versions and loading completions with source <(kubectl completion zsh) it seems the completion worked in kubectl 1.21. If the zsh completion just gets the latest kubectl completion then I think that explains the issue, since 1.23 is the latest. I think the above issue they may fix it in kubectl 1.24.

@mcornella yes, this works for me

That’s interesting. In the current version, does it work if you instead source the file?

source "$ZSH_CACHE_DIR/completions/_kubectl"

Hi, auto completion works for me again after sourcing this.

Can you test if #10594 works? Try with omz pr test 10594.

I’m afraid this doesn’t work for me. Tried setting my .zshrc to the default template and added kubectl plugin. But the kcn alias does not seem to autocomplete still.