You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
Copy file name to clipboardExpand all lines: Makefile
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -130,15 +130,15 @@ vet: ## Run go vet against code.
130
130
131
131
.PHONY: test
132
132
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
134
134
135
135
.PHONY: test-unit
136
136
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
138
138
139
139
.PHONY: test-integration
140
140
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
142
142
143
143
.PHONY: test-e2e
144
144
test-e2e: ## Run end-to-end tests against an existing Kubernetes cluster.
0 commit comments