Skip to content

Commit f6c018e

Browse files
committed
Add setup-envtest in Makefile
Use setup-envtest for installing the binaries required for using envtest. The latest envtest binaries for k8s v1.21.2 are not compatible with kubebuilder < v3, which results in envtest suite test tear down failure. envtest fails to stop the kube-apiserver. ``` timeout waiting for process kube-apiserver to stop ``` Pin to k8s v1.19.2 envtest binaries that work with kubebuilder v2. Signed-off-by: Sunny <darkowlzz@protonmail.com>
1 parent 40a4767 commit f6c018e

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Makefile

+21-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ IMG ?= fluxcd/source-controller:latest
33
# Produce CRDs that work back to Kubernetes 1.16
44
CRD_OPTIONS ?= crd:crdVersions=v1
55

6+
ENVTEST_BIN_VERSION?=1.19.2
7+
KUBEBUILDER_ASSETS?=$(shell $(SETUP_ENVTEST) use -i $(ENVTEST_BIN_VERSION) -p path)
8+
69
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
710
ifeq (,$(shell go env GOBIN))
811
GOBIN=$(shell go env GOPATH)/bin
@@ -13,8 +16,8 @@ endif
1316
all: manager
1417

1518
# Run tests
16-
test: generate fmt vet manifests api-docs
17-
go test ./... -coverprofile cover.out
19+
test: generate fmt vet manifests api-docs setup-envtest
20+
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./... -coverprofile cover.out
1821
cd api; go test ./... -coverprofile cover.out
1922

2023
# Build manager binary
@@ -112,3 +115,19 @@ API_REF_GEN=$(GOBIN)/gen-crd-api-reference-docs
112115
else
113116
API_REF_GEN=$(shell which gen-crd-api-reference-docs)
114117
endif
118+
119+
# Find or download setup-envtest
120+
setup-envtest:
121+
ifeq (, $(shell which setup-envtest))
122+
@{ \
123+
set -e ;\
124+
SETUP_ENVTEST_TMP_DIR=$$(mktemp -d) ;\
125+
cd $$SETUP_ENVTEST_TMP_DIR ;\
126+
go mod init tmp ;\
127+
go get sigs.k8s.io/controller-runtime/tools/setup-envtest@latest ;\
128+
rm -rf $$SETUP_ENVTEST_TMP_DIR ;\
129+
}
130+
SETUP_ENVTEST=$(GOBIN)/setup-envtest
131+
else
132+
SETUP_ENVTEST=$(shell which setup-envtest)
133+
endif

0 commit comments

Comments
 (0)