Skip to content

Commit 1ca6875

Browse files
authored
Expliclty set CGO_ENABLED=1 when running go test with race detection. (#1089)
The Go race detector is implemented in C/C++ and requires CGO_ENABLED to work. However, even if CGO_ENABLED isn't explicitly set, Go assumes CGO_ENABLED=1 by default when: - C compiler (like gcc) is available - go env setup allows it (e.g., go env | grep CGO) This failed on a fresh system without a C compiler. So if (e.g.,) gcc installed, `go test -race` just quietly uses CGO under the hood. While this is not needed for local runs, the change makes CGO_ENABLED=1 explicit and portable (e.g., for containers, CI, or cross compile). Signed-off-by: Etai Lev Ran <[email protected]>
1 parent 5c851eb commit 1ca6875

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ vet: ## Run go vet against code.
130130

131131
.PHONY: test
132132
test: manifests generate fmt vet envtest image-build ## Run tests.
133-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e | grep -v /conformance) -race -coverprofile cover.out
133+
CGO_ENABLED=1 KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e | grep -v /conformance) -race -coverprofile cover.out
134134

135135
.PHONY: test-unit
136136
test-unit: ## Run unit tests.
137-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./pkg/... -race -coverprofile cover.out
137+
CGO_ENABLED=1 KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./pkg/... -race -coverprofile cover.out
138138

139139
.PHONY: test-integration
140140
test-integration: ## Run integration tests.
141-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./test/integration/epp/... -race -coverprofile cover.out
141+
CGO_ENABLED=1 KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./test/integration/epp/... -race -coverprofile cover.out
142142

143143
.PHONY: test-e2e
144144
test-e2e: ## Run end-to-end tests against an existing Kubernetes cluster.

0 commit comments

Comments
 (0)