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 verify script for go directive changes #267

Merged

Conversation

MadhavJivrajani
Copy link
Contributor

@MadhavJivrajani MadhavJivrajani commented Mar 12, 2024

Building on kubernetes/utils#306

This commit adds a script that checks the changed version in the go.mod file with a certain maximum version that the go directive can have.

We set the maximum version of the go directive as 1.20 here because the oldest go directive that exists on our supported release branches in k/k is 1.20.

Fixes #264
xref kubernetes/kubernetes#123744

TODO: need to change the command here: https://github.com/kubernetes/test-infra/blob/0100e558a4a3594165262e0864a53d1b22f0973c/config/jobs/kubernetes/gengo/gengo-config.yaml#L29

Done kubernetes/test-infra#32368

/assign @liggitt @dims

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 12, 2024
@k8s-ci-robot k8s-ci-robot requested review from sttts and thockin March 12, 2024 09:50
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 12, 2024
@dims
Copy link
Member

dims commented Mar 12, 2024

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 12, 2024
@MadhavJivrajani
Copy link
Contributor Author

MadhavJivrajani commented Mar 12, 2024

/assign @sttts
for approval

Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

Will you also fix the presubmit job config to call verify ?

hack/verify-go-directive.sh Outdated Show resolved Hide resolved
hack/verify-go-directive.sh Outdated Show resolved Hide resolved
hack/verify-go-directive.sh Outdated Show resolved Hide resolved
exit 1
fi

if ! printf '%s\n' "${current}" "${max}" | sort --check=silent --version-sort; then
Copy link
Member

Choose a reason for hiding this comment

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

Why not test for exact equal? We don't want it to go backwards either, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to understand this a little better, would this serve as a sanity check in general? Because when we bump deps, the go directive is either going to stay the same or its going to increase, I don't think it can go backwards iiuc.

Copy link
Member

Choose a reason for hiding this comment

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

What I meant is that this is obvious:

if [[ "${current}" != "${max}" ]]; then
    echo >&2 "FAIL: current Go directive ${current} must be ${max}"
fi

If I understand this code, you would allow "max" to be 1.20.1 and "current" to be 1.20 - why would we do that? I feel like it's too clever -- don't we ALWAYS want an exact match?

The goal here is that the verify script is not going to be changed "accidentally" (by tooling), so it's an effective (but simple) cross-check.

Copy link
Contributor Author

@MadhavJivrajani MadhavJivrajani Apr 4, 2024

Choose a reason for hiding this comment

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

I understand now, thanks for laying it out @thockin!

Edit: @thockin, the go directive in the go.mod here is 1.13, do we want to bump that because only then will this work

Copy link
Member

Choose a reason for hiding this comment

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

Uggh, after making my point, you clever showed me I was being an idiot. This is not "locking" the version, it really is upper-bounding it. As soon as we add support for type-params, 1.13 will have to bump up, I guess?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, "upper-bounding" is a nice way to put it. Thanks! <3

As soon as we add support for type-params, 1.13 will have to bump up, I guess?

Yeah, that sounds about right!

Makefile Outdated Show resolved Hide resolved
This commit adds a script that checks the changed version in
the go.mod file with a certain maximum version that the go
directive can have.

We set the maximum version of the go directive as 1.20 here
because the oldest go directive that exists on our supported
release branches in k/k is 1.20.

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
@MadhavJivrajani MadhavJivrajani force-pushed the add-go-directive-verify branch from 2d939fd to 7d40e07 Compare April 3, 2024 11:41
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 3, 2024
@sttts
Copy link
Contributor

sttts commented Apr 3, 2024

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 3, 2024
Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

Thanks!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 4, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dims, MadhavJivrajani, sttts, thockin

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 merged commit a0386bf into kubernetes:master Apr 4, 2024
4 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. 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 presubmit check to prevent accidental go directive bump
6 participants