cmctl icon indicating copy to clipboard operation
cmctl copied to clipboard

Make the binary dynamically determine whether it is a kubectl plugin

Open inteon opened this issue 1 year ago • 5 comments

fixes https://github.com/cert-manager/cmctl/issues/38

See https://krew.sigs.k8s.io/docs/developer-guide/develop/best-practices/

TODO: I would like to get some feedback on the kubectl cert-manager autocomplete functionality. UPDATE: autocomplete works as expected, additional improvements can be made in a separate PR

This PR adds a new completion command based on @maelvls' instructions to make kubectl completion work (https://github.com/cert-manager/cert-manager/issues/4657): ./kubectl-cert-manager completion kubectl --help

inteon avatar Apr 30 '24 14:04 inteon

Looks to work for me, help prints the correct binary and autocomplete works (assuming you have that set up as per https://github.com/cert-manager/cert-manager/issues/4657)

image

One thing we could do though, is if we detect the binary name, could we detect kubectl_complete-cert_manager also and remove the need for the script? This could be a follow up improvement, dont think that it should block this

ThatsMrTalbot avatar May 13 '24 14:05 ThatsMrTalbot

I've tried it, I had to rename the binary after running go install since the go.mod module name ends with cmctl:

go install . && mv $(go env GOPATH)/bin/{cmctl,kubectl-cert_manager}

Installing the "completion" is... weird. It is a shim rather than a completion script. I think I prefer Adam's idea. With Adam's idea, instead of:

kubectl cert-manager completion kubectl >$(go env GOPATH)/bin/kubectl_complete-cert-manager
chmod +x $(go env GOPATH)/bin/kubectl_complete-cert-manager

It would be:

ln -s $(which kubectl-cert_manager) $(dirname $(which kubectl-cert_manager))/kubectl_complete-cert-manager

No script needs to be created, and completion kubectl is no longer necessary 👍 Although it would be good to have a note in the --help with a link that explains how to enable completion.

What do you think?

maelvls avatar May 15 '24 10:05 maelvls

Installing the "completion" is... weird. It is a shim rather than a completion script. I think I prefer Adam's idea. What do you think?

I'll investigate if this is easily doable.

inteon avatar May 15 '24 10:05 inteon

I propose that we improve the completion logic in a separate PR.

inteon avatar May 16 '24 10:05 inteon

Looks good! We will probably need some docs ready for the release telling people how to install /lgtm

ThatsMrTalbot avatar Jun 10 '24 11:06 ThatsMrTalbot

/approve

inteon avatar Jun 10 '24 11:06 inteon

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: inteon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

cert-manager-prow[bot] avatar Jun 10 '24 11:06 cert-manager-prow[bot]