kubernetes/hack/lib
Patrick Ohly 23362e001c build: support -race in binaries
Since a few releases, Go supports `go build -race` and then produces
binaries which do data race detection when invoked. Some changes are needed to
enable using this in a kind cluster:

- `-race` must be passed when building dynamically linked binaries.
  Only those support -race because CGO is required.
  To avoid adding yet another env variables, the existing KUBE_RACE
  gets used to convey the intent.
- KUBE_RACE must be passed into the dockerized build.
- Logging the base image of a release image makes it easier
  to figure out whether the binary has a chance to run.

The base image is important because dynamically linked binaries need a base
image with libc. By default, control plane components are linked statically,
so users need to explicitly override the defaults:

    KUBE_RACE=-race KUBE_CGO_OVERRIDES="kube-apiserver kube-controller-manager kube-scheduler" KUBE_GORUNNER_IMAGE=gcr.io/k8s-staging-test-infra/kubekins-e2e:v20250815-171060767f-master kind build node-image ...

KUBE_GORUNNER_IMAGE changes the base image for kube-apiserver,
kube-controller-manager and kube-scheduler. The kubekins image was picked for
this example because a Prow job definition already uses it. Reusing
it in a job avoids the need to maintain another image definition.

Running conformance tests against such a cluster with alpha+beta features
enabled revealed one new data race:

    $ kubectl logs -n kube-system kube-controller-manager-kind-control-plane
    ...
    WARNING: DATA RACE
    Write at 0x00c00019a730 by goroutine 216:
    k8s.io/client-go/tools/leaderelection.(*LeaderElector).setObservedRecord()
         k8s.io/client-go/tools/leaderelection/leaderelection.go:529 +0x179
    k8s.io/client-go/tools/leaderelection.(*LeaderElector).tryCoordinatedRenew()
         k8s.io/client-go/tools/leaderelection/leaderelection.go:367 +0x5ca
    ...
2025-09-02 16:32:09 +02:00
..
.gitattributes Capture git export-subst strings in version.sh for 'git archive' use. 2017-11-09 16:36:27 -08:00
etcd.sh Update etcd to 3.6.4 2025-07-27 21:45:02 -07:00
golang.sh build: support -race in binaries 2025-09-02 16:32:09 +02:00
init.sh DRA API: s/v1beta2/v1/ and generated files 2025-07-24 08:30:24 +02:00
logging.sh Revert "print error message regardless verbosity level" 2024-02-06 16:40:08 +02:00
protoc.sh Remove gogo-protobuf from CRI 2025-07-04 08:55:57 +02:00
test.sh Remove long/golang version information making short the default 2023-07-07 18:46:34 +02:00
util.sh make verify: run checks in all module hack directories 2024-09-26 08:46:04 +02:00
verify-generated.sh cleanup tempdirs on exit in kube::verify::generated 2025-08-26 18:10:33 -07:00
version.sh Remove vendor from ldflags 2024-02-29 00:22:09 -08:00