@@ -19,6 +19,7 @@ ARCH ?= arm64
1919
2020# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
2121CRD_OPTIONS ?= crd:generateEmbeddedObjectMeta=true,allowDangerousTypes=true
22+ OPERATOR_SDK_VERSION ?= v1.41.1
2223
2324# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
2425ifeq (,$(shell go env GOBIN) )
@@ -72,23 +73,13 @@ PHONY: vet
7273vet : # # Run go vet against code.
7374 go vet ./...
7475
75- ENVTEST_ASSETS_DIR =$(shell pwd) /testbin
76-
77- install-setup-envtest : # # Install the setup-envtest tool if it is not already installed
78- if ! command -v setup-envtest & > /dev/null; then \
79- go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest; \
80- fi
81-
82- setup-envtest : install-setup-envtest # # Download and set up the envtest binary
83- source <( setup-envtest use -p env)
84-
8576test : manifests generate fmt vet setup-envtest # # Run tests.
86- go test ./apis/ ... -coverprofile cover.out
77+ KUBEBUILDER_ASSETS= " $( shell $( ENVTEST ) use $( ENVTEST_K8S_VERSION ) --bin-dir $( LOCALBIN ) -p path ) " go test $$( go list ./ ... | grep -v /e2e ) -coverprofile cover.out
8778
8879# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
8980.PHONY : test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
9081test-e2e :
91- go test ./test /e2e/ -v -ginkgo.v
82+ go test ./tests /e2e/ -v -ginkgo.v
9283
9384.PHONY : lint
9485lint : golangci-lint # # Run golangci-lint linter
@@ -199,9 +190,12 @@ KIND = $(LOCALBIN)/kind
199190
200191# # Tool Versions
201192KUSTOMIZE_VERSION ?= v5.6.0
202- CONTROLLER_TOOLS_VERSION ?= v0.15.0
203- ENVTEST_VERSION ?= release-0.19
204- GOLANGCI_LINT_VERSION ?= v2.0.1
193+ CONTROLLER_TOOLS_VERSION ?= v0.18.0
194+ # ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
195+ ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-% d.% d", $$2, $$3}')
196+ # ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
197+ ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.% d", $$3}')
198+ GOLANGCI_LINT_VERSION ?= v2.1.0
205199GINKGO_VERSION ?= v2.23.4
206200CODE_GENERATOR_VERSION ?= v0.32.3
207201KIND_VERSION ?= v0.17.0
@@ -216,6 +210,14 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
216210$(CONTROLLER_GEN ) : $(LOCALBIN )
217211 $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION ) )
218212
213+ .PHONY : setup-envtest
214+ setup-envtest : envtest # # Download the binaries required for ENVTEST in the local bin directory.
215+ @echo " Setting up envtest binaries for Kubernetes version $( ENVTEST_K8S_VERSION) ..."
216+ @$(ENVTEST ) use $(ENVTEST_K8S_VERSION ) --bin-dir $(LOCALBIN ) -p path || { \
217+ echo " Error: Failed to set up envtest binaries for version $( ENVTEST_K8S_VERSION) ." ; \
218+ exit 1; \
219+ }
220+
219221.PHONY : envtest
220222envtest : $(ENVTEST ) # # Download setup-envtest locally if necessary.
221223$(ENVTEST ) : $(LOCALBIN )
@@ -236,6 +238,26 @@ code-generator: $(CODE_GENERATOR) ## Download code-generator locally if necessar
236238$(CODE_GENERATOR ) : $(LOCALBIN )
237239 $(call go-install-tool,$(CODE_GENERATOR ) ,k8s.io/code-generator,$(CODE_GENERATOR_VERSION ) )
238240
241+ KIND_CLUSTER ?= fluent-operator-test-e2e
242+
243+ .PHONY : setup-test-e2e
244+ setup-test-e2e : # # Set up a Kind cluster for e2e tests if it does not exist
245+ @command -v $(KIND ) > /dev/null 2>&1 || { \
246+ echo " Kind is not installed. Please install Kind manually." ; \
247+ exit 1; \
248+ }
249+ @case " $$ ($( KIND) get clusters)" in \
250+ * " $( KIND_CLUSTER) " * ) \
251+ echo " Kind cluster '$( KIND_CLUSTER) ' already exists. Skipping creation." ;; \
252+ * ) \
253+ echo " Creating Kind cluster '$( KIND_CLUSTER) '..." ; \
254+ $(KIND ) create cluster --name $(KIND_CLUSTER ) ;; \
255+ esac
256+
257+ .PHONY : cleanup-test-e2e
258+ cleanup-test-e2e :
259+ $(KIND ) delete cluster --name $(KIND_CLUSTER )
260+
239261.PHONY : kind
240262kind : $(KIND ) # # Download code-generator locally if necessary.
241263$(KIND ) : $(LOCALBIN )
@@ -297,7 +319,7 @@ ifeq (,$(shell which opm 2>/dev/null))
297319 set -e ;\
298320 mkdir -p $(dir $(OPM)) ;\
299321 OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
300- curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23 .0/$${OS}-$${ARCH}-opm ;\
322+ curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.55 .0/$${OS}-$${ARCH}-opm ;\
301323 chmod +x $(OPM) ;\
302324 }
303325else
0 commit comments