kubernetes-sigs / controller-runtime

Repo for the controller-runtime subproject of kubebuilder (sig-apimachinery)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest` fails with ` go.mod:3: invalid go version '1.22.0': must match format 1.23`

kgoutham93 opened this issue · comments

Installing latest version of setup-envtest fails with the following error log.

go: downloading sigs.k8s.io/controller-runtime v0.17.2
go: downloading sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20240322105421-affb96708000
go: sigs.k8s.io/controller-runtime/tools/setup-envtest@latest (in sigs.k8s.io/controller-runtime/tools/setup-envtest@v0.0.0-20240322105421-affb96708000): go.mod:3: invalid go version '1.22.0': must match format 1.23

Go version

$ go version
go version go1.20.7 linux/amd64

Could be related to golang/go#61888 ?

I guess it might be related to: 4c2442e#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R3 (there are some discussions in the original PR thread): #2693 (comment)

Previously: 1.21, now 1.22.0.

I tried to open a quick fix for it, but unfortunately I don't have time to do to it properly and thus I closed it. 😓

I tried to open a quick fix for it, but unfortunately I don't have time to do to it properly and thus I closed it. 😓

@fspaniol So I assume just dropping the patch version wasn't enough? Did you find a problem with that?

I tried to open a quick fix for it, but unfortunately I don't have time to do to it properly and thus I closed it. 😓

@fspaniol So I assume just dropping the patch version wasn't enough? Did you find a problem with that?

I'm sorry, I should have been more specific. I didn't exactly try it out because I'm on a rush to finish some things here, what I meant was that since the PR actions failed due to the best practice checks, I closed it. The fix may be valid still, but I honestly haven't tried it out.

For now, in my repositories I just used the latest release tag.

I tried to open a quick fix for it, but unfortunately I don't have time to do to it properly and thus I closed it. 😓

@fspaniol So I assume just dropping the patch version wasn't enough? Did you find a problem with that?

Hey @sbueringer , I managed to find the time to go a bit deeper on this and opened a new PR with some insights: #2722

If setup-envtest had git tags, that might provide a workaround. Currently, if you try to go get sigs.k8s.io/controller-runtime/tools/setup-envtest you get an auto-generated version number, because it's not taking the parent directory's version.

Alternatively, using go workspaces might allow the parent tag to work for child modules.

I ran into a similar problem trying to use setup-envtest@latest, which now requires Go 1.22. Not having tags makes it hard to pin to an old version. I ended up using go get sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.16 to puin to an old version.

Thx for taking a closer look!

I think it's important that we have a go.mod file which won't be updated after running go mod tidy (or other go commands).

As far as I can tell there is no way to do this with go 1.22it will always be updated to go 1.22.0 if commands like go mod tidy are run with Go 1.22.

Also based on the delta here: https://go-review.googlesource.com/c/go/+/560855/8/src/cmd/vendor/golang.org/x/mod/modfile/rule.go I think they basically changed the format of the go version: invalid go version '%s': must match format 1.23.0.

So I think we have no other choice than using go 1.22.0. Folks that use older go versions will have to pin to older CR versions. But I think this also sort of makes sense and was always the case. If CR declares a go version as the "mimimum Go version" than that's the minimum required version :).

I think adding tags for tools/setup-envtestmakes it easier to pin to a specific CR version, but it won't change the fact that the minimum required version is 1.22.

Just a side note: controller-runtime is expected to fail with Go versions < 1.22. That's basically what the go directive in go.mod is saying. The minimum Go version is 1.22.0. So if you're trying to build controller-runtime with a Go toolchain < 1.22, you should expect failures.

Yes, but the problem is that the instructions here say to use latest when executing envtest. So if you don't have Go 1.22+ installed, that go install command suddenly started failing when controller-runtime was updated. And because there's no git tag for this submodule, there's no easy way to pin to an old version using the same semver as the parent module. So you're stuck trying to find the exact commit you need to pin to that matches the old version of config-runtime you're using.

On top of that, recent config-management changes have several reverse incompatible interface changes, making upgrade non-trivial. So everyone using envtest is now forced to do work to fix their environment.

I think if you were happy before with using latest, it should be fine to pin to a release branch, e.g. go get sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.16 (+ we should update our docs)

I wonder if we didn't have the same problem before as we specify a min go version in the tools/setup-envtest/go.mod file (before 1.22 it was 1.20).