4848
4949# Set the Operator SDK version to use. By default, what is installed on the system is used.
5050# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
51- OPERATOR_SDK_VERSION ?= v1.37.0
52-
51+ OPERATOR_SDK_VERSION ?= v1.42.1
5352# Image URL to use all building/pushing image targets
5453IMG ?= controller:latest
55- # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
56- ENVTEST_K8S_VERSION = 1.30.0
57-
58- # Force Go toolchain version to prevent automatic selection issues
59- # See: https://go.dev/doc/toolchain
60- export GOTOOLCHAIN = go1.22.12
6154
6255# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
6356ifeq (,$(shell go env GOBIN) )
@@ -116,21 +109,50 @@ vet: ## Run go vet against code.
116109 go vet ./...
117110
118111.PHONY : test
119- test : manifests generate fmt vet envtest # # Run tests.
120- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test $(shell go list ./... | grep -v /test/) -coverprofile cover.out
121-
122- .PHONY : test-e2e # You will need to have a Kind cluster up in running to run this target
123- test-e2e :
124- go test ./test/e2e/ -v -ginkgo.v
112+ test : manifests generate fmt vet setup-envtest # # Run tests.
113+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test $$(go list ./... | grep -v /e2e ) -coverprofile cover.out
114+
115+ # TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
116+ # The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
117+ # CertManager is installed by default; skip with:
118+ # - CERT_MANAGER_INSTALL_SKIP=true
119+ KIND_CLUSTER ?= operator-test-e2e
120+
121+ .PHONY : setup-test-e2e
122+ setup-test-e2e : # # Set up a Kind cluster for e2e tests if it does not exist
123+ @command -v $(KIND ) > /dev/null 2>&1 || { \
124+ echo " Kind is not installed. Please install Kind manually." ; \
125+ exit 1; \
126+ }
127+ @case " $$ ($( KIND) get clusters)" in \
128+ * " $( KIND_CLUSTER) " * ) \
129+ echo " Kind cluster '$( KIND_CLUSTER) ' already exists. Skipping creation." ;; \
130+ * ) \
131+ echo " Creating Kind cluster '$( KIND_CLUSTER) '..." ; \
132+ $(KIND ) create cluster --name $(KIND_CLUSTER ) ;; \
133+ esac
134+
135+ .PHONY : test-e2e
136+ test-e2e : setup-test-e2e manifests generate fmt vet # # Run the e2e tests. Expected an isolated environment using Kind.
137+ KIND_CLUSTER=$(KIND_CLUSTER ) go test ./test/e2e/ -v -ginkgo.v
138+ $(MAKE ) cleanup-test-e2e
139+
140+ .PHONY : cleanup-test-e2e
141+ cleanup-test-e2e : # # Tear down the Kind cluster used for e2e tests
142+ @$(KIND ) delete cluster --name $(KIND_CLUSTER )
125143
126144.PHONY : lint
127- lint : golangci-lint # # Run golangci-lint linter & yamllint
145+ lint : golangci-lint # # Run golangci-lint linter
128146 $(GOLANGCI_LINT ) run
129147
130148.PHONY : lint-fix
131149lint-fix : golangci-lint # # Run golangci-lint linter and perform fixes
132150 $(GOLANGCI_LINT ) run --fix
133151
152+ .PHONY : lint-config
153+ lint-config : golangci-lint # # Verify golangci-lint linter configuration
154+ $(GOLANGCI_LINT ) config verify
155+
134156# #@ Build
135157
136158.PHONY : build
@@ -163,10 +185,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
163185docker-buildx : # # Build and push docker image for the manager for cross-platform support
164186 # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
165187 sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
166- - $(CONTAINER_TOOL ) buildx create --name project-v3 -builder
167- $(CONTAINER_TOOL ) buildx use project-v3 -builder
188+ - $(CONTAINER_TOOL ) buildx create --name operator -builder
189+ $(CONTAINER_TOOL ) buildx use operator -builder
168190 - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
169- - $(CONTAINER_TOOL ) buildx rm project-v3 -builder
191+ - $(CONTAINER_TOOL ) buildx rm operator -builder
170192 rm Dockerfile.cross
171193
172194.PHONY : build-installer
@@ -207,16 +229,20 @@ $(LOCALBIN):
207229
208230# # Tool Binaries
209231KUBECTL ?= kubectl
232+ KIND ?= kind
210233KUSTOMIZE ?= $(LOCALBIN ) /kustomize
211234CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
212235ENVTEST ?= $(LOCALBIN ) /setup-envtest
213236GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
214237
215238# # Tool Versions
216- KUSTOMIZE_VERSION ?= v5.4.2
217- CONTROLLER_TOOLS_VERSION ?= v0.15.0
218- ENVTEST_VERSION ?= release-0.19
219- GOLANGCI_LINT_VERSION ?= v1.59.1
239+ KUSTOMIZE_VERSION ?= v5.6.0
240+ CONTROLLER_TOOLS_VERSION ?= v0.18.0
241+ # ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
242+ ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-% d.% d", $$2, $$3}')
243+ # ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
244+ ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.% d", $$3}')
245+ GOLANGCI_LINT_VERSION ?= v2.1.0
220246
221247.PHONY : kustomize
222248kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
@@ -228,18 +254,26 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
228254$(CONTROLLER_GEN ) : $(LOCALBIN )
229255 $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION ) )
230256
257+ .PHONY : setup-envtest
258+ setup-envtest : envtest # # Download the binaries required for ENVTEST in the local bin directory.
259+ @echo " Setting up envtest binaries for Kubernetes version $( ENVTEST_K8S_VERSION) ..."
260+ @$(ENVTEST ) use $(ENVTEST_K8S_VERSION ) --bin-dir $(LOCALBIN ) -p path || { \
261+ echo " Error: Failed to set up envtest binaries for version $( ENVTEST_K8S_VERSION) ." ; \
262+ exit 1; \
263+ }
264+
231265.PHONY : envtest
232266envtest : $(ENVTEST ) # # Download setup-envtest locally if necessary.
233267$(ENVTEST ) : $(LOCALBIN )
234268 $(call go-install-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION ) )
235-
269+
236270.PHONY : golangci-lint
237271golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
238272$(GOLANGCI_LINT ) : $(LOCALBIN )
239- $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
240-
273+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/v2 /cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
274+
241275# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
242- # $1 - target path with name of binary (ideally with version)
276+ # $1 - target path with name of binary
243277# $2 - package url which can be installed
244278# $3 - specific version of package
245279define go-install-tool
@@ -273,14 +307,14 @@ endif
273307
274308.PHONY : bundle
275309bundle : manifests kustomize operator-sdk # # Generate bundle manifests and metadata, then validate generated files.
276- $(OPERATOR_SDK ) generate kustomize manifests --interactive=false - q
310+ $(OPERATOR_SDK ) generate kustomize manifests -q
277311 cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
278312 $(KUSTOMIZE ) build config/manifests | $(OPERATOR_SDK ) generate bundle $(BUNDLE_GEN_FLAGS )
279313 $(OPERATOR_SDK ) bundle validate ./bundle
280314
281315.PHONY : bundle-build
282316bundle-build : # # Build the bundle image.
283- docker build -f bundle.Dockerfile -t $(BUNDLE_IMG ) .
317+ $( CONTAINER_TOOL ) build -f bundle.Dockerfile -t $(BUNDLE_IMG ) .
284318
285319.PHONY : bundle-push
286320bundle-push : # # Push the bundle image.
@@ -295,7 +329,7 @@ ifeq (,$(shell which opm 2>/dev/null))
295329 set -e ;\
296330 mkdir -p $(dir $(OPM)) ;\
297331 OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
298- curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23 .0/$${OS}-$${ARCH}-opm ;\
332+ curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.55 .0/$${OS}-$${ARCH}-opm ;\
299333 chmod +x $(OPM) ;\
300334 }
301335else
@@ -320,14 +354,18 @@ endif
320354# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
321355.PHONY : catalog-build
322356catalog-build : opm # # Build a catalog image.
323- $(OPM ) index add --container-tool docker --mode semver --tag $(CATALOG_IMG ) --bundles $(BUNDLE_IMGS ) $(FROM_INDEX_OPT )
357+ $(OPM ) index add --container-tool $( CONTAINER_TOOL ) --mode semver --tag $(CATALOG_IMG ) --bundles $(BUNDLE_IMGS ) $(FROM_INDEX_OPT )
324358
325359# Push the catalog image.
326360.PHONY : catalog-push
327361catalog-push : # # Push a catalog image.
328362 $(MAKE ) docker-push IMG=$(CATALOG_IMG )
329363
364+ # Force Go toolchain version
365+ export GOTOOLCHAIN = go1.24.13
366+
330367.PHONY : metalk8s
331368metalk8s : manifests kustomize # # Generate MetalK8s resulting manifests
369+ mkdir -p deploy
332370 $(KUSTOMIZE ) build config/metalk8s | \
333371 sed ' s/BUILD_IMAGE_CLUSTER_OPERATOR:latest/{{ build_image_name("metalk8s-operator") }}/' > deploy/manifests.yaml
0 commit comments