|
24 | 24 | GOBIN=$(shell go env GOBIN) |
25 | 25 | endif |
26 | 26 |
|
| 27 | +# KUBEBUILDER_ASSETS path is set as environment variable when running envtest. |
| 28 | +ENVTEST_BIN_VERSION = 1.21.4 |
| 29 | +KUBEBUILDER_ASSETS = $(shell $(SETUP_ENVTEST) use -i -p path $(ENVTEST_BIN_VERSION)) |
| 30 | + |
27 | 31 | # Setting SHELL to bash allows bash commands to be executed by recipes. |
28 | 32 | # This is a requirement for 'setup-envtest.sh' in the test target. |
29 | 33 | # Options are set to exit when a recipe line exits non-zero or a piped command fails. |
@@ -65,11 +69,9 @@ fmt: ## Run go fmt against code. |
65 | 69 | vet: ## Run go vet against code. |
66 | 70 | go vet ./... |
67 | 71 |
|
68 | | -ENVTEST_ASSETS_DIR=$(shell pwd)/testbin |
69 | | -test: manifests generate fmt vet ## Run tests. |
70 | | - mkdir -p ${ENVTEST_ASSETS_DIR} |
71 | | - test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh |
72 | | - source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out |
| 72 | +test: manifests generate fmt vet setup-envtest ## Run tests. |
| 73 | + KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \ |
| 74 | + go test ./... -coverprofile cover.out |
73 | 75 |
|
74 | 76 | update-kind-nodes: |
75 | 77 | ifndef LATEST_KIND_NODE |
@@ -120,7 +122,11 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in |
120 | 122 | undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. |
121 | 123 | $(KUSTOMIZE) build config/default | kubectl delete -f - |
122 | 124 |
|
123 | | - |
| 125 | +SETUP_ENVTEST = $(shell pwd)/bin/setup-envtest |
| 126 | +setup-envtest: |
| 127 | + $(call go-get-tool,$(SETUP_ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) |
| 128 | + $(SETUP_ENVTEST) use $(ENVTEST_BIN_VERSION) |
| 129 | + |
124 | 130 | CONTROLLER_GEN = $(shell pwd)/bin/controller-gen |
125 | 131 | controller-gen: ## Download controller-gen locally if necessary. |
126 | 132 | $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.0) |
|
0 commit comments