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

🐛 clusterctl: fix goproxy to also return versions for major > 1 #7709

Merged

Conversation

chrischdi
Copy link
Member

@chrischdi chrischdi commented Dec 8, 2022

What this PR does / why we need it:

This PR fixes the goproxy client to also list versions of go modules > v1.
The previously used goproxy endpoint only lists versions of major v1.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #7700

Additional info:

The goproxy client will not provide the correct results for go based provider which do not follow go module semantical versioning (e.g. tagging v2.0.0 but not setting go.mod to /v2. xref. If this is considered as a no-go, I would propose to remove the goproxy implementation instead of fixing it. Such providers are always able to set GOPROXY=off to allow clusterctl to directly use the github api.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 8, 2022
@chrischdi
Copy link
Member Author

That stage should be unrelated

/test pull-cluster-api-e2e-informing-main

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/lgtm

Should we also fix the code in https://github.com/kubernetes-sigs/cluster-api/blob/main/hack/tools/mdbook/releaselink/releaselink.go ?

We should probably dedupe these two and favor less copying around, wdyt?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 8, 2022
@ykakarap
Copy link
Contributor

ykakarap commented Dec 9, 2022

/cc @ykakarap

@ykakarap
Copy link
Contributor

ykakarap commented Dec 9, 2022

/area clusterctl

@k8s-ci-robot k8s-ci-robot added area/clusterctl Issues or PRs related to clusterctl size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 9, 2022
@chrischdi chrischdi force-pushed the pr/clusterctl-fix-goproxy-majors branch 2 times, most recently from 3203984 to 6b6c73b Compare December 9, 2022 11:53
@chrischdi
Copy link
Member Author

/lgtm

Should we also fix the code in https://github.com/kubernetes-sigs/cluster-api/blob/main/hack/tools/mdbook/releaselink/releaselink.go ?

We should probably dedupe these two and favor less copying around, wdyt?

Great point. Did already forget that we've "stolen" that from there :-)
Also adjusted the parameter for aws to show the latest version in the doc.

I moved it to internal/goproxy for now. Happy to get better recommendations 👍
I also added it as separate commit for now to better show the diff to the first commit. Will squash later on.

@chrischdi chrischdi force-pushed the pr/clusterctl-fix-goproxy-majors branch from 6b6c73b to 2e5e0c9 Compare December 9, 2022 12:28
@vincepri
Copy link
Member

vincepri commented Dec 9, 2022

/assign @ykakarap

Copy link
Contributor

@ykakarap ykakarap 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 to support >v1 versions looks good.

There is an edge case where this might now work. Example when a go modules jumps from v1 to v3 then the current code will not list the v3 versions as it will stop immediately after v2 is not found. This is a very rare case and I dont know think why someone might want to jump a major version. But, I thought I would point this out anyway.

FYI: This is a breaking change in clusterctl's library but given our compatibility notice for clusterctl we should be fine and no further action is needed.

internal/goproxy/goproxy_test.go Outdated Show resolved Hide resolved
internal/goproxy/goproxy.go Outdated Show resolved Hide resolved
@@ -58,36 +56,22 @@ func (l ReleaseLink) Process(input *plugin.Input) error {
versionRange := semver.MustParseRange(tags.Get("version"))
includePrereleases := tags.Get("prereleases") == "true"

repo, err := vcs.RepoRootForImportPath(gomodule, false)
scheme, host, err := goproxy.GetSchemeAndHost(os.Getenv("GOPROXY"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Since now we are reading from GOPROXY env variable we should account for scheme and host being empty strings.

If GOPROXY envvar is set to direct or off we will get an empty scheme and host and the code below will fail.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added returning an error when one of scheme or host is empty to fail.

@chrischdi chrischdi force-pushed the pr/clusterctl-fix-goproxy-majors branch from 2e5e0c9 to 8e24add Compare December 12, 2022 11:52
@chrischdi
Copy link
Member Author

Thanks for reviewiewing.

The changes to support >v1 versions looks good.

There is an edge case where this might now work. Example when a go modules jumps from v1 to v3 then the current code will not list the v3 versions as it will stop immediately after v2 is not found. This is a very rare case and I dont know think why someone might want to jump a major version. But, I thought I would point this out anyway.

Yes great point! That's why I mentioned it in the office hours and also added the note at the PR description 👍

@chrischdi chrischdi force-pushed the pr/clusterctl-fix-goproxy-majors branch from 8e24add to 0deb3a6 Compare December 12, 2022 12:08
@chrischdi
Copy link
Member Author

/test pull-cluster-api-e2e-informing-main

@fabriziopandini
Copy link
Member

/lgtm
after this merge we should check if go proxy can provide a method for listing available versions

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 12, 2022
@chrischdi chrischdi force-pushed the pr/clusterctl-fix-goproxy-majors branch from 0deb3a6 to ad4b17d Compare December 12, 2022 12:50
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 12, 2022
@chrischdi
Copy link
Member Author

Squashed both commits to a single one.

Copy link
Contributor

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

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

Looks good - just a couple nits

docs/book/src/clusterctl/commands/init.md Outdated Show resolved Hide resolved
docs/book/src/clusterctl/overview.md Outdated Show resolved Hide resolved
docs/book/src/clusterctl/provider-contract.md Outdated Show resolved Hide resolved
Also:
* moves goproxy functionality to an internal package
* reuses the package also for releaselink
* fixes releaselink references for aws
@chrischdi chrischdi force-pushed the pr/clusterctl-fix-goproxy-majors branch from ad4b17d to 128e6fc Compare December 12, 2022 13:36
@fabriziopandini
Copy link
Member

Thanks @chrischdi for quicky jumping on this issue!
/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 Dec 12, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

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 Dec 12, 2022
@k8s-ci-robot k8s-ci-robot merged commit f799638 into kubernetes-sigs:main Dec 12, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.4 milestone Dec 12, 2022
@chrischdi
Copy link
Member Author

/cherry-pick release-1.3

@k8s-infra-cherrypick-robot

@chrischdi: #7709 failed to apply on top of branch "release-1.3":

Applying: clusterctl: fix goproxy to also return versions for major > 1
Using index info to reconstruct a base tree...
M	cmd/clusterctl/client/repository/goproxy.go
M	docs/book/src/clusterctl/commands/init.md
M	docs/book/src/user/quick-start.md
Falling back to patching base and 3-way merge...
Auto-merging docs/book/src/user/quick-start.md
Auto-merging docs/book/src/clusterctl/commands/init.md
Removing cmd/clusterctl/client/repository/goproxy_test.go
CONFLICT (modify/delete): cmd/clusterctl/client/repository/goproxy.go deleted in clusterctl: fix goproxy to also return versions for major > 1 and modified in HEAD. Version HEAD of cmd/clusterctl/client/repository/goproxy.go left in tree.
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 clusterctl: fix goproxy to also return versions for major > 1
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherry-pick release-1.3

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.

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. area/clusterctl Issues or PRs related to clusterctl 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

goproxyClient doesn't list version >=v2
7 participants