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

Cherry pick handle #120279 GOTOOLCHAIN in kube::golang::verify_go_version onto 1.26 #122077

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions build/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ function kube::build::run_build_command_ex() {
--env "KUBE_CGO_OVERRIDES=' ${KUBE_CGO_OVERRIDES[*]:-} '"
--env "FORCE_HOST_GO=${FORCE_HOST_GO:-}"
--env "GO_VERSION=${GO_VERSION:-}"
--env "GOTOOLCHAIN=${GOTOOLCHAIN:-}"
--env "GOFLAGS=${GOFLAGS:-}"
--env "GOGCFLAGS=${GOGCFLAGS:-}"
--env "SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-}"
Expand Down
16 changes: 13 additions & 3 deletions hack/lib/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,23 @@ kube::golang::create_gopath_tree() {
kube::golang::verify_go_version() {
# default GO_VERSION to content of .go-version
GO_VERSION="${GO_VERSION:-"$(cat "${KUBE_ROOT}/.go-version")"}"
# only setup go if we haven't set FORCE_HOST_GO, or `go version` doesn't match GO_VERSION
if ! ([ -n "${FORCE_HOST_GO:-}" ] || \
(command -v go >/dev/null && [ "$(go version | cut -d' ' -f3)" = "go${GO_VERSION}" ])); then
if [ "${GOTOOLCHAIN:-auto}" != 'auto' ]; then
# no-op, just respect GOTOOLCHAIN
:
elif [ -n "${FORCE_HOST_GO:-}" ]; then
# ensure existing host version is used, like before GOTOOLCHAIN existed
export GOTOOLCHAIN='local'
else
# otherwise, we want to ensure the go version matches GO_VERSION
GOTOOLCHAIN="go${GO_VERSION}"
export GOTOOLCHAIN
# if go is either not installed or too old to respect GOTOOLCHAIN then use gimme
if ! (command -v go >/dev/null && [ "$(go version | cut -d' ' -f3)" = "${GOTOOLCHAIN}" ]); then
export GIMME_ENV_PREFIX=${GIMME_ENV_PREFIX:-"${KUBE_OUTPUT}/.gimme/envs"}
export GIMME_VERSION_PREFIX=${GIMME_VERSION_PREFIX:-"${KUBE_OUTPUT}/.gimme/versions"}
# eval because the output of this is shell to set PATH etc.
eval "$("${KUBE_ROOT}/third_party/gimme/gimme" "${GO_VERSION}")"
fi
fi

if [[ -z "$(command -v go)" ]]; then
Expand Down