Skip to content

Commit f3a34a8

Browse files
Install setup-envtest utility if not exists
Signed-off-by: Vaibhav Jain <vajain@redhat.com>
1 parent 27ac6c9 commit f3a34a8

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ CONTROLLER_GEN_VERSION ?= "v0.11.4"
3535
# https://github.com/kubernetes-sigs/controller-runtime/tree/main/tools/setup-envtest
3636
# install with `go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest`
3737
# find available versions by running `setup-envtest list`
38-
KUBERNETES_VERSION ?= 1.23
38+
KUBERNETES_VERSION ?= 1.26
3939

40+
## Location to install dependencies to
41+
LOCALBIN ?= $(shell pwd)/bin
42+
$(LOCALBIN):
43+
mkdir -p $(LOCALBIN)
44+
45+
ENVTEST ?= $(LOCALBIN)/setup-envtest
4046
CRD_OPTIONS ?= "crd:maxDescLen=0"
4147

4248
# Model Mesh gRPC API Proto Generation
@@ -56,8 +62,8 @@ all: manager
5662

5763
.PHONY: test
5864
## Run unit tests (Requires kubebuilder, etcd, kube-apiserver, envtest)
59-
test:
60-
KUBEBUILDER_ASSETS="$$(setup-envtest use $(KUBERNETES_VERSION) -p path)" \
65+
test: envtest
66+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(KUBERNETES_VERSION) -p path)" \
6167
KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT=120s \
6268
go test -coverprofile cover.out `go list ./... | grep -v fvt`
6369

@@ -212,5 +218,11 @@ check-doc-links:
212218
help:
213219
@perl -0 -nle 'printf("\033[36m %-20s\033[0m %s\n", "$$2", "$$1") while m/^##\s*([^\r\n]+)\n^([\w.-]+):[^=]/gm' $(MAKEFILE_LIST) | sort
214220

221+
.PHONY: envtest
222+
## Download envtest-setup locally if necessary.
223+
envtest: $(ENVTEST)
224+
$(ENVTEST): $(LOCALBIN)
225+
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
226+
215227
# Override targets if they are included in RUN_ARGs so it doesn't run them twice
216228
$(eval $(RUN_ARGS):;@:)

0 commit comments

Comments
 (0)