5252
5353# Set the Operator SDK version to use. By default, what is installed on the system is used.
5454# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
55- OPERATOR_SDK_VERSION ?= v1.38 .0
55+ OPERATOR_SDK_VERSION ?= v1.40 .0
5656# Image URL to use all building/pushing image targets
5757IMG ?= $(IMAGE_TAG_BASE ) :$(VERSION )
58- # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
59- ENVTEST_K8S_VERSION = 1.30.0
6058
6159# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
6260ifeq (,$(shell go env GOBIN) )
@@ -119,13 +117,37 @@ vet: ## Run go vet against code.
119117 go vet ./...
120118
121119.PHONY : test
122- test : manifests generate fmt vet envtest # # Run tests.
123- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test $$(go list ./... | grep -v /e2e ) -coverprofile cover.out
124-
125- # Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
126- .PHONY : test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
127- test-e2e :
128- go test ./test/e2e/ -v -ginkgo.v
120+ test : manifests generate fmt vet setup-envtest # # Run tests.
121+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test $(shell go list ./... | grep -v /test/) -coverprofile cover.out
122+
123+ # TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
124+ # The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
125+ # CertManager is installed by default; skip with:
126+ # - CERT_MANAGER_INSTALL_SKIP=true
127+ KIND_CLUSTER ?= susql-operator-test-e2e
128+
129+ .PHONY : setup-test-e2e
130+ setup-test-e2e : # # Set up a Kind cluster for e2e tests if it does not exist
131+ @command -v $(KIND ) > /dev/null 2>&1 || { \
132+ echo " Kind is not installed. Please install Kind manually." ; \
133+ exit 1; \
134+ }
135+ @case " $$ ($( KIND) get clusters)" in \
136+ * " $( KIND_CLUSTER) " * ) \
137+ echo " Kind cluster '$( KIND_CLUSTER) ' already exists. Skipping creation." ;; \
138+ * ) \
139+ echo " Creating Kind cluster '$( KIND_CLUSTER) '..." ; \
140+ $(KIND ) create cluster --name $(KIND_CLUSTER ) ;; \
141+ esac
142+
143+ .PHONY : test-e2e
144+ test-e2e : setup-test-e2e manifests generate fmt vet # # Run the e2e tests. Expected an isolated environment using Kind.
145+ KIND_CLUSTER=$(KIND_CLUSTER ) go test ./test/e2e/ -v -ginkgo.v
146+ $(MAKE ) cleanup-test-e2e
147+
148+ .PHONY : cleanup-test-e2e
149+ cleanup-test-e2e : # # Tear down the Kind cluster used for e2e tests
150+ @$(KIND ) delete cluster --name $(KIND_CLUSTER )
129151
130152.PHONY : lint
131153lint : golangci-lint # # Run golangci-lint linter
@@ -135,6 +157,10 @@ lint: golangci-lint ## Run golangci-lint linter
135157lint-fix : golangci-lint # # Run golangci-lint linter and perform fixes
136158 $(GOLANGCI_LINT ) run --fix
137159
160+ .PHONY : lint-config
161+ lint-config : golangci-lint # # Verify golangci-lint linter configuration
162+ $(GOLANGCI_LINT ) config verify
163+
138164# #@ Build
139165
140166.PHONY : build
@@ -195,10 +221,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
195221docker-buildx : # # Build and push docker image for the manager for cross-platform support
196222 # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
197223 sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
198- - $(CONTAINER_TOOL ) buildx create --name project-v3 -builder
199- $(CONTAINER_TOOL ) buildx use project-v3 -builder
224+ - $(CONTAINER_TOOL ) buildx create --name susql-operator -builder
225+ $(CONTAINER_TOOL ) buildx use susql-operator -builder
200226 - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
201- - $(CONTAINER_TOOL ) buildx rm project-v3 -builder
227+ - $(CONTAINER_TOOL ) buildx rm susql-operator -builder
202228 rm Dockerfile.cross
203229
204230.PHONY : build-installer
@@ -239,16 +265,19 @@ $(LOCALBIN):
239265
240266# # Tool Binaries
241267KUBECTL ?= kubectl
268+ KIND ?= kind
242269KUSTOMIZE ?= $(LOCALBIN ) /kustomize
243270CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
244271ENVTEST ?= $(LOCALBIN ) /setup-envtest
245272GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
246273
247274# # Tool Versions
248- KUSTOMIZE_VERSION ?= v5.4.2
249- CONTROLLER_TOOLS_VERSION ?= v0.15.0
250- ENVTEST_VERSION ?= release-0.18
251- GOLANGCI_LINT_VERSION ?= v1.59.1
275+ KUSTOMIZE_VERSION ?= v5.6.0
276+ CONTROLLER_TOOLS_VERSION ?= v0.18.0
277+ ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-% d.% d", $$2, $$3}')
278+ # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
279+ ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.% d", $$3}')
280+ GOLANGCI_LINT_VERSION ?= v2.1.0
252281
253282.PHONY : kustomize
254283kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
@@ -260,6 +289,14 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
260289$(CONTROLLER_GEN ) : $(LOCALBIN )
261290 $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION ) )
262291
292+ .PHONY : setup-envtest
293+ setup-envtest : envtest # # Download the binaries required for ENVTEST in the local bin directory.
294+ @echo " Setting up envtest binaries for Kubernetes version $( ENVTEST_K8S_VERSION) ..."
295+ @$(ENVTEST ) use $(ENVTEST_K8S_VERSION ) --bin-dir $(LOCALBIN ) -p path || { \
296+ echo " Error: Failed to set up envtest binaries for version $( ENVTEST_K8S_VERSION) ." ; \
297+ exit 1; \
298+ }
299+
263300.PHONY : envtest
264301envtest : $(ENVTEST ) # # Download setup-envtest locally if necessary.
265302$(ENVTEST ) : $(LOCALBIN )
@@ -268,10 +305,10 @@ $(ENVTEST): $(LOCALBIN)
268305.PHONY : golangci-lint
269306golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
270307$(GOLANGCI_LINT ) : $(LOCALBIN )
271- $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
308+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/v2/ cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
272309
273310# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
274- # $1 - target path with name of binary (ideally with version)
311+ # $1 - target path with name of binary
275312# $2 - package url which can be installed
276313# $3 - specific version of package
277314define go-install-tool
@@ -322,6 +359,7 @@ bundle-push: ## Push the bundle image.
322359 $(call docker_push,$(BUNDLE_IMG ) )
323360
324361.PHONY : opm
362+ opmVersion = "v1.55.0"
325363OPM = $(LOCALBIN ) /opm
326364opm : # # Download opm locally if necessary.
327365ifeq (,$(wildcard $(OPM ) ) )
@@ -330,7 +368,7 @@ ifeq (,$(shell which opm 2>/dev/null))
330368 set -e ;\
331369 mkdir -p $(dir $(OPM)) ;\
332370 OS=$(GOOS) && ARCH=$(GOARCH) && \
333- curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0 /$${OS}-$${ARCH}-opm ;\
371+ curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/${opmVersion} /$${OS}-$${ARCH}-opm ;\
334372 chmod +x $(OPM) ;\
335373 }
336374else
0 commit comments