11
22# Image URL to use all building/pushing image targets
33IMG ?= controller:latest
4- # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5- ENVTEST_K8S_VERSION = 1.31.0
64
75# Docker image name for the mkdocs based local development setup
86IMAGE =ironcore-dev/boot-operator-docs
@@ -72,16 +70,28 @@ check-license: addlicense ## Check that every file has a license header present.
7270 find . -name ' *.go' -exec $(ADDLICENSE ) -check -c ' IronCore authors' {} +
7371
7472.PHONY : test
75- test : manifests generate fmt vet envtest # # Run tests.
73+ test : manifests generate fmt vet setup- envtest # # Run tests.
7674 KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test $$(go list ./... | grep -v /e2e ) -coverprofile cover.out
7775
78- # Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
79- .PHONY : test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
80- test-e2e :
76+ # TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
77+ # The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
78+ # Prometheus and CertManager are installed by default; skip with:
79+ # - PROMETHEUS_INSTALL_SKIP=true
80+ # - CERT_MANAGER_INSTALL_SKIP=true
81+ .PHONY : test-e2e
82+ test-e2e : manifests generate fmt vet # # Run the e2e tests. Expected an isolated environment using Kind.
83+ @command -v kind > /dev/null 2>&1 || { \
84+ echo " Kind is not installed. Please install Kind manually." ; \
85+ exit 1; \
86+ }
87+ @kind get clusters | grep -q ' kind' || { \
88+ echo " No Kind cluster is running. Please start a Kind cluster before running the e2e tests." ; \
89+ exit 1; \
90+ }
8191 go test ./test/e2e/ -v -ginkgo.v
8292
8393.PHONY : lint
84- lint : golangci-lint # # Run golangci-lint linter & yamllint
94+ lint : golangci-lint # # Run golangci-lint linter
8595 $(GOLANGCI_LINT ) run
8696
8797.PHONY : lint-fix
@@ -120,21 +130,17 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
120130docker-buildx : # # Build and push docker image for the manager for cross-platform support
121131 # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
122132 sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
123- - $(CONTAINER_TOOL ) buildx create --name project-v3 -builder
124- $(CONTAINER_TOOL ) buildx use project-v3 -builder
133+ - $(CONTAINER_TOOL ) buildx create --name boot-operator -builder
134+ $(CONTAINER_TOOL ) buildx use boot-operator -builder
125135 - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
126- - $(CONTAINER_TOOL ) buildx rm project-v3 -builder
136+ - $(CONTAINER_TOOL ) buildx rm boot-operator -builder
127137 rm Dockerfile.cross
128138
129139.PHONY : build-installer
130140build-installer : manifests generate kustomize # # Generate a consolidated YAML with CRDs and deployment.
131141 mkdir -p dist
132- @if [ -d " config/crd" ]; then \
133- $(KUSTOMIZE ) build config/crd > dist/install.yaml; \
134- fi
135- echo " ---" >> dist/install.yaml # Add a document separator before appending
136- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
137- $(KUSTOMIZE ) build config/default >> dist/install.yaml
142+ cd config/manager && $(KUSTOMIZE ) edit set image controller=${CONTROLLER_IMG}
143+ $(KUSTOMIZE ) build config/default > dist/install.yaml
138144
139145# #@ Deployment
140146
@@ -155,6 +161,12 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
155161 cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
156162 $(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
157163
164+ # # This e2e-deploy target is specifically used for metrics endpoint validation
165+ .PHONY : e2e-deploy
166+ e2e-deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
167+ cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
168+ $(KUSTOMIZE ) build config/e2e-metrics-validation | $(KUBECTL ) apply -f -
169+
158170.PHONY : undeploy
159171undeploy : kustomize # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
160172 $(KUSTOMIZE ) build config/default | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
@@ -168,18 +180,21 @@ $(LOCALBIN):
168180
169181# # Tool Binaries
170182KUBECTL ?= kubectl
171- KUSTOMIZE ?= $(LOCALBIN ) /kustomize- $( KUSTOMIZE_VERSION )
172- CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen- $( CONTROLLER_TOOLS_VERSION )
173- ENVTEST ?= $(LOCALBIN ) /setup-envtest- $( ENVTEST_VERSION )
174- GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint- $( GOLANGCI_LINT_VERSION )
183+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize
184+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
185+ ENVTEST ?= $(LOCALBIN ) /setup-envtest
186+ GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
175187ADDLICENSE ?= $(LOCALBIN ) /addlicense
176- GOIMPORTS ?= $(LOCALBIN ) /goimports- $( GOIMPORTS_VERSION )
177- GEN_CRD_API_REFERENCE_DOCS ?= $(LOCALBIN ) /gen-crd-api-reference-docs- $( GEN_CRD_API_REFERENCE_DOCS_VERSION )
188+ GOIMPORTS ?= $(LOCALBIN ) /goimports
189+ GEN_CRD_API_REFERENCE_DOCS ?= $(LOCALBIN ) /gen-crd-api-reference-docs
178190
179191# # Tool Versions
180- KUSTOMIZE_VERSION ?= v5.3.0
181- CONTROLLER_TOOLS_VERSION ?= v0.16.0
182- ENVTEST_VERSION ?= latest
192+ KUSTOMIZE_VERSION ?= v5.5.0
193+ CONTROLLER_TOOLS_VERSION ?= v0.17.1
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.% d",$$3, $$2}')
183198GOLANGCI_LINT_VERSION ?= v2.1
184199ADDLICENSE_VERSION ?= v1.1.1
185200GOIMPORTS_VERSION ?= v0.31.0
@@ -195,6 +210,14 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
195210$(CONTROLLER_GEN ) : $(LOCALBIN )
196211 $(call go-install-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION ) )
197212
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+
198221.PHONY : envtest
199222envtest : $(ENVTEST ) # # Download setup-envtest locally if necessary.
200223$(ENVTEST ) : $(LOCALBIN )
@@ -235,15 +258,17 @@ $(GEN_CRD_API_REFERENCE_DOCS): $(LOCALBIN)
235258 $(call go-install-tool,$(GEN_CRD_API_REFERENCE_DOCS ) ,github.com/ahmetb/gen-crd-api-reference-docs,$(GEN_CRD_API_REFERENCE_DOCS_VERSION ) )
236259
237260# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
238- # $1 - target path with name of binary (ideally with version)
261+ # $1 - target path with name of binary
239262# $2 - package url which can be installed
240263# $3 - specific version of package
241264define go-install-tool
242- @[ -f $(1 ) ] || { \
265+ @[ -f " $(1 ) - $( 3 ) " ] || { \
243266set -e; \
244267package=$(2 ) @$(3 ) ;\
245268echo "Downloading $${package}" ;\
269+ rm -f $(1 ) || true ;\
246270GOBIN=$(LOCALBIN ) go install $${package} ;\
247- mv "$$(echo "$(1 ) " | sed "s/-$(3 ) $$//" ) " $(1 ) ;\
248- }
271+ mv $(1 ) $(1 ) -$(3 ) ;\
272+ } ;\
273+ ln -sf $(1 ) -$(3 ) $(1 )
249274endef
0 commit comments