Skip to content

Commit 29545bb

Browse files
committed
prow.sh: take Go version from Kubernetes source
Using the same (recent) Go version for all Kubernetes versions can break for older versions when there are incompatible changes in Go. To avoid that, we use exactly the minimum version of Go required for each Kubernetes version. This is based on the assumption that this combination was tested successfully. When building the E2E suite from Kubernetes (the default) we do the same, but still allow building it from elsewhere. We allow the Go version to be empty when it doesn't matter.
1 parent 429581c commit 29545bb

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

prow.sh

+22-5
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ go_from_travis_yml () {
6060
grep "^ *- go:" "${RELEASE_TOOLS_ROOT}/travis.yml" | sed -e 's/.*go: *//'
6161
}
6262
configvar CSI_PROW_GO_VERSION_BUILD "$(go_from_travis_yml)" "Go version for building the component" # depends on component's source code
63-
configvar CSI_PROW_GO_VERSION_K8S 1.12.1 "Go version for building Kubernetes for the test cluster" # depends on Kubernetes version
64-
configvar CSI_PROW_GO_VERSION_E2E 1.12.1 "Go version for building the Kubernetes E2E test suite" # depends on CSI_PROW_E2E settings below
63+
configvar CSI_PROW_GO_VERSION_E2E "" "override Go version for building the Kubernetes E2E test suite" # normally doesn't need to be set, see install_e2e
6564
configvar CSI_PROW_GO_VERSION_SANITY "${CSI_PROW_GO_VERSION_BUILD}" "Go version for building the csi-sanity test suite" # depends on CSI_PROW_SANITY settings below
6665
configvar CSI_PROW_GO_VERSION_KIND "${CSI_PROW_GO_VERSION_BUILD}" "Go version for building 'kind'" # depends on CSI_PROW_KIND_VERSION below
6766
configvar CSI_PROW_GO_VERSION_GINKGO "${CSI_PROW_GO_VERSION_BUILD}" "Go version for building ginkgo" # depends on CSI_PROW_GINKGO_VERSION below
@@ -292,12 +291,14 @@ mkdir -p "${CSI_PROW_BIN}"
292291
PATH="${CSI_PROW_BIN}:$PATH"
293292

294293
# Ensure that PATH has the desired version of the Go tools, then run command given as argument.
294+
# Empty parameter uses the already installed Go. In Prow, that version is kept up-to-date by
295+
# bumping the container image regularly.
295296
run_with_go () {
296297
local version
297298
version="$1"
298299
shift
299300

300-
if go version 2>/dev/null | grep -q "go$version"; then
301+
if ! [ "$version" ] || go version 2>/dev/null | grep -q "go$version"; then
301302
run "$@"
302303
else
303304
if ! [ -d "${CSI_PROW_WORK}/go-$version" ]; then
@@ -374,6 +375,20 @@ list_gates () (
374375
done
375376
)
376377

378+
go_version_for_kubernetes () (
379+
local path="$1"
380+
local version="$2"
381+
local go_version
382+
383+
# We use the minimal Go version specified for each K8S release (= minimum_go_version in hack/lib/golang.sh).
384+
# More recent versions might also work, but we don't want to count on that.
385+
go_version="$(grep minimum_go_version= "$path/hack/lib/golang.sh" | sed -e 's/.*=go//')"
386+
if ! [ "$go_version" ]; then
387+
die "Unable to determine Go version for Kubernetes $version from hack/lib/golang.sh."
388+
fi
389+
echo "$go_version"
390+
)
391+
377392
csi_prow_kind_have_kubernetes=false
378393
# Brings up a Kubernetes cluster and sets KUBECONFIG.
379394
# Accepts additional feature gates in the form gate1=true|false,gate2=...
@@ -399,7 +414,8 @@ start_cluster () {
399414
# while v1.14.0-fake.1 did.
400415
(cd "$GOPATH/src/k8s.io/kubernetes" && run git tag -f v1.14.0-fake.1) || die "git tag failed"
401416

402-
run_with_go "${CSI_PROW_GO_VERSION_K8S}" kind build node-image --type bazel --image csiprow/node:latest --kube-root "$GOPATH/src/k8s.io/kubernetes" || die "'kind build node-image' failed"
417+
go_version="$(go_version_for_kubernetes "$GOPATH/src/k8s.io/kubernetes" "$version")" || die "cannot proceed without knowing Go version for Kubernetes"
418+
run_with_go "$go_version" kind build node-image --type bazel --image csiprow/node:latest --kube-root "$GOPATH/src/k8s.io/kubernetes" || die "'kind build node-image' failed"
403419
csi_prow_kind_have_kubernetes=true
404420
fi
405421
image="csiprow/node:latest"
@@ -563,7 +579,8 @@ install_e2e () {
563579

564580
git_checkout "${CSI_PROW_E2E_REPO}" "${GOPATH}/src/${CSI_PROW_E2E_IMPORT_PATH}" "${CSI_PROW_E2E_VERSION}" --depth=1 &&
565581
if [ "${CSI_PROW_E2E_IMPORT_PATH}" = "k8s.io/kubernetes" ]; then
566-
run_with_go "${CSI_PROW_GO_VERSION_E2E}" make WHAT=test/e2e/e2e.test "-C${GOPATH}/src/${CSI_PROW_E2E_IMPORT_PATH}" &&
582+
go_version="${CSI_PROW_GO_VERSION_E2E:-$(go_version_for_kubernetes "${GOPATH}/src/${CSI_PROW_E2E_IMPORT_PATH}" "${CSI_PROW_E2E_VERSION}")}" &&
583+
run_with_go "$go_version" make WHAT=test/e2e/e2e.test "-C${GOPATH}/src/${CSI_PROW_E2E_IMPORT_PATH}" &&
567584
ln -s "${GOPATH}/src/${CSI_PROW_E2E_IMPORT_PATH}/_output/bin/e2e.test" "${CSI_PROW_WORK}"
568585
else
569586
run_with_go "${CSI_PROW_GO_VERSION_E2E}" go test -c -o "${CSI_PROW_WORK}/e2e.test" "${CSI_PROW_E2E_IMPORT_PATH}/test/e2e"

0 commit comments

Comments
 (0)