Skip to content

✨ Add a --version option to controller-gen - #332

Merged
k8s-ci-robot merged 2 commits into
kubernetes-sigs:masterfrom
dlespiau:2019-10-01-version
Oct 7, 2019
Merged

k8s-ci-robot merged 2 commits into
kubernetes-sigs:masterfrom
dlespiau:2019-10-01-version

Conversation

@dlespiau

@dlespiau dlespiau commented Oct 1, 2019

Copy link
Copy Markdown
Contributor

It's useful to know the version of a controller-gen binary lying around. We could write checks in the kubebuilder Makefile to upgrade controller-gen when needed, or at least warn about it.

Fixes: #259

I checked that this indeed worked with main modules when using go get: https://github.com/dlespiau/go-main-module-version.

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Welcome @dlespiau!

It looks like this is your first PR to kubernetes-sigs/controller-tools 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-tools has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 1, 2019
@dlespiau
dlespiau force-pushed the 2019-10-01-version branch from 0dfb910 to 327cb3e Compare October 1, 2019 12:17
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Oct 1, 2019
@dlespiau

dlespiau commented Oct 2, 2019

Copy link
Copy Markdown
Contributor Author

/assign @droot

@droot droot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for submitting the PR (I was about to start work on it :))

Looks good. One minor comment.

Comment thread pkg/version/version.go Outdated
func Print() error {
v, err := version()
if err != nil {
return err

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like nothing will get printed for the end-user. We should probably print Version: Unknown in this case.

@droot

droot commented Oct 2, 2019

Copy link
Copy Markdown
Contributor

@droot

droot commented Oct 2, 2019

Copy link
Copy Markdown
Contributor

I took another look and feel that we can simplify the version function by not returning error. In case of error, we simply return "unknown" version.

It's useful to know the version of a controller-gen binary lying around. With
this, we can write checks in the kubebuilder Makefile to upgrade controller-gen
when needed, or at least warn about it.
@dlespiau
dlespiau force-pushed the 2019-10-01-version branch from 327cb3e to 6eef398 Compare October 4, 2019 10:57
@dlespiau dlespiau changed the title Add a --version option to controller-gen ✨ Add a --version option to controller-gen Oct 4, 2019
@dlespiau

dlespiau commented Oct 4, 2019

Copy link
Copy Markdown
Contributor Author

The error was propagated and displayed by the main program explaining why the version coud not be displayed (not compiled with go modules). But I see the point: may as well always display a "Version: .*" string that can be parsed in always the same way.

One detail is that the go runtime with return version (devel) when compiled from a local checkout. I chose to follow that lead and display (unknown) instead of the suggested Unknown so we have a stronger invariant. Also documented all the possible behaviours of Print.

@droot

droot commented Oct 7, 2019

Copy link
Copy Markdown
Contributor

One detail is that the go runtime with return version (devel) when compiled from a local checkout. I chose to follow that lead and display (unknown) instead of the suggested Unknown so we have a stronger invariant. Also documented all the possible behaviours of Print.

Sounds good to me.

@droot droot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 7, 2019
@k8s-ci-robot
k8s-ci-robot merged commit dd0b8e7 into kubernetes-sigs:master Oct 7, 2019
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by: dlespiau

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

The pull request process is described here

Details 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

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a version command or option to controller-gen

3 participants