Description
What broke? What's expected?
The e2e tests should not be running by default!
I did a review of a project that uses kubebuilder, and I naiively thought I could just clone the repository and do go test ./...
But then the e2e tests started installing CRDs and stuff into a Kubernetes cluster I just happened to have selected in my ~/.kube/config.
I've tracked it to this part of the template:
Had to spend some hours cleaning up, as the tests installed a bunch of other stuff too, like a Prometheus Operator and cert-manager.
What I suggest kubebuilder does is add a build tag to the top of these files, like so:
//go:build e2e
// +build e2e
And then the Makefile needs to be slightly adjusted:
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
test-e2e:
- go test ./test/e2e/ -v -ginkgo.v
+ go test ./test/e2e/ -v -tags e2e -ginkgo.v
That way, tests don't default to modifying your production infrastructure.
Reproducing this issue
- New project
- go test ./...
KubeBuilder (CLI) Version
Version: main.version{KubeBuilderVersion:"v4.1.1", KubernetesVendor:"unknown", GitCommit:"unknown", BuildDate:"unknown", GoOs:"linux", GoArch:"amd64"}
PROJECT version
3
Plugin versions
- go.kubebuilder.io/v4
Other versions
go version go1.23.0 linux/amd64
from go.mod
k8s.io/api v0.31.0
k8s.io/apimachinery v0.31.0
k8s.io/client-go v0.31.0
sigs.k8s.io/controller-runtime v0.19.0
$ kubectl version --client
Client Version: v1.30.2
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Extra Labels
No response