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

Progress of the support of shell completion for the "kubectl cert-manager" plugin, coming in Kubernetes 1.24 #4657

Closed
maelvls opened this issue Dec 12, 2021 · 7 comments
Labels
area/ctl Indicates a PR or issue relates to the cert-manager-ctl CLI component kind/feature Categorizes issue or PR as related to a new feature. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@maelvls
Copy link
Member

maelvls commented Dec 12, 2021

Currently, the only way to get shell completion to work when using the cert-manager kubectl plugin is to skip the kubectl plugin mechanism altogether as it can be read on the Kubectl plugin:

While the kubectl plugin is supported, it is recommended to use cmctl as this enables a better experience via tab auto-completion.

In the last couple of weeks, there has been a promising effort for bringing completion support to kubectl plugins. Marc Khouzam proposed the kubectl PR 105867. Cobra also v1.3.0 comes a fix to get flag completion, see below explanation. These two changes should land in kubectl probably in Kubernetes 1.24.

Here is what the completion will look like:

Peek 2021-12-12 17-31

This issue tracks the progress of the kubectl plugin support for kubectl cert-manager.

Plan:

  • Start discussing on this issue the best way of dealing with the "shim" -> as part of the documentation? Or installed by krew?
  • Wait until Kubernetes 1.24 is released, at which point Shell completion for plugins kubernetes/kubernetes#105867 should have been merged.
  • (non-blocking) Wait for the flag bug to be fixed, kubernetes/kubernetes must start using the next release of Cobra which has not been released yet.

Try the completion!

🚧 Last update to the below command lines: 14 January 2022.

If you would like to test the completion support:

  1. Add ~/bin to your PATH. (optional, but the following steps assume that ~/bin is in your PATH).

    export PATH="$HOME/bin:$PATH"
  2. Install the patched kubectl (kubectl PR 105867 + replace cobra v1.2.1 with v1.3.0 to get PR 1161):

    curl -L https://github.com/kubernetes/kubernetes/archive/d50260c72595d8bda78dbb02d1db847477f34a7e.tar.gz | tar xz  -C /tmp
    pushd /tmp/kubernetes-d50260c72595d8bda78dbb02d1db847477f34a7e
    go get github.com/spf13/cobra@v1.3.0
    go mod edit -replace github.com/spf13/cobra=github.com/spf13/cobra@v1.3.0
    go build -o ~/bin/kubectl -mod=mod ./cmd/kubectl
    popd
  3. Install the kubectl cert-manager plugin:

     curl -SL https://github.com/jetstack/cert-manager/releases/download/v1.6.1/kubectl-cert_manager-linux-amd64.tar.gz | tar xzv kubectl-cert_manager && mv kubectl-cert_manager ~/bin
  4. Enable cert-manager plugin completion by creating the shim kubectl_complete-cert_manager:

    # The following command assumes that ~/bin is in your PATH.
    cat <<'EOF' >~/bin/kubectl_complete-cert_manager && chmod u+x ~/bin/kubectl_complete-cert_manager
    #!/usr/bin/env sh
    # https://github.com/kubernetes/kubernetes/pull/105867
    kubectl cert-manager __complete "$@"
    EOF

Kubectl, Cobra v1.2.1 vs. v1.3.0 and the flag completion bug

Currently, kubectl using PR 105867 does not support flag completion. When completing flags for a plugin such as cert-manager, you can see that nothing appears when completing:

$ kubectl cert-manager status certificate -n<TAB><TAB>
# Nothing happens.

A fix for this bug was already merged in Cobra in PR 1161 released in cobra v1.3.0, and kubectl's go.mod still refers to cobra v1.2.1. In order to have the fix working, you need to update kubectl's go.mod to point cobra to v1.3.0.

Then, you should see:

$ kubectl cert-manager status certificate -n<TAB><TAB>
--as                            -- Username to impersonate for the operation
--as-group                      -- Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--cache-dir                     -- Default cache directory
--certificate-authority         -- Path to a cert file for the certificate authority
--client-certificate            -- Path to a client certificate file for TLS
...

/kind feature
/area ctl

@jetstack-bot jetstack-bot added kind/feature Categorizes issue or PR as related to a new feature. area/ctl Indicates a PR or issue relates to the cert-manager-ctl CLI component labels Dec 12, 2021
@maelvls maelvls changed the title Progress of the support of completion of the "kubectl cert-manager" plugin, due on Kubernetes 1.24 Progress of the support of shell completion for the "kubectl cert-manager" plugin, due on Kubernetes 1.24 Dec 12, 2021
@maelvls maelvls changed the title Progress of the support of shell completion for the "kubectl cert-manager" plugin, due on Kubernetes 1.24 Progress of the support of shell completion for the "kubectl cert-manager" plugin, coming in Kubernetes 1.24 Dec 12, 2021
@maelvls
Copy link
Member Author

maelvls commented Jan 21, 2022

Updates:

etenzy added a commit to etenzy/.dotfiles that referenced this issue Mar 17, 2022
@jetstack-bot
Copy link
Collaborator

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
Send feedback to jetstack.
/lifecycle stale

@jetstack-bot jetstack-bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 21, 2022
@jetstack-bot
Copy link
Collaborator

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close.
Send feedback to jetstack.
/lifecycle rotten
/remove-lifecycle stale

@jetstack-bot jetstack-bot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 21, 2022
@jetstack-bot
Copy link
Collaborator

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.
Send feedback to jetstack.
/close

@jetstack-bot
Copy link
Collaborator

@jetstack-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.
Send feedback to jetstack.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@marckhouzam
Copy link

It took longer but the support for completion for plugins has been merged and will be part of kubectl 1.26.
kubernetes/kubernetes#105867

@maelvls
Copy link
Member Author

maelvls commented Jan 18, 2023

Kubernetes 1.26 was released a few days ago, which means you can now use the kubectl cert-manager completion out-of-the-box! There is still a manual action required to enable the auto-completion though:

# The following command assumes that ~/bin is in your PATH.
cat <<'EOF' >~/bin/kubectl_complete-cert_manager && chmod u+x ~/bin/kubectl_complete-cert_manager
#!/usr/bin/env sh
# https://github.com/kubernetes/kubernetes/pull/105867
kubectl cert-manager __complete "$@"
EOF

My hope is that we will embed this kubectl_complete-cert_manager file to our Krew (kubernetes-sigs/krew#812) installation. Regarding Homebrew, the name of the formula is cmctl and the completion script is already shipped under this name.

Update: the above command is now officially documented in https://cert-manager.io/docs/reference/cmctl/#auto-completion-with-the-kubectl-plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ctl Indicates a PR or issue relates to the cert-manager-ctl CLI component kind/feature Categorizes issue or PR as related to a new feature. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

3 participants