Linkerd2: linkerd completion command does not work as expected

Created on 30 Jan 2020  路  7Comments  路  Source: linkerd/linkerd2

Bug Report

The linkerd completion command does not work as expected on zsh.

What is the issue?

The completion scripts are generated, but sourcing them does not provide shell completion. Not sure if this error is restricted to only zsh.

How can it be reproduced?

Run:

$ source <(linkerd completion zsh)

Completion does not work

Logs, error output, etc

(If the output is long, please create a gist and
paste the link here.)

linkerd check output

your output here ...

Environment

  • Kubernetes Version: 1.16
  • Cluster Environment: (GKE, AKS, kops, ...) minikube
  • Host OS: linux
  • Linkerd version: stable-2.6

Possible solution

Additional context

Could be an issue with cobra completion script generator. Check https://github.com/spf13/cobra/issues/881

arecli help wanted

Most helpful comment

We've been patiently waiting for the upstream fixes, but if there are workarounds we can apply within Linkerd, we'd _love_ a PR.

All 7 comments

Looks like this is more about the instructions being wrong than a blocker bug itself?

I was able to get linkerd shell completion to work on oh-my-zsh on macOS (10.15) by:

  • First I added autoload -U compinit && compinit to .zsrhrc
  • Then, instead of linkerd completion zsh > "${fpath[1]}/_linkerd" I used linkerd completion zsh > "~/.oh-my-zsh/completions/_linkerd" (not that it matters, it's just that ${fpath[1]} pointed to another oh-my-zsh plugin)

But what really got it working was changing all the lines in the _linkerd script that go:

'(-L --linkerd-namespace)'{-L,--linkerd-namespace}'[Namespace in which Linkerd is installed [$LINKERD_NAMESPACE]]:' \

to

'(-L --linkerd-namespace)'{-L,--linkerd-namespace}'[Namespace in which Linkerd is installed \[$LINKERD_NAMESPACE\]]:' \

With the [ and ] characters in the flag description escaped (thanks to clap-rs/clap#771 that pointed the way).

Indeed, it looks to be an issue with spf13/cobra, in particular, following the links from spf13/cobra#881:

Unfortunately, the changes in https://github.com/spf13/cobra/pull/1070 still haven't been released.

So... looks like we just have to wait for a new release of spf13/cobra, _or_ avoid using square brackets in the flag description.

@aisrael good investigation :+1: Cobra's releases are taking ages, so for now I'd vote for getting rid of the brackets. Would you be up for a PR? :wink:

Any updates on this issue? Is really noone using zsh completion? I'm trying out linkerd the first time and using oh-my-zsh as well (Linux). Still doesnt work. At least someone have a ready regexp for replacing the broken brackets on the fly? I will workround for now doing it manually.
Anyhows linkerd seems awesome ^^


My workaround does replace all the mentioned [$LINKERD_NAMESPACE] with [$LINKERD_NAMESPACE] but it still does not work as proposed by @aisrael

This is my complete fix that doesn't fix it unfortunately :/

autoload -U compinit && compinit
(linkerd completion zsh | sed 's/\[$LINKERD_NAMESPACE\]/\\\[$LINKERD_NAMESPACE\\\]/g') > "${fpath[1]}/_linkerd"

Another update ... it does work. Just sourcing the above files is NOT sufficient. Whoever encounters this: You need to restart the shell completely (actually I don't know why, probably a oh-my-zsh thing)

simple () will also work fine

We've been patiently waiting for the upstream fixes, but if there are workarounds we can apply within Linkerd, we'd _love_ a PR.

We've been patiently waiting for the upstream fixes, but if there are workarounds we can apply within Linkerd, we'd love a PR.

As I proposed, "simple ()" should work fine... PR 馃憜

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alpeb picture alpeb  路  3Comments

zaharidichev picture zaharidichev  路  4Comments

vikas027 picture vikas027  路  4Comments

adleong picture adleong  路  4Comments

olix0r picture olix0r  路  3Comments