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

Make the binary dynamically determine whether it is a kubectl plugin #61

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

inteon
Copy link
Member

@inteon inteon commented Apr 30, 2024

fixes #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 (cert-manager/cert-manager#4657): ./kubectl-cert-manager completion kubectl --help

@cert-manager-prow
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from inteon. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
@ThatsMrTalbot
Copy link
Contributor

Looks to work for me, help prints the correct binary and autocomplete works (assuming you have that set up as per cert-manager/cert-manager#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

@maelvls
Copy link
Member

maelvls commented May 15, 2024

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?

@inteon
Copy link
Member Author

inteon commented May 15, 2024

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
Copy link
Member Author

inteon commented May 16, 2024

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

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
Comment on lines +70 to +72
Use: "convert",
Short: "Convert cert-manager config files between different API versions",
Long: templates.LongDesc(`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have to do with "making the binary dynamically determine whether it is a kubectl plugin"?

Inlining these Long paragraphs is a good idea, but it makes it extra hard to review the actual changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I inlined these paragraphs because sometimes we call build.WithTemplate(setupCtx, which takes the setupCtx argument to determine if it is running as cmctl or kubectl cert-manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unifying cmctl and kubectl cert-manager
3 participants