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
Fix version tag management #5463
Fix version tag management #5463
Conversation
Hi @chansuke. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Hi there, @chansuke! 👋 Thanks for your contribution! I see this PR is still a work in progress. Would you like a preliminary review on what you have so far? |
@stormqueen1990 Hi!Thank you for your comment.I've just started working on this issue and will finish soon. I will mention when it's ready. |
f084ef6
to
2768527
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some feedback! Please let me know if anything is unclear 😃
bi, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
return fmt.Errorf("unable to read build information") | ||
} | ||
|
||
var version string | ||
for _, dep := range bi.Deps { | ||
if dep.Path == "sigs.k8s.io/kustomize/kustomize" { | ||
version = dep.Version | ||
break | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change mirrors very closely the code in provenance.go
:
kustomize/api/provenance/provenance.go
Lines 53 to 64 in bfb00ec
info, ok := debug.ReadBuildInfo() | |
if !ok { | |
return p | |
} | |
for _, setting := range info.Settings { | |
// For now, the git commit is the only information of interest. | |
// We could consider adding other info such as the commit date in the future. | |
if setting.Key == "vcs.revision" { | |
p.GitCommit = setting.Value | |
} | |
} |
I think this code should be incorporated in that place, instead of added here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stormqueen1990 Thank you for your review!! I will update the function.
fmt.Fprintln(o.Writer, version) | ||
} else { | ||
fmt.Fprintln(o.Writer, provenance.GetProvenance().Semver()) | ||
fmt.Fprintln(o.Writer, version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: this will cause the output to be the same regardless of whether the --short
flag was passed or not. Is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't intentional. I didn't read the code of provenance.go
/ok-to-test |
2768527
to
d513839
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @chansuke! 👋
Thank you very much for your contribution!
While this change looks good to me in principle, I'm afraid it doesn't address the issue. I tested it locally and kustomize version
still outputs (devel)
for me.
What I believe still needs to happen, in conjunction with this change, is an update to the Makefile, adding the -ldflags
options to save the version in the built binary. Something similar to what currently exists here:
kustomize/releasing/create-release.sh
Lines 57 to 61 in bfb00ec
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o output/$binary_name -ldflags\ | |
"-s -w\ | |
-X sigs.k8s.io/kustomize/api/provenance.version=$version\ | |
-X sigs.k8s.io/kustomize/api/provenance.gitCommit=$(git rev-parse HEAD)\ | |
-X sigs.k8s.io/kustomize/api/provenance.buildDate=$build_date"\ |
One way to get the current working tree as a "development" version would be to use git describe --tags --always --dirty
in the build process, in order to save that information in the version, something along the lines of:
go install -ldflags \
"-X sigs.k8s.io/kustomize/api/provenance.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
-X sigs.k8s.io/kustomize/api/provenance.version=$(shell git describe --tags --always --dirty)" \
.
Does this make sense?
api/provenance/provenance.go
Outdated
@@ -62,6 +62,13 @@ func GetProvenance() Provenance { | |||
p.GitCommit = setting.Value | |||
} | |||
} | |||
|
|||
for _, dep := range info.Deps { | |||
if dep.Path == "sigs.k8s.io/kustomize/kustomize" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: this needs to be
if dep.Path == "sigs.k8s.io/kustomize/kustomize" { | |
if dep.Path == "sigs.k8s.io/kustomize/kustomize/v5" { |
nit (non-blocking): it would be nice to have a constant for the module name with a comment explaining why we are looking for this specific dependency.
d513839
to
0d4e7e4
Compare
@stormqueen1990 Yes, that's make sense and fixed Makefile too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree to what @stormqueen1990 commented. Just added some more thoughts.
api/provenance/provenance.go
Outdated
@@ -62,6 +62,13 @@ func GetProvenance() Provenance { | |||
p.GitCommit = setting.Value | |||
} | |||
} | |||
|
|||
for _, dep := range info.Deps { | |||
if dep.Path == "sigs.k8s.io/kustomize/kustomize/v5" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to also check if dep != nil
, to avoid nil pointer error.
api/provenance/provenance.go
Outdated
|
||
for _, dep := range info.Deps { | ||
if dep.Path == "sigs.k8s.io/kustomize/kustomize/v5" { | ||
p.Version = dep.Version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are returning p.Version
directly, we need to be aware of pseudo-versions too (golang/go#50603). We can sanitize it further to figure out the closest tag as done here (https://github.com/operator-framework/helm-operator-plugins/blob/d00d0092fe5c2a7776a678b7dcee4085cbccfe01/internal/version/version.go#L85). If we are comfortable with printing it as is, then that also seems good. It would be nice to add a comment in case we want to revisit it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@varshaprasad96 Thank you for the comment!! I will add some code to manage pseudo version
This PR has multiple commits, and the default merge method is: merge. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
b0465e3
to
ff4a022
Compare
api/provenance/provenance.go
Outdated
if dep != nil { | ||
continue | ||
} | ||
if dep.Path == "sigs.k8s.io/kustomize/kustomize/v5" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was meant to be:
if dep != nil { | |
continue | |
} | |
if dep.Path == "sigs.k8s.io/kustomize/kustomize/v5" { | |
if dep != nil && dep.Path == "sigs.k8s.io/kustomize/kustomize/v5" { |
since we would like to check what's the Path
of a given dep
if and only if dep
is not nil
.
ff4a022
to
9778337
Compare
Hi there, @chansuke! 👋 This is looking good. I see there's just a couple of lint issues being reported. Could you please address those? You can also run the linter locally by doing I'll keep an eye out for an update to leave my LGTM here. Thanks for your contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution :))
The changes look good to me, apart from a minor nit on adding tests. lgtm from my end, after the linter passes and @stormqueen1990's reviews are addressed.
api/provenance/provenance.go
Outdated
return p | ||
} | ||
|
||
func getMostRecentTag(m debug.Module) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic looks good! Could you add some unit tests to verify this piece of code? (If not in this PR, we can do it as a follow up too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@varshaprasad96 Thank you for your review! I've add unit tests of GetMostRecentTag
9778337
to
d7bca53
Compare
c9c7253
to
cd88610
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/cc @varshaprasad96
for a second review
@stormqueen1990: GitHub didn't allow me to request PR reviews from the following users: a, second, review, for. Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: chansuke, varshaprasad96 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 |
Fixes #5339