Skip to content

Commit d935836

Browse files
authored
Merge pull request kubernetes#130176 from liggitt/go-tools
Honor KUBE_HACK_TOOLS_GOTOOLCHAIN
2 parents 9f26291 + 0ce48b5 commit d935836

File tree

9 files changed

+33
-11
lines changed

9 files changed

+33
-11
lines changed

hack/jenkins/benchmark-dockerized.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ export KUBE_ROOT
4343
export PATH=${GOPATH}/bin:${PWD}/third_party/etcd:/usr/local/go/bin:${PATH}
4444

4545
# Install tools we need
46-
go -C "${KUBE_ROOT}/hack/tools" install github.com/cespare/prettybench
47-
go -C "${KUBE_ROOT}/hack/tools" install gotest.tools/gotestsum
46+
hack_tools_gotoolchain="${GOTOOLCHAIN:-}"
47+
if [ -n "${KUBE_HACK_TOOLS_GOTOOLCHAIN:-}" ]; then
48+
hack_tools_gotoolchain="${KUBE_HACK_TOOLS_GOTOOLCHAIN}";
49+
fi
50+
GOTOOLCHAIN="${hack_tools_gotoolchain}" go -C "${KUBE_ROOT}/hack/tools" install github.com/cespare/prettybench
51+
GOTOOLCHAIN="${hack_tools_gotoolchain}" go -C "${KUBE_ROOT}/hack/tools" install gotest.tools/gotestsum
4852

4953
# Disable the Go race detector.
5054
export KUBE_RACE=" "

hack/jenkins/test-dockerized.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ set -o xtrace
2727
export PATH=${GOPATH}/bin:${PWD}/third_party/etcd:/usr/local/go/bin:${PATH}
2828

2929
# Install tools we need
30-
go -C "./hack/tools" install gotest.tools/gotestsum
30+
hack_tools_gotoolchain="${GOTOOLCHAIN:-}"
31+
if [ -n "${KUBE_HACK_TOOLS_GOTOOLCHAIN:-}" ]; then
32+
hack_tools_gotoolchain="${KUBE_HACK_TOOLS_GOTOOLCHAIN}";
33+
fi
34+
GOTOOLCHAIN="${hack_tools_gotoolchain}" go -C "./hack/tools" install gotest.tools/gotestsum
3135

3236
# Disable coverage report
3337
export KUBE_COVER="n"

hack/lib/golang.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,26 @@ kube::golang::setup_env() {
607607
kube::golang::internal::verify_go_version
608608
}
609609

610+
# kube::golang::hack_tools_gotoolchain outputs the value to use for $GOTOOLCHAIN,
611+
# using $KUBE_HACK_TOOLS_GOTOOLCHAIN if set, falling back to $GOTOOLCHAIN if set,
612+
# or outputting the empty string.
613+
#
614+
# Use this when installing / building tools specified in the hack/tools module:
615+
# GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go install ...
616+
kube::golang::hack_tools_gotoolchain() {
617+
local hack_tools_gotoolchain="${GOTOOLCHAIN:-}"
618+
if [ -n "${KUBE_HACK_TOOLS_GOTOOLCHAIN:-}" ]; then
619+
hack_tools_gotoolchain="${KUBE_HACK_TOOLS_GOTOOLCHAIN}";
620+
fi
621+
echo -n "${hack_tools_gotoolchain}"
622+
}
623+
610624
kube::golang::setup_gomaxprocs() {
611625
# GOMAXPROCS by default does not reflect the number of cpu(s) available
612626
# when running in a container, please see https://github.com/golang/go/issues/33803
613627
if [[ -z "${GOMAXPROCS:-}" ]]; then
614628
if ! command -v ncpu >/dev/null 2>&1; then
615-
go -C "${KUBE_ROOT}/hack/tools" install ./ncpu || echo "Will not automatically set GOMAXPROCS"
629+
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" install ./ncpu || echo "Will not automatically set GOMAXPROCS"
616630
fi
617631
if command -v ncpu >/dev/null 2>&1; then
618632
GOMAXPROCS=$(ncpu)

hack/make-rules/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ junitFilenamePrefix() {
182182
installTools() {
183183
if ! command -v gotestsum >/dev/null 2>&1; then
184184
kube::log::status "gotestsum not found; installing from ./hack/tools"
185-
go -C "${KUBE_ROOT}/hack/tools" install gotest.tools/gotestsum
185+
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" install gotest.tools/gotestsum
186186
fi
187187

188188
if ! command -v prune-junit-xml >/dev/null 2>&1; then

hack/update-mocks.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
2727
kube::golang::setup_env
2828

2929
echo 'installing mockery'
30-
go -C "${KUBE_ROOT}/hack/tools" install github.com/vektra/mockery/v2
30+
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" install github.com/vektra/mockery/v2
3131

3232
function git_grep() {
3333
git grep --untracked --exclude-standard \

hack/update-netparse-cve.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ PATH="${GOBIN}:${PATH}"
3636

3737
# Install golangci-lint
3838
echo 'installing net parser converter'
39-
go -C "${KUBE_ROOT}/hack/tools" install github.com/aojea/sloppy-netparser
39+
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" install github.com/aojea/sloppy-netparser
4040

4141
cd "${KUBE_ROOT}"
4242

hack/verify-golangci-lint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ done
121121

122122
# Install golangci-lint
123123
echo "installing golangci-lint and logcheck plugin from hack/tools into ${GOBIN}"
124-
go -C "${KUBE_ROOT}/hack/tools" install github.com/golangci/golangci-lint/cmd/golangci-lint
124+
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" install github.com/golangci/golangci-lint/cmd/golangci-lint
125125
if [ "${golangci_config}" ]; then
126126
# This cannot be used without a config.
127127
# This uses `go build` because `go install -buildmode=plugin` doesn't work
128128
# (on purpose: https://github.com/golang/go/issues/64964).
129-
go -C "${KUBE_ROOT}/hack/tools" build -o "${GOBIN}/logcheck.so" -buildmode=plugin sigs.k8s.io/logtools/logcheck/plugin
129+
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" build -o "${GOBIN}/logcheck.so" -buildmode=plugin sigs.k8s.io/logtools/logcheck/plugin
130130
fi
131131

132132
if [ "${golangci_config}" ]; then

hack/verify-publishing-bot.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
2727

2828
kube::golang::setup_env
2929

30-
go -C "${KUBE_ROOT}/hack/tools" install ./publishing-verifier
30+
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" install ./publishing-verifier
3131

3232
publishing-verifier "${KUBE_ROOT}"

hack/verify-spelling.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export GOBIN="${KUBE_OUTPUT_BIN}"
3232
PATH="${GOBIN}:${PATH}"
3333

3434
# Install tools we need
35-
go -C "${KUBE_ROOT}/hack/tools" install github.com/client9/misspell/cmd/misspell
35+
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" install github.com/client9/misspell/cmd/misspell
3636

3737
# Spell checking
3838
# All the skipping files are defined in hack/.spelling_failures

0 commit comments

Comments
 (0)