kubectl: WSL2 -very slow bash autocompletion since version 1.26.0
What happened:
Since updating to kubectl 1.26.0
on both my WSL2 distros (Ubuntu and Fedora Remix). Bash automcompletion is super slow.
Ubuntu was 1.25.2 Fedora was 1.25.4
What you expected to happen:
Autocompletion should be as fast as < 1.26.0
How to reproduce it (as minimally and precisely as possible):
Update to 1.26.0. Type kubectl
followed by TAB
Anything else we need to know?:
This seems to be a known issue in WSL. But, I am not experiencing it with other tools like: flux
or tanzu
(for which I installed completions manually). So it seems a combination of a new version of kubectl and the WSL Windows Path “issue”.
Environment:
- Kubernetes client and server versions (use
kubectl version
):
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.0", GitCommit:"b46a3f887ca979b1a5d14fd39cb1af43e7e5d12d", GitTreeState:"clean", BuildDate:"2022-12-08T19:58:30Z", GoVersion:"go1.19.4", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.7
- Cloud provider or hardware configuration: NA
- OS (e.g:
cat /etc/os-release
):
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
NAME="Fedora Remix for WSL"
VERSION="37"
ID=fedoraremixforwsl
ID_LIKE=fedora
VERSION_ID=37
PLATFORM_ID="platform:f37"
PRETTY_NAME="Fedora Remix for WSL"
ANSI_COLOR="0;34"
CPE_NAME="cpe:/o:fedoraproject:fedora:37"
HOME_URL="https://github.com/WhitewaterFoundry/Fedora-Remix-for-WSL"
SUPPORT_URL="https://github.com/WhitewaterFoundry/Fedora-Remix-for-WSL"
BUG_REPORT_URL="https://github.com/WhitewaterFoundry/Fedora-Remix-for-WSL/issues"
PRIVACY_POLICY_URL="https://github.com/WhitewaterFoundry/Fedora-Remix-for-WSL/blob/master/PRIVACY.md"
FEDORA_REMIX_VERSION=37.0.2
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 23 (13 by maintainers)
The only way to avoid the slow down in every scenario is to remove the Windows paths as described in comments further above.
Optimizing the code as we’ve discussed would probably improve the situation for completing commands of a plugin but only if, as you have taken the time to insure, the completion script of the plugin is in the first path on the list.
It would still not improve completion for the first argument, e.g.,
kubectl <TAB>
.So I would suggest opening a different issue explaining things, if you feel it’s worth it, and after that it will depend if anyone feels it’s worth working on.
Ok so we know problem now. Thanks again @Karocyt ! Using the very long PATH should only affect completion for a limited set of scenarios:
Once kubectl detects it is doing completion for a plugin’s arguments, it looks through the PATH variable looking for a script called
kubectl_complete-<pluginName>
which will provide the completion choices. Most plugins don’t yet provide such a script so kubectl goes through the entire PATH looking for the script.BTW, this PATH problem will also make using any kubectl plugin very slow.
This comment says you can actually configure WSL to not append the windows paths: https://github.com/microsoft/WSL/issues/4234#issuecomment-505609403
But if you do need the windows paths to be included in PATH, there isn’t much you can do… What I can think of is wrapping kubectl in a function that changes the PATH variable just for the kubectl invocation.
kubectl plugin list
seems to be the culprit indeed, but if it’s about listing plugins, why is it hanging for plugins args too ? At this stage there would be no point listing plugins as a name was already given and is set in stone…EDIT: Removing all the Windows paths from
$PATH
fixed it !Windows appends the content of the whole Windows
PATH
variable to Ubuntu’s$PATH
. I can’t find a specific culprit but it seems that the more Windows files on the Path, the slower it gets. I got down to 5 seconds (from 20-30) removing the bigger half of it, and it’s instant if I clean everything. I guess there is some kind of translation layer for Windows files, and listing all these folders/files eats up a lot.So it is technically a WSL “bug”, but this one was closed long ago (it seems that accessing Windows executables from WSL was one of their more appraised features, don’t ask me why), so this will need a hack/fix on Kubernetes side…
Maybe stripping
/mnt/one-letter-drive/*
fromPATH
when on WSL ?Thanks for the info @Karocyt. This points to the fact that kubectl 1.26 now completes plugin names also, which goes through the entire list of paths present in
$PATH
.To confirm you can check if listing plugins is slow by doing :
kubectl plugin list
Sorry, my mistake. I saw “Ubuntu” and didn’t even look at the version assuming it was your os version.
So now you are running kubectl 1.26. What version of kubectl were you running before?
I’m asking because the only change I’m aware of between 1.25 and 1.26 is that we’ve enabled completion descriptions. However we’ve also tested for performance for this change. On the other hand, if you were previously running an even older kubectl, then the problem may be something else that changed before 1.26