devops-works / binenv

One binary to rule them all. Manage all those pesky binaries (kubectl, helm, terraform, ...) easily.
MIT License
366 stars 44 forks source link

Kubectl/Helm completions not working with binenv #256

Open jmischler72 opened 1 month ago

jmischler72 commented 1 month ago

Hello, I have a Oh-my-zsh shell and ever since i installed my tools with binenv, i dont have any completions from the omz plugins kubectl and helm. I tried the binenv completion steps but it still isn't working:

Zsh:

# If shell completion is not already enabled in your environment you will need
# to enable it.  You can execute the following once:

$ echo "autoload -U compinit; compinit" >> ~/.zshrc

# To load completions for each session, execute once:
$ binenv completion zsh > "${fpath[1]}/_binenv"

# You will need to start a new shell for this setup to take effect.

The quickstart for linux didn't help either

leucos commented 3 weeks ago

Thanks or reporting this @jmischler72 Indeed there is an issue with completion. We're looking into it.

leucos commented 3 weeks ago

Can you tell what version you are using ?

vfricou commented 3 weeks ago

Hello,

I’ve exactly same problem.

I’ve try with fresh zsh without any custom in zshrc just necessary for binenv (with completions) and kubectl (with completions). Fresh binenv installation and fresh kubectl command installation through binenv.

It’s seem to completion couldn’t be correctly loaded/called due to shims call for kubectl commands, but I’m not sure.

Version for me :

leucos commented 1 week ago

@jmischler72 @vfricou this should be fixed in v0.19.11.

Could you try to binenv update && binenv install binenv please ?

If you still have issues with the new version, please do the following:

export BASH_COMP_DEBUG_FILE=/tmp/binenvdebug
kubectl g<TAB><TAB>

and paste the /tmp/binenvdebug file here (please sanitize any sensitive information before).

Thanks !

vfricou commented 1 week ago

Hello,

I’ve try with fully clean bash or zsh environment to validate.

On Linux bash : work for first completion level. (kubectl g), but not for next levels (kubectl get po). On Linux zsh : work with exactly same behaviour (with adapted completion loading from bash to zsh).

On MacOS both bash (clean) or zsh (actually customized) : Completion won’t load and debug file wasn’t created. I’m assured for read/write rights on folder/file to generate debug.


Debug bash Linux :

========= starting completion logic ==========
cur is g, words[*] is kubectl g, #words[@] is 2, cword is 1
Truncated words[*]: kubectl g,
lastParam g, lastChar g
Calling kubectl __complete g
binenv called in shim mode for "kubectl __complete g"
The completion directive is: 4
The completions are: get    Display one or many resources

Activating no file completion
__kubectl_handle_completion_types: COMP_TYPE is 9
COMPREPLY[0]: get   Display one or many resources
Removed description from single completion, which is now: get

========= starting completion logic ==========
cur is p, words[*] is kubectl get p, #words[@] is 3, cword is 2
Truncated words[*]: kubectl get p,
lastParam p, lastChar p
Calling kubectl __complete get p
binenv called in shim mode for "kubectl __complete get p"
The completion directive is: 4
The completions are:
Activating no file completion
__kubectl_handle_completion_types: COMP_TYPE is 9

========= starting completion logic ==========
cur is p, words[*] is kubectl get p, #words[@] is 3, cword is 2
Truncated words[*]: kubectl get p,
lastParam p, lastChar p
Calling kubectl __complete get p
binenv called in shim mode for "kubectl __complete get p"
The completion directive is: 4
The completions are:
Activating no file completion
__kubectl_handle_completion_types: COMP_TYPE is 63

========= starting completion logic ==========
cur is p, words[*] is kubectl get p, #words[@] is 3, cword is 2
Truncated words[*]: kubectl get p,
lastParam p, lastChar p
Calling kubectl __complete get p
binenv called in shim mode for "kubectl __complete get p"
The completion directive is: 4
The completions are:
Activating no file completion
__kubectl_handle_completion_types: COMP_TYPE is 63

Debug zsh Linux :

========= starting completion logic ==========
CURRENT: 2, words[*]: kubectl g
Truncated words[*]: kubectl g,
lastParam: g, lastChar: g
About to call: eval kubectl __complete g
binenv called in shim mode for "kubectl __complete g"
completion output: get  Display one or many resources
:4
last line: :4
directive: 4
completions: get    Display one or many resources
flagPrefix:
Adding completion: get:Display one or many resources
Calling _describe
_describe found some completions

========= starting completion logic ==========
CURRENT: 3, words[*]: kubectl get p
Truncated words[*]: kubectl get p,
lastParam: p, lastChar: p
About to call: eval kubectl __complete get p
binenv called in shim mode for "kubectl __complete get p"
completion output: :4
last line: :4
directive: 4
completions:
flagPrefix:
Calling _describe
_describe did not find completions.
Checking if we should do file completion.
deactivating file completion

========= starting completion logic ==========
CURRENT: 3, words[*]: kubectl get po
Truncated words[*]: kubectl get po,
lastParam: po, lastChar: o
About to call: eval kubectl __complete get po
binenv called in shim mode for "kubectl __complete get po"
completion output: :4
last line: :4
directive: 4
completions:
flagPrefix:
Calling _describe
_describe did not find completions.
Checking if we should do file completion.
deactivating file completion
leucos commented 1 week ago

Thanks !

This is weird; I have a different output here.

========= starting completion logic ==========
cur is p, words[*] is kubectl get p, #words[@] is 3, cword is 2
Truncated words[*]: kubectl get p,
lastParam p, lastChar p
Calling kubectl __complete get p
binenv called in shim mode for "kubectl __complete get p"
The completion directive is: 4
The completions are: persistentvolumeclaims
persistentvolumes
pods
podtemplates
provisioningrequests.autoscaling.x-k8s.io
prioritylevelconfigurations.flowcontrol.apiserver.k8s.io
pods.metrics.k8s.io
podmonitors.monitoring.coreos.com
probes.monitoring.coreos.com
prometheusagents.monitoring.coreos.com
prometheuses.monitoring.coreos.com
prometheusrules.monitoring.coreos.com
podmonitorings.monitoring.googleapis.com
podlogs.monitoring.grafana.com
poddisruptionbudgets.policy
priorityclasses.scheduling.k8s.io

Activating no file completion
__kubectl_handle_completion_types: COMP_TYPE is 63

What does ~/.binenv/binaries/kubectl/1.30.1 __complete get p does return ?

And kubectl __complete get p ?

(if you're still on 1.30.1, otherwise please adjust version)

leucos commented 1 week ago

Oh well,I think this is because you do not have a connetion to a k8s API available, and the second level will check the available resources from the API:

$ kubectl __complete get p
E0627 11:08:11.427694 2431754 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused
:4
Completion ended with directive: ShellCompDirectiveNoFileComp

So this sounds normal.

vfricou commented 1 week ago

For kubectl and helm completion on Linux, it’s OK

Effectively, with correct KUBECONFIG file exported, it’s OK on Linux.

But for MacOS issues stay present, and bash debug file export don’t work.

leucos commented 1 week ago

Did you follow kubectl instructions there (for bash & zsh) ? https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/#enable-shell-autocompletion