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
Copy file name to clipboardexpand all lines: CONTRIBUTING.md
+11
Original file line number
Diff line number
Diff line change
@@ -88,6 +88,17 @@ USE_EXISTING_CLUSTER=true make test
88
88
89
89
Tests can also be run without an existing cluster. For that, install [`kubebuilder`](https://book.kubebuilder.io/quick-start.html#installation). In this case, the tests will bootstrap `etcd` and `kubernetes-api-server` for the tests. Run against an existing cluster whenever possible, though.
90
90
91
+
### Unit tests
92
+
93
+
Some unit tests use [envtest](https://book.kubebuilder.io/reference/envtest.html) which requires Kubernetes binaries (e.g. `api-server`, `etcd` and `kubectl`) to be present on the host filesystem. Makefile takes care of installing all dependent binaries, however running the tests from IDE or via `go test` might not work out-of-the-box. The `envtest` uses env variable `KUBEBUILDER_ASSETS` that points to a directory with these binaries. To make the test work in IDE or `go test` the environment variable has to be correctly set.
94
+
95
+
Example how to run test that use `envtest`:
96
+
97
+
```bash
98
+
make envtest
99
+
KUBEBUILDER_ASSETS=$(./bin/setup-envtest use -p path 1.23) go test ./pkg...
100
+
```
101
+
91
102
### End to end tests
92
103
93
104
To run the end-to-end tests, you'll need [`kind`](https://kind.sigs.k8s.io) and [`kuttl`](https://kuttl.dev). Refer to their documentation for installation instructions.
@git diff -s --exit-code bundle config || (echo "Build failed: the bundle, config files has been changed but the generated bundle, config files aren't up to date. Run 'make bundle' and update your PR."&& git diff &&exit 1)
60
64
@git diff -s --exit-code docs/api.md || (echo "Build failed: the api.md file has been changed but the generated api.md file isn't up to date. Run 'make api-docs' and update your PR."&& git diff &&exit 1)
61
65
66
+
.PHONY: all
62
67
all: manager
68
+
.PHONY: ci
63
69
ci: test
64
70
65
71
# Run tests
66
-
test: generate fmt vet ensure-generate-is-noop
67
-
go test${GOTEST_OPTS} ./...
72
+
# setup-envtest uses KUBEBUILDER_ASSETS which points to a directory with binaries (api-server, etcd and kubectl)
73
+
.PHONY: test
74
+
test: generate fmt vet ensure-generate-is-noop envtest
75
+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(KUBE_VERSION) -p path)" go test${GOTEST_OPTS} ./...
68
76
69
77
# Build manager binary
78
+
.PHONY: manager
70
79
manager: generate fmt vet
71
80
go build -o bin/manager main.go
72
81
73
82
# Run against the configured Kubernetes cluster in ~/.kube/config
83
+
.PHONY: run
74
84
run: generate fmt vet manifests
75
85
ENABLE_WEBHOOKS=$(ENABLE_WEBHOOKS) go run -ldflags ${LD_FLAGS} ./main.go --zap-devel
0 commit comments