From d1b5a9953a0b80cc449fbdbcaebe07ff9d948f53 Mon Sep 17 00:00:00 2001 From: Benjamin Elder Date: Wed, 30 Aug 2023 13:42:54 -0700 Subject: [PATCH 1/2] handle GOTOOLCHAIN in kube::golang::verify_go_version for now: - shim FORCE_HOST_GO to GOTOOLCHAIN=local - treat GOTOOLCHAIN set and !=auto like FORCE_HOST_GO - otherwise set GOTOOLCHAIN=go${GO_VERSION} and fallback to gimme if necessary TODO: set toolchain statements in go.mod files and keep them in sync --- hack/lib/golang.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index 983ff368e25..4284eb5bae3 100755 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -466,13 +466,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 From d765e40a98870aa2b5280c701fffaaac61b4dfe7 Mon Sep 17 00:00:00 2001 From: Benjamin Elder Date: Mon, 11 Sep 2023 14:20:19 -0700 Subject: [PATCH 2/2] pass GOTOOLCHAIN to build containers --- build/common.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/build/common.sh b/build/common.sh index 4eb7f541c1d..b011fbf6fb5 100755 --- a/build/common.sh +++ b/build/common.sh @@ -540,6 +540,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:-}"