Skip to content

Commit

Permalink
Merge pull request kubernetes#130176 from liggitt/go-tools
Browse files Browse the repository at this point in the history
Honor KUBE_HACK_TOOLS_GOTOOLCHAIN
  • Loading branch information
k8s-ci-robot authored Feb 14, 2025
2 parents 9f26291 + 0ce48b5 commit d935836
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 11 deletions.
8 changes: 6 additions & 2 deletions hack/jenkins/benchmark-dockerized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ export KUBE_ROOT
export PATH=${GOPATH}/bin:${PWD}/third_party/etcd:/usr/local/go/bin:${PATH}

# Install tools we need
go -C "${KUBE_ROOT}/hack/tools" install github.com/cespare/prettybench
go -C "${KUBE_ROOT}/hack/tools" install gotest.tools/gotestsum
hack_tools_gotoolchain="${GOTOOLCHAIN:-}"
if [ -n "${KUBE_HACK_TOOLS_GOTOOLCHAIN:-}" ]; then
hack_tools_gotoolchain="${KUBE_HACK_TOOLS_GOTOOLCHAIN}";
fi
GOTOOLCHAIN="${hack_tools_gotoolchain}" go -C "${KUBE_ROOT}/hack/tools" install github.com/cespare/prettybench
GOTOOLCHAIN="${hack_tools_gotoolchain}" go -C "${KUBE_ROOT}/hack/tools" install gotest.tools/gotestsum

# Disable the Go race detector.
export KUBE_RACE=" "
Expand Down
6 changes: 5 additions & 1 deletion hack/jenkins/test-dockerized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ set -o xtrace
export PATH=${GOPATH}/bin:${PWD}/third_party/etcd:/usr/local/go/bin:${PATH}

# Install tools we need
go -C "./hack/tools" install gotest.tools/gotestsum
hack_tools_gotoolchain="${GOTOOLCHAIN:-}"
if [ -n "${KUBE_HACK_TOOLS_GOTOOLCHAIN:-}" ]; then
hack_tools_gotoolchain="${KUBE_HACK_TOOLS_GOTOOLCHAIN}";
fi
GOTOOLCHAIN="${hack_tools_gotoolchain}" go -C "./hack/tools" install gotest.tools/gotestsum

# Disable coverage report
export KUBE_COVER="n"
Expand Down
16 changes: 15 additions & 1 deletion hack/lib/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,26 @@ kube::golang::setup_env() {
kube::golang::internal::verify_go_version
}

# kube::golang::hack_tools_gotoolchain outputs the value to use for $GOTOOLCHAIN,
# using $KUBE_HACK_TOOLS_GOTOOLCHAIN if set, falling back to $GOTOOLCHAIN if set,
# or outputting the empty string.
#
# Use this when installing / building tools specified in the hack/tools module:
# GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go install ...
kube::golang::hack_tools_gotoolchain() {
local hack_tools_gotoolchain="${GOTOOLCHAIN:-}"
if [ -n "${KUBE_HACK_TOOLS_GOTOOLCHAIN:-}" ]; then
hack_tools_gotoolchain="${KUBE_HACK_TOOLS_GOTOOLCHAIN}";
fi
echo -n "${hack_tools_gotoolchain}"
}

kube::golang::setup_gomaxprocs() {
# GOMAXPROCS by default does not reflect the number of cpu(s) available
# when running in a container, please see https://github.com/golang/go/issues/33803
if [[ -z "${GOMAXPROCS:-}" ]]; then
if ! command -v ncpu >/dev/null 2>&1; then
go -C "${KUBE_ROOT}/hack/tools" install ./ncpu || echo "Will not automatically set GOMAXPROCS"
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" install ./ncpu || echo "Will not automatically set GOMAXPROCS"
fi
if command -v ncpu >/dev/null 2>&1; then
GOMAXPROCS=$(ncpu)
Expand Down
2 changes: 1 addition & 1 deletion hack/make-rules/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ junitFilenamePrefix() {
installTools() {
if ! command -v gotestsum >/dev/null 2>&1; then
kube::log::status "gotestsum not found; installing from ./hack/tools"
go -C "${KUBE_ROOT}/hack/tools" install gotest.tools/gotestsum
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" install gotest.tools/gotestsum
fi

if ! command -v prune-junit-xml >/dev/null 2>&1; then
Expand Down
2 changes: 1 addition & 1 deletion hack/update-mocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
kube::golang::setup_env

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

function git_grep() {
git grep --untracked --exclude-standard \
Expand Down
2 changes: 1 addition & 1 deletion hack/update-netparse-cve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ PATH="${GOBIN}:${PATH}"

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

cd "${KUBE_ROOT}"

Expand Down
4 changes: 2 additions & 2 deletions hack/verify-golangci-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ done

# Install golangci-lint
echo "installing golangci-lint and logcheck plugin from hack/tools into ${GOBIN}"
go -C "${KUBE_ROOT}/hack/tools" install github.com/golangci/golangci-lint/cmd/golangci-lint
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" install github.com/golangci/golangci-lint/cmd/golangci-lint
if [ "${golangci_config}" ]; then
# This cannot be used without a config.
# This uses `go build` because `go install -buildmode=plugin` doesn't work
# (on purpose: https://github.com/golang/go/issues/64964).
go -C "${KUBE_ROOT}/hack/tools" build -o "${GOBIN}/logcheck.so" -buildmode=plugin sigs.k8s.io/logtools/logcheck/plugin
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
fi

if [ "${golangci_config}" ]; then
Expand Down
2 changes: 1 addition & 1 deletion hack/verify-publishing-bot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ source "${KUBE_ROOT}/hack/lib/init.sh"

kube::golang::setup_env

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

publishing-verifier "${KUBE_ROOT}"
2 changes: 1 addition & 1 deletion hack/verify-spelling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export GOBIN="${KUBE_OUTPUT_BIN}"
PATH="${GOBIN}:${PATH}"

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

# Spell checking
# All the skipping files are defined in hack/.spelling_failures
Expand Down

0 comments on commit d935836

Please sign in to comment.