kubectl
kubectl copied to clipboard
kubectl plugin completion searches all of PATH, even when not needed
(follow-up from #1336)
What happened:
kubectl 1.26.0
added completion for plugins. WSL2 (by default) adds the Windows %PATH%
to the Linux $PATH
. Since kubectl <TAB>
searches $PATH
for plugins (e.g. kubectl-foo
), this is extremely slow.
Similarly, if the plugin exists, but doesn't provide a completion script (e.g. kubectl_complete-foo
), kubectl f<TAB>
is also extremely slow.
This is not that bug. That's explained (and a workaround is given) in #1336.
This issue is about when the plugin is specified (and found), and it does have a completion script. Even if the completion script is in the first entry in $PATH
, kubectl searches every directory anyway.
And kubectl foo <TAB>
is still extremely slow.
See the comment https://github.com/kubernetes/kubectl/issues/1336#issuecomment-1483911662, wherein:
I see that when it’s doing completion for a specific plugin, the code still looks for all plugins. That would explain why things remain slow when the WSL path contains all the windows paths.
What you expected to happen:
If I have a kubectl plugin, with a completion script, and both are early in $PATH
, I expect kubectl completion to avoid searching all of $PATH
and to be much quicker to respond.
How to reproduce it (as minimally and precisely as possible):
- Using WSL2, with defaults, observe that
$PATH
has a lot of/mnt/c/Program Files/Whatever
entries in it. - Write a simple kubectl plugin, put it somewhere early in
$PATH
. I had https://github.com/rlipscombe/kubectl-ssh in$HOME/bin
. - Observe that
kubectl ssh <TAB>
is really slow (it useskubectl __complete port-forward
to do its completion). - Observe that
kubectl __complete port-forward
isn't slow.
Anything else we need to know?:
The workaround given in #1336 also addresses the problem here, which probably lowers the priority of this issue.
Environment:
- Kubernetes client and server versions (use
kubectl version
): kubectl client 1.26.1; server version doesn't matter. - Cloud provider or hardware configuration: not relevant
- OS (e.g:
cat /etc/os-release
): Ubuntu 22.04.2 LTS on WSL 2 (version 1.1.5.0) on Windows 11 (build 23419.ni_prerelease.230317-1432).