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

Merged
merged 3 commits into from
Jun 10, 2024

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 cert-manager-prow bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 30, 2024
@cert-manager-prow cert-manager-prow bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 8, 2024
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
@cert-manager-prow cert-manager-prow bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 8, 2024
@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.

pkg/check/api/api.go Outdated Show resolved Hide resolved
cmd/cmd.go Show resolved Hide resolved
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
@ThatsMrTalbot
Copy link
Contributor

ThatsMrTalbot commented Jun 10, 2024

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

@cert-manager-prow cert-manager-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jun 10, 2024
@inteon
Copy link
Member Author

inteon commented Jun 10, 2024

/approve

@cert-manager-prow
Copy link
Contributor

[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 cert-manager-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 10, 2024
@cert-manager-prow cert-manager-prow bot merged commit 6afbcf4 into cert-manager:main Jun 10, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unifying cmctl and kubectl cert-manager
3 participants