Skip to content

Commit d6a8c72

Browse files
committed
Simplify verify_go_version to avoid GOTOOLCHAIN/gimme issues
- Add watch-termination and k8s-tests-ext to build targets - Set KUBE_STATIC_BINARIES to empty - Add setup_gomaxprocs function - Update build/pause/Dockerfile.Rhel to use Go 1.25 builder Signed-off-by: Harshal Patil <harpatil@redhat.com>
1 parent 135b1cd commit d6a8c72

2 files changed

Lines changed: 19 additions & 53 deletions

File tree

build/pause/Dockerfile.Rhel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.24-openshift-4.21 AS builder
1+
FROM quay.io/jacobsee/openshift-build:rhel-9-golang-1.25 AS builder
22
WORKDIR /go/src/github.com/openshift/kubernetes/build/pause
33
COPY . .
44
RUN mkdir -p bin && \

hack/lib/golang.sh

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ kube::golang::server_targets() {
7878
staging/src/k8s.io/kube-aggregator
7979
staging/src/k8s.io/apiextensions-apiserver
8080
cluster/gce/gci/mounter
81+
cmd/watch-termination
82+
openshift-hack/cmd/k8s-tests-ext
8183
)
8284
echo "${targets[@]}"
8385
}
@@ -316,20 +318,7 @@ readonly KUBE_ALL_TARGETS=(
316318
)
317319
readonly KUBE_ALL_BINARIES=("${KUBE_ALL_TARGETS[@]##*/}")
318320

319-
readonly KUBE_STATIC_BINARIES=(
320-
apiextensions-apiserver
321-
kube-aggregator
322-
kube-apiserver
323-
kube-controller-manager
324-
kube-scheduler
325-
kube-proxy
326-
kube-log-runner
327-
kubeadm
328-
kubectl
329-
kubectl-convert
330-
kubemark
331-
mounter
332-
)
321+
readonly KUBE_STATIC_BINARIES=()
333322

334323
# Fully-qualified package names that we want to instrument for coverage information.
335324
readonly KUBE_COVERAGE_INSTRUMENTED_PACKAGES=(
@@ -519,44 +508,6 @@ kube::golang::set_platform_envs() {
519508
# env-var GO_VERSION is the desired go version to use, downloading it if needed (defaults to content of .go-version)
520509
# env-var FORCE_HOST_GO set to a non-empty value uses the go version in the $PATH and skips ensuring $GO_VERSION is used
521510
kube::golang::internal::verify_go_version() {
522-
# default GO_VERSION to content of .go-version
523-
GO_VERSION="${GO_VERSION:-"$(cat "${KUBE_ROOT}/.go-version")"}"
524-
if [ "${GOTOOLCHAIN:-auto}" != 'auto' ]; then
525-
# no-op, just respect GOTOOLCHAIN
526-
:
527-
elif [ "${GO_VERSION:-}" == 'devel' ]; then
528-
# get the latest master version of Go, build and use that version
529-
export GOTOOLCHAIN='local'
530-
if [[ ! -f "${KUBE_ROOT}/.gimme/envs/gomaster.env" && ! -f "${HOME}/.gimme/envs/gomaster.env" ]]; then
531-
# gimme tries to write to $HOME directory, in CI environments this may not be writable.
532-
if [ ! -w "${HOME:?Variable HOME is not set}" ]; then
533-
tmp_home="$(mktemp -d)"
534-
export HOME="${tmp_home}"
535-
fi
536-
GOROOT_BOOTSTRAP="${GOROOT_BOOTSTRAP:-/usr/local/go}" "${KUBE_ROOT}/third_party/gimme/gimme" "master" >/dev/null 2>&1
537-
fi
538-
539-
if [[ -f "${KUBE_ROOT}/.gimme/envs/gomaster.env" ]]; then
540-
source "${KUBE_ROOT}/.gimme/envs/gomaster.env"
541-
elif [[ -f "${HOME}/.gimme/envs/gomaster.env" ]]; then
542-
source "${HOME}/.gimme/envs/gomaster.env"
543-
fi
544-
elif [ -n "${FORCE_HOST_GO:-}" ]; then
545-
# ensure existing host version is used, like before GOTOOLCHAIN existed
546-
export GOTOOLCHAIN='local'
547-
else
548-
# otherwise, we want to ensure the go version matches GO_VERSION
549-
GOTOOLCHAIN="go${GO_VERSION}"
550-
export GOTOOLCHAIN
551-
# if go is either not installed or too old to respect GOTOOLCHAIN then use gimme
552-
if ! (command -v go >/dev/null && [ "$(go version | cut -d' ' -f3)" = "${GOTOOLCHAIN}" ]); then
553-
export GIMME_ENV_PREFIX=${GIMME_ENV_PREFIX:-"${KUBE_OUTPUT}/.gimme/envs"}
554-
export GIMME_VERSION_PREFIX=${GIMME_VERSION_PREFIX:-"${KUBE_OUTPUT}/.gimme/versions"}
555-
# eval because the output of this is shell to set PATH etc.
556-
eval "$("${KUBE_ROOT}/third_party/gimme/gimme" "${GO_VERSION}")"
557-
fi
558-
fi
559-
560511
if [[ -z "$(command -v go)" ]]; then
561512
kube::log::usage_from_stdin <<EOF
562513
Can't find 'go' in PATH, please fix and retry.
@@ -638,6 +589,21 @@ kube::golang::hack_tools_gotoolchain() {
638589
echo -n "${hack_tools_gotoolchain}"
639590
}
640591

592+
kube::golang::setup_gomaxprocs() {
593+
# GOMAXPROCS by default does not reflect the number of cpu(s) available
594+
# when running in a container, please see https://github.com/golang/go/issues/33803
595+
if [[ -z "${GOMAXPROCS:-}" ]]; then
596+
if ! command -v ncpu >/dev/null 2>&1; then
597+
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" install -mod=readonly ./ncpu || echo "Will not automatically set GOMAXPROCS"
598+
fi
599+
if command -v ncpu >/dev/null 2>&1; then
600+
GOMAXPROCS=$(ncpu)
601+
export GOMAXPROCS
602+
kube::log::status "Set GOMAXPROCS automatically to ${GOMAXPROCS}"
603+
fi
604+
fi
605+
}
606+
641607
# This will take binaries from $GOPATH/bin and copy them to the appropriate
642608
# place in ${KUBE_OUTPUT_BIN}
643609
#

0 commit comments

Comments
 (0)