22VERSION ?= 0.18.0
33# Default bundle image tag
44BUNDLE_IMG ?= controller-bundle:$(VERSION )
5+ # Kubernetes version to use for envtest
6+ ENVTEST_K8S_VERSION =1.31.0
7+
58# Options for 'bundle-build'
69ifneq ($(origin CHANNELS ) , undefined)
710BUNDLE_CHANNELS := --channels=$(CHANNELS )
@@ -13,8 +16,6 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
1316
1417# Image URL to use all building/pushing image targets
1518IMG ?= quay.io/opstree/redis-operator:v$(VERSION )
16- # Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
17- CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
1819
1920# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
2021ifeq (,$(shell go env GOBIN) )
@@ -28,11 +29,9 @@ CONTAINER_ENGINE ?= docker
2829all : manager
2930
3031# Run tests
31- ENVTEST_ASSETS_DIR =$(shell pwd) /testbin
3232test : generate fmt vet manifests
33- mkdir -p ${ENVTEST_ASSETS_DIR}
34- 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.7.0/hack/setup-envtest.sh
35- source ${ENVTEST_ASSETS_DIR} /setup-envtest.sh; ENVTEST_K8S_VERSION=1.24.1 fetch_envtest_tools $(ENVTEST_ASSETS_DIR ) ; setup_envtest_env $(ENVTEST_ASSETS_DIR ) ; go test ./... -coverprofile cover.out
33+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test ./... -coverprofile cover.out
34+
3635
3736# Build manager binary
3837manager : generate fmt vet
@@ -61,7 +60,7 @@ undeploy:
6160
6261# Generate manifests e.g. CRD, RBAC etc.
6362manifests : controller-gen
64- $(CONTROLLER_GEN ) $( CRD_OPTIONS ) rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
63+ $(CONTROLLER_GEN ) crd rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
6564
6665# Run go fmt against code
6766fmt :
@@ -86,27 +85,18 @@ docker-build:
8685docker-push :
8786 ${CONTAINER_ENGINE} buildx build --push --platform=" linux/arm64,linux/amd64" -t ${IMG} .
8887
89- # Download controller-gen locally if necessary
90- CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
91- controller-gen :
92- $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)
93-
94- # Download kustomize locally if necessary
95- KUSTOMIZE = $(shell pwd) /bin/kustomize
96- kustomize :
97- $(call go-install-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v4@v4.5.4)
9888
99- # go-install-tool will 'go install' any package $2 and install it to $1.
100- PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
89+ # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
90+ # $1 - target path with name of binary (ideally with version)
91+ # $2 - package url which can be installed
92+ # $3 - specific version of package
10193define go-install-tool
10294@[ -f $(1 ) ] || { \
103- set -e ;\
104- TMP_DIR=$$(mktemp -d ) ;\
105- cd $$TMP_DIR ;\
106- go mod init tmp ;\
107- echo "Downloading $(2 ) " ;\
108- GOBIN=$(PROJECT_DIR ) /bin go install $(2 ) ;\
109- rm -rf $$TMP_DIR ;\
95+ set -e; \
96+ package=$(2 ) @$(3 ) ;\
97+ echo "Downloading $${package}" ;\
98+ GOBIN=$(LOCALBIN ) go install $${package} ;\
99+ mv "$$(echo "$(1 ) " | sed "s/-$(3 ) $$//" ) " $(1 ) ;\
110100}
111101endef
112102
@@ -151,22 +141,76 @@ unit-tests:
151141 @go tool cover -html=coverage.out
152142
153143.PHONY : e2e-test
154- e2e-test : e2e-kind-setup install- kuttl
155- $(shell pwd) /bin /kuttl test --config tests/_config/kuttl-test.yaml
144+ e2e-test : e2e-kind-setup kuttl
145+ $(LOCALBIN ) /kuttl test --config tests/_config/kuttl-test.yaml
156146
157147.PHONY : integration-test-setup
158148integration-test-setup :
159149 ./hack/integrationSetup.sh
160150
161151
162- .PHONY : install-kuttl
163- install-kuttl :
164- curl -L https://github.com/kudobuilder/kuttl/releases/download/v0.15.0/kubectl-kuttl_0.15.0_linux_x86_64 -o $(shell pwd) /bin/kuttl
165- chmod +x $(shell pwd) /bin/kuttl
166-
167152.PHONY : e2e-kind-setup
168153e2e-kind-setup :
169154 ${CONTAINER_ENGINE} build -t redis-operator:e2e -f Dockerfile .
170- kind create cluster --config tests/_config/kind-config.yaml
171- kind load docker-image redis-operator:e2e --name kind
155+ $( KIND ) create cluster --config tests/_config/kind-config.yaml
156+ $( KIND ) load docker-image redis-operator:e2e --name kind
172157 make deploy IMG=redis-operator:e2e
158+
159+
160+ # #@ Dependencies
161+
162+ # # Location to install dependencies to
163+ LOCALBIN ?= $(shell pwd) /bin
164+ $(LOCALBIN ) :
165+ mkdir -p $(LOCALBIN )
166+
167+ # # Tool Binaries
168+ KUBECTL ?= kubectl
169+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize-$(KUSTOMIZE_VERSION )
170+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen-$(CONTROLLER_TOOLS_VERSION )
171+ ENVTEST ?= $(LOCALBIN ) /setup-envtest-$(ENVTEST_VERSION )
172+ GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint-$(GOLANGCI_LINT_VERSION )
173+ KUTTL =$(LOCALBIN ) /kuttl-$(KUTTL_VERSION )
174+ KIND =$(LOCALBIN ) /kind-$(KIND_VERSION )
175+
176+ # # Tool Versions
177+ KUSTOMIZE_VERSION ?= v5.3.0
178+ CONTROLLER_TOOLS_VERSION ?= v0.14.0
179+ ENVTEST_VERSION ?= release-0.17
180+ GOLANGCI_LINT_VERSION ?= v1.57.2
181+ KUTTL_VERSION ?= 0.15.0
182+ KIND_VERSION ?= v0.24.0
183+
184+
185+ .PHONY : kustomize
186+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
187+ $(KUSTOMIZE ) : $(LOCALBIN )
188+ $(call go-install-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION ) )
189+
190+ .PHONY : controller-gen
191+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
192+ $(CONTROLLER_GEN ) : $(LOCALBIN )
193+ $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION ) )
194+
195+ .PHONY : envtest
196+ envtest : $(ENVTEST ) # # Download setup-envtest locally if necessary.
197+ $(ENVTEST ) : $(LOCALBIN )
198+ $(call go-install-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION ) )
199+
200+ .PHONY : golangci-lint
201+ golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
202+ $(GOLANGCI_LINT ) : $(LOCALBIN )
203+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})
204+
205+ .PHONY : kind
206+ kind : $(KIND ) # # Download golangci-lint locally if necessary.
207+ $(KIND ) : $(LOCALBIN )
208+ $(call go-install-tool,$(KIND ) ,sigs.k8s.io/kind,${KIND_VERSION})
209+
210+
211+
212+ .PHONY : kuttl
213+ kuttl : $(KUTTL ) # # Download kuttl locally if necessary.
214+ $(KUTTL ) : $(LOCALBIN )
215+ curl -L https://github.com/kudobuilder/kuttl/releases/download/v$(KUTTL_VERSION ) /kubectl-kuttl_$(KUTTL_VERSION ) _linux_x86_64 -o $(LOCALBIN ) /kuttl
216+ chmod +x $(LOCALBIN ) /kuttl
0 commit comments