try workaround for Go 1.25.0 with old x/tools build problem

This commit is contained in:
Ryan Richard
2025-08-20 15:19:13 -07:00
parent 8641046b0b
commit f8781b483f

View File

@@ -67,7 +67,15 @@ cp -pr "$(go env GOMODCACHE)/k8s.io/code-generator@v$K8S_PKG_VERSION" "$(go env
# In version 0.23.0 the line inside the shell script that previously said "go install ..." started
# to instead say "GO111MODULE=on go install ..." so this sed is a little wrong, but still seems to work.
echo "Running go install for all k8s.io/code-generator commands ..."
# Using sed to edit the go.mod file (and then running go mod tidy) is a dirty hack to work around
# an issue introduced starting in Go 1.25.0. See https://github.com/golang/go/issues/74462.
# The version of code-generator used by Kube 1.30 depends on x/tools v0.18.0.
# The version of code-generator used by Kube 1.31 depends on x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d.
# Other versions of Kube use code-generator versions which do not have this problem.
(cd "$(go env GOPATH)/src/k8s.io/code-generator" &&
sed -i -E -e 's#golang\.org/x/tools v0\.18\.0#golang\.org/x/tools v0\.24\.1#g' ./go.mod &&
sed -i -E -e 's#golang\.org/x/tools v0\.21\.1-.*#golang\.org/x/tools v0\.24\.1#g' ./go.mod &&
go mod tidy &&
go install -v ./cmd/... &&
sed -i -E -e 's/(go install.*)/# \1/g' ./*.sh)
@@ -78,7 +86,20 @@ if [[ ! -f "$(go env GOPATH)/bin/openapi-gen" ]]; then
kube_openapi_version=$(go list -m k8s.io/kube-openapi | cut -f2 -d' ')
# Install that version of its openapi-gen command.
echo "Running go install for openapi-gen $kube_openapi_version ..."
go install -v "k8s.io/kube-openapi/cmd/openapi-gen@$kube_openapi_version"
# Using sed to edit the go.mod file (and then running go mod tidy) is a dirty hack to work around
# an issue introduced starting in Go 1.25.0. See https://github.com/golang/go/issues/74462.
# If this were not needed, then we could just use "go install" directly without
# copying the source code or editing the go.mod file (which is what this script used to do),
# like this: go install -v "k8s.io/kube-openapi/cmd/openapi-gen@$kube_openapi_version"
# The version of kube-openapi used by Kube 1.30 (and maybe 1.31) depends on x/tools v0.18.0.
# The version of kube-openapi used by Kube 1.32 depends on x/tools v0.24.0.
# Other versions of Kube use kube-openapi versions which do not have this problem.
cp -pr "$(go env GOMODCACHE)/k8s.io/kube-openapi@$kube_openapi_version" "$(go env GOPATH)/src/k8s.io/kube-openapi"
(cd "$(go env GOPATH)/src/k8s.io/kube-openapi" &&
sed -i -E -e 's#golang\.org/x/tools v0\.18\.0#golang\.org/x/tools v0\.24\.1#g' ./go.mod &&
sed -i -E -e 's#golang\.org/x/tools v0\.24\.0#golang\.org/x/tools v0\.24\.1#g' ./go.mod &&
go mod tidy &&
go install -v ./cmd/openapi-gen)
fi
echo "Running go install for controller-gen ..."