|
50 | 50 | OPERATOR_SDK_VERSION = v1.8.0 |
51 | 51 | OPM_VERSION = v1.19.5 |
52 | 52 |
|
53 | | -CONTROLLER_GEN_VERSION = v0.6.1 |
54 | | -CONTROLLER_GEN=$(GOBIN)/controller-gen-$(CONTROLLER_GEN_VERSION) |
55 | | - |
56 | 53 | # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) |
57 | 54 | CRD_OPTIONS ?= "crd:crdVersions=v1,trivialVersions=true" |
58 | 55 |
|
@@ -98,11 +95,8 @@ update_devworkspace_crds: |
98 | 95 | ###### End rules for dealing with devfile/api |
99 | 96 |
|
100 | 97 | ### test: Runs tests |
101 | | -ENVTEST_ASSETS_DIR = $(shell pwd)/bin/testbin |
102 | | -test: generate fmt vet manifests |
103 | | - mkdir -p $(ENVTEST_ASSETS_DIR) |
104 | | - 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.6.3/hack/setup-envtest.sh |
105 | | - source $(ENVTEST_ASSETS_DIR)/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test $(shell go list ./... | grep -v test/e2e) -coverprofile cover.out |
| 98 | +test: generate fmt vet manifests envtest |
| 99 | + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $(shell go list ./... | grep -v test/e2e) -coverprofile cover.out |
106 | 100 |
|
107 | 101 | ### test_e2e: Runs e2e test on the cluster set in context. DevWorkspace Operator must be already deployed |
108 | 102 | test_e2e: |
@@ -195,24 +189,6 @@ docker-push: |
195 | 189 | endif |
196 | 190 | $(DOCKER) push ${DWO_IMG} |
197 | 191 |
|
198 | | -### controller-gen: Finds or downloads controller-gen |
199 | | -# download controller-gen if necessary |
200 | | -controller-gen: |
201 | | - ifeq (, $(shell which controller-gen-$(CONTROLLER_GEN_VERSION) 2>/dev/null)) |
202 | | - @echo "Installing controller gen as $(GOBIN)/controller-gen-$(CONTROLLER_GEN_VERSION)" |
203 | | - @{ \ |
204 | | - set -e ;\ |
205 | | - CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ |
206 | | - cd $$CONTROLLER_GEN_TMP_DIR ;\ |
207 | | - go mod init tmp ;\ |
208 | | - go get -d -v sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) |
209 | | - go build -o $(GOBIN)/controller-gen-$(CONTROLLER_GEN_VERSION) sigs.k8s.io/controller-tools/cmd/controller-gen |
210 | | - rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ |
211 | | - } |
212 | | - else |
213 | | - @echo "Using installed $(GOBIN)/controller-gen-$(CONTROLLER_GEN_VERSION)" |
214 | | - endif |
215 | | - |
216 | 192 | ### compile-devworkspace-controller: Compiles the devworkspace-controller binary |
217 | 193 | .PHONY: compile-devworkspace-controller |
218 | 194 | compile-devworkspace-controller: |
@@ -249,3 +225,25 @@ help: Makefile |
249 | 225 | @echo ' ROUTING_SUFFIX - Cluster routing suffix (e.g. $$(minikube ip).nip.io, apps-crc.testing)' |
250 | 226 | @echo ' PULL_POLICY - Image pull policy for controller' |
251 | 227 | @echo ' DEVWORKSPACE_API_VERSION - Branch or tag of the github.com/devfile/api to depend on. Defaults to master' |
| 228 | + |
| 229 | +# Automatic setup of required binaries: controller-gen, envtest |
| 230 | +LOCALBIN ?= $(shell pwd)/bin |
| 231 | +$(LOCALBIN): |
| 232 | + mkdir -p $(LOCALBIN) |
| 233 | +## Tool Binaries |
| 234 | +CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen |
| 235 | +CONTROLLER_GEN_VERSION = v0.6.1 |
| 236 | +ENVTEST ?= $(LOCALBIN)/setup-envtest |
| 237 | +ENVTEST_K8S_VERSION = 1.21.2 |
| 238 | + |
| 239 | +### controller-gen: Finds or downloads controller-gen |
| 240 | +# download controller-gen if necessary |
| 241 | +.PHONY: controller-gen |
| 242 | +controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. |
| 243 | +$(CONTROLLER_GEN): $(LOCALBIN) |
| 244 | + test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) |
| 245 | + |
| 246 | +.PHONY: envtest |
| 247 | +envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. |
| 248 | +$(ENVTEST): $(LOCALBIN) |
| 249 | + test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest |
0 commit comments