build: also support KUBE_RACE for test binaries

This is relevant for building e2e.test in
pull-kubernetes-e2e-kind-alpha-beta-features-race: if it contains data races,
tests might be flaky.
This commit is contained in:
Patrick Ohly
2025-09-03 11:06:19 +02:00
parent a8905a154b
commit 9b696ff58c

View File

@@ -830,7 +830,7 @@ kube::golang::build_binaries_for_platform() {
for binary in "${binaries[@]}"; do
if [[ "${binary}" =~ ".test"$ ]]; then
tests+=("${binary}")
kube::log::info " ${binary} (test)"
kube::log::info " ${binary} (test${KUBE_RACE:+, race detection})"
elif kube::golang::is_statically_linked "${binary}"; then
statics+=("${binary}")
kube::log::info " ${binary} (static)"
@@ -863,7 +863,7 @@ kube::golang::build_binaries_for_platform() {
-tags="${gotags:-}"
)
if [[ -n "${KUBE_RACE:-}" ]]; then
build_args+=("${KUBE_RACE}")
build_args+=("${KUBE_RACE}")
fi
kube::golang::build_some_binaries "${nonstatics[@]}"
fi
@@ -874,13 +874,18 @@ kube::golang::build_binaries_for_platform() {
testpkg=$(dirname "${test}")
mkdir -p "$(dirname "${outfile}")"
go test -c \
${goflags:+"${goflags[@]}"} \
-gcflags="${gogcflags}" \
-ldflags="${goldflags}" \
-tags="${gotags:-}" \
-o "${outfile}" \
"${testpkg}"
build_args=(
-c
${goflags:+"${goflags[@]}"}
-gcflags="${gogcflags}"
-ldflags="${goldflags}"
-tags="${gotags:-}"
-o "${outfile}"
)
if [[ -n "${KUBE_RACE:-}" ]]; then
build_args+=("${KUBE_RACE}")
fi
go test "${build_args[@]}" "${testpkg}"
done
}