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

Fix version tag management #5463

Merged
merged 1 commit into from Jan 26, 2024

Conversation

chansuke
Copy link
Member

Fixes #5339

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 23, 2023
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 23, 2023
@stormqueen1990
Copy link
Member

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?

@chansuke
Copy link
Member Author

@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.

@chansuke chansuke changed the title WIP: Fix version tag management Fix version tag management Nov 24, 2023
@chansuke chansuke marked this pull request as ready for review November 24, 2023 15:23
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 24, 2023
Copy link
Member

@stormqueen1990 stormqueen1990 left a 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 😃

Comment on lines 66 to 77
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
}
}
Copy link
Member

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:

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.

Copy link
Member Author

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.

Comment on lines 81 to 83
fmt.Fprintln(o.Writer, version)
} else {
fmt.Fprintln(o.Writer, provenance.GetProvenance().Semver())
fmt.Fprintln(o.Writer, version)
Copy link
Member

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?

Copy link
Member Author

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

@stormqueen1990
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 28, 2023
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 28, 2023
Copy link
Member

@stormqueen1990 stormqueen1990 left a 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:

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?

@@ -62,6 +62,13 @@ func GetProvenance() Provenance {
p.GitCommit = setting.Value
}
}

for _, dep := range info.Deps {
if dep.Path == "sigs.k8s.io/kustomize/kustomize" {
Copy link
Member

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

Suggested change
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.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 29, 2023
@chansuke
Copy link
Member Author

@stormqueen1990 Yes, that's make sense and fixed Makefile too.

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.

Agree to what @stormqueen1990 commented. Just added some more thoughts.

@@ -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" {
Copy link
Member

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.


for _, dep := range info.Deps {
if dep.Path == "sigs.k8s.io/kustomize/kustomize/v5" {
p.Version = dep.Version
Copy link
Member

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.

Copy link
Member Author

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

@k8s-ci-robot
Copy link
Contributor

This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

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.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 8, 2023
@chansuke chansuke force-pushed the feat/show-version branch 2 times, most recently from b0465e3 to ff4a022 Compare December 8, 2023 15:15
Comment on lines 69 to 72
if dep != nil {
continue
}
if dep.Path == "sigs.k8s.io/kustomize/kustomize/v5" {
Copy link
Member

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:

Suggested change
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.

@stormqueen1990
Copy link
Member

stormqueen1990 commented Dec 13, 2023

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 make lint from the kustomize folder in this repository after you make the changes to ensure it's passing.

I'll keep an eye out for an update to leave my LGTM here.

Thanks for your contribution!

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.

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.

return p
}

func getMostRecentTag(m debug.Module) string {
Copy link
Member

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).

Copy link
Member Author

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

Copy link
Member

@stormqueen1990 stormqueen1990 left a 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

@k8s-ci-robot
Copy link
Contributor

@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:

/lgtm

/cc @varshaprasad96 for a second review

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.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 7, 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.

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 26, 2024
@k8s-ci-robot k8s-ci-robot merged commit abdcae8 into kubernetes-sigs:master Jan 26, 2024
9 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. 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Development

Successfully merging this pull request may close these issues.

Kustomize version is always devel, but should be v5.x.x
4 participants