oc: `oc` completion not working despite running the required command `oc completion zsh` or saving output to zsh `fpath`

Not understanding why my oc completion isn’t working despite all of my other completions working perfectly in zsh environment. Downloaded the latest binary for oc and have it installed in my /usr/local/bin/ space and then trying the following scenarios with zero luck: source [<oc completion zsh) and saving that in .zshrc with no success. or simply saving the output to my fpath custom location along with all of my other completions such as kubectl which work fine. oc completion zsh > ~/.oh-my-zsh/completions/_oc After running any of the above I still get nothing for tab completion against oc.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (6 by maintainers)

Most upvoted comments

There are a couple of other workarounds for this, such as downgrading your client for the oc completion zsh command, or replacing doing a s/kubectl/oc/ as a one-liner.

# Load the oc completion code for zsh[1] into the current shell
source <(oc completion zsh | sed -e 's/kubectl/oc/g')
# Set the oc completion code for zsh[1] to autoload on startup
oc completion zsh | sed -e 's/kubectl/oc/g' > "${fpath[1]}/_oc"

Linking related upstream issue/PR with possibly a simpler solution that unwrapping the oc completion command.

Upstream issue: https://github.com/kubernetes/kubernetes/issues/106968 Upstream PR: https://github.com/kubernetes/kubernetes/pull/106969

It looks like the upstream fix is just waiting on a final approval.

the kubectl completion works fine on zsh but it appears the add line compdef kubectl _kubectl breaks the oc completion starting from release-4.8

this is my fix

# cat ~/.zshrc | grep "oc completion"
source <(oc completion zsh | sed -e 's/compdef _kubectl kubectl/compdef _oc oc/' )

# oc version
Client Version: 4.9.8
Kubernetes Version: v1.20.2

it appears that on v1.20.2 the code is different https://github.com/kubernetes/kubectl/blob/release-1.20/pkg/cmd/completion/completion.go#L146

this change was from Kubernetes version v1.22 https://github.com/kubernetes/kubectl/blob/release-1.22/pkg/cmd/completion/completion.go#L152

@eifrach It appears https://github.com/openshift/oc/blob/master/contrib/completions/zsh/oc is just a generated file for testing purposes and not a template. The oc completion command is just a wrapper for kubectl completion so the issue is going to be a change upstream to how this command produces the zsh completions and would not be as simple as fixing the generated file.

It looks like the compdef kubectl _kubectl line is now being hardcoded in the upstream kubectl completion zsh function:

https://github.com/kubernetes/kubectl/blob/master/pkg/cmd/completion/completion.go#L173