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

✨ Add version flag for operator-controller manager binary #802

Merged
merged 1 commit into from
May 7, 2024

Conversation

yashoza19
Copy link
Contributor

Description

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@yashoza19 yashoza19 requested a review from a team as a code owner April 29, 2024 19:04
Copy link

netlify bot commented Apr 29, 2024

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit c5d750b
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/663a32ba0898630008f55475
😎 Deploy Preview https://deploy-preview-802--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@yashoza19 yashoza19 changed the title add version flag for operator-controller manager binary ✨ Add version flag for operator-controller manager binary Apr 29, 2024
@acornett21
Copy link
Contributor

I'd personally like to see release info in the version cmd as well ie 1.0.0 and the GHA's to be updated to accommodate. Since it's easier to go from a release -> commit, then from a commit -> release when trying to trouble shoot or find the culprit of a bug. But is this not something the maintainers what, that is also fine.

Copy link
Member

@varshaprasad96 varshaprasad96 left a comment

Choose a reason for hiding this comment

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

@yashoza19 Thanks for the PR!

A couple of linter errors from the CI, and I agree with @acornett21 - having the release tag information mentioned is really helpful for debugging.

@yashoza19
Copy link
Contributor Author

Thanks for the comments @acornett21 and @varshaprasad96.

I have made the necessary changes to also show release tag information with git commit.

cmd/manager/main.go Outdated Show resolved Hide resolved
perdasilva
perdasilva previously approved these changes Apr 30, 2024
Copy link
Contributor

@perdasilva perdasilva left a comment

Choose a reason for hiding this comment

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

lgtm - one small suggestion on the description for the help flag

@acornett21
Copy link
Contributor

acornett21 commented Apr 30, 2024

I have made the necessary changes to also show release tag information with git commit.

@yashoza19 Does the GHA/Makefile need to be updated/enhanced accommodate this? Or do we get that for free somehow?

@yashoza19
Copy link
Contributor Author

@acornett21

Thank you for the email. Kindly, please note your case is in progress. Our team will reach out if any documents are needed from your end, as of today, confirming there are no actions pending from your end.

The MAKEFILE is updated in this PR. We can open another issue to update the GHA's if required.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 2, 2024
@openshift-merge-robot openshift-merge-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels May 2, 2024
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 3, 2024
Copy link

codecov bot commented May 3, 2024

Codecov Report

Attention: Patch coverage is 80.76923% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 71.15%. Comparing base (fadfe36) to head (628c960).
Report is 7 commits behind head on main.

Files Patch % Lines
cmd/manager/main.go 70.00% 2 Missing and 1 partial ⚠️
internal/version/version.go 87.50% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #802      +/-   ##
==========================================
+ Coverage   64.63%   71.15%   +6.51%     
==========================================
  Files          16       17       +1     
  Lines        1315     1300      -15     
==========================================
+ Hits          850      925      +75     
+ Misses        403      303     -100     
- Partials       62       72      +10     
Flag Coverage Δ
e2e 42.84% <80.76%> (+0.94%) ⬆️
unit 63.59% <ø> (+5.87%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

varshaprasad96
varshaprasad96 previously approved these changes May 3, 2024
Copy link
Member

@varshaprasad96 varshaprasad96 left a comment

Choose a reason for hiding this comment

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

The changes look good, just one nit!

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts), zap.StacktraceLevel(zapcore.DPanicLevel)))
setupLog.Info("starting up the provisioner", "Git commit", version.String())
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Its no longer a provisioner (as in rukpak), I'd make it a generic controller

Suggested change
setupLog.Info("starting up the provisioner", "Git commit", version.String())
setupLog.Info("starting up the controller", "Git commit", version.String())

Makefile Outdated
Comment on lines 210 to 213
export GIT_REPO ?= github.com/operator-framework/operator-controller
export VERSION ?= $(shell git describe --tags --always --abbrev=0)
export VERSION_PATH ?= ${GIT_REPO}/internal/version
export GIT_COMMIT ?= $(shell git rev-parse HEAD)
Copy link
Member

@joelanford joelanford May 3, 2024

Choose a reason for hiding this comment

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

Don't use ?=, especially with shell commands. Because they run every time a variable is referenced. See the changes I made here: #813. I don't think these need to be overridable (do they?), so we can use use := instead of ?=.

Also, I see a mix of spaces and tabs. @m1kola had a good point when he reverted the vertical spacing I added in the above PR, so let's avoid that here as well.

Makefile Outdated
@@ -207,10 +207,14 @@ CGO_ENABLED := 0
endif
export CGO_ENABLED

export GIT_REPO ?= github.com/operator-framework/operator-controller
export VERSION ?= $(shell git describe --tags --always --abbrev=0)
Copy link
Member

@joelanford joelanford May 3, 2024

Choose a reason for hiding this comment

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

We already have a VERSION variable above. Delete this one. It is important to use --dirty so that a user knows if the binary was built from a modified git tree. And it is important not to use --abbrev=0 because non-tagged commits would look like they were tagged with that version.

Makefile Outdated
export GO_BUILD_GCFLAGS := all=-trimpath=$(PWD)
export GO_BUILD_FLAGS :=
export GO_BUILD_LDFLAGS := -s -w -X '$(VERSION_PATH).version=$(VERSION)' -X '$(VERSION_PATH).gitCommit=$(GIT_COMMIT)'
Copy link
Member

@joelanford joelanford May 3, 2024

Choose a reason for hiding this comment

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

Nit to avoid long lines (note the extra empty line at the end so that we can put \ at the end of each line consistently).

Suggested change
export GO_BUILD_LDFLAGS := -s -w -X '$(VERSION_PATH).version=$(VERSION)' -X '$(VERSION_PATH).gitCommit=$(GIT_COMMIT)'
export GO_BUILD_LDFLAGS := -s -w \
-X '$(VERSION_PATH).version=$(VERSION)' \
-X '$(VERSION_PATH).gitCommit=$(GIT_COMMIT)' \

Makefile Outdated
export GIT_REPO ?= github.com/operator-framework/operator-controller
export VERSION ?= $(shell git describe --tags --always --abbrev=0)
export VERSION_PATH ?= ${GIT_REPO}/internal/version
export GIT_COMMIT ?= $(shell git rev-parse HEAD)
Copy link
Member

@joelanford joelanford May 3, 2024

Choose a reason for hiding this comment

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

Looks like debug.BuildInfo contains the git commit with key vcs.revision. Could we use that instead of injecting it?

https://pkg.go.dev/runtime/debug#BuildSetting

@yashoza19
Copy link
Contributor Author

@joelanford and @varshaprasad96, Thanks for the review. I have made the suggested changes, PTAL whenever you get a chance. Thanks!

Makefile Outdated
@@ -207,10 +207,13 @@ CGO_ENABLED := 0
endif
export CGO_ENABLED

export GIT_REPO := github.com/operator-framework/operator-controller
Copy link
Member

Choose a reason for hiding this comment

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

Oh one more think I noticed: This technically needs to be to go module name in order to be used within the $(VERSION_PATH) variable. So in that case, can we be explicit (and more copy/paste friendly) with this:

Suggested change
export GIT_REPO := github.com/operator-framework/operator-controller
export GIT_REPO := $(shell go list -m)

@yashoza19 yashoza19 force-pushed the issue328 branch 3 times, most recently from 628c960 to b3d43cc Compare May 7, 2024 13:39
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts), zap.StacktraceLevel(zapcore.DPanicLevel)))
setupLog.Info("starting up the controller", "Git commit", version.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This isn't just the git commit so that might be a bit misleading in the logs. Maybe something like:

Suggested change
setupLog.Info("starting up the controller", "Git commit", version.String())
setupLog.Info("starting up the controller", "version info", version.String())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. fixed it.

everettraven
everettraven previously approved these changes May 7, 2024
Copy link
Contributor

@everettraven everettraven left a comment

Choose a reason for hiding this comment

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

One minor nit. Otherwise looks good to me, thanks @yashoza19 !

everettraven
everettraven previously approved these changes May 7, 2024
Signed-off-by: yashoza19 <yoza@redhat.com>
@joelanford joelanford added this pull request to the merge queue May 7, 2024
Merged via the queue into operator-framework:main with commit 6d73b73 May 7, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No commit/version command on operator-controller manager binary
7 participants