Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linkerd completion command does not work as expected #3999

Closed
mayankshah1607 opened this issue Jan 30, 2020 · 7 comments · Fixed by #5285
Closed

linkerd completion command does not work as expected #3999

mayankshah1607 opened this issue Jan 30, 2020 · 7 comments · Fixed by #5285

Comments

@mayankshah1607
Copy link
Contributor

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 spf13/cobra#881

@grampelberg
Copy link
Contributor

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

@aisrael
Copy link

aisrael commented Sep 22, 2020

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 spf13/cobra#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.

@alpeb alpeb added the area/cli label Sep 22, 2020
@alpeb alpeb added this to To do in 2.9 - backlog via automation Sep 22, 2020
@alpeb
Copy link
Member

alpeb commented Sep 22, 2020

@aisrael good investigation 👍 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? 😉

@grampelberg grampelberg removed this from To do in 2.9 - backlog Sep 28, 2020
@Flowkap
Copy link

Flowkap commented Nov 4, 2020

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)

@jiraguha
Copy link
Contributor

simple () will also work fine

@olix0r
Copy link
Member

olix0r commented Nov 25, 2020

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

jiraguha added a commit to jiraguha/linkerd2 that referenced this issue Nov 26, 2020
@jiraguha
Copy link
Contributor

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 👆

jiraguha added a commit to jiraguha/linkerd2 that referenced this issue Dec 2, 2020
Signed-off-by: jpiraguha <jiraguha@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants