@@ -6,16 +6,19 @@ CEPH_BUCKET_PROVIDER_IMG ?= ceph-bucket-provider:latest
66# Docker image name for the mkdocs based local development setup
77MKDOCS_IMG =ironcore-dev/ceph-provider-docs
88
9- # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
10- ENVTEST_K8S_VERSION = 1.28.0
11-
129# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1310ifeq (,$(shell go env GOBIN) )
1411GOBIN =$(shell go env GOPATH) /bin
1512else
1613GOBIN =$(shell go env GOBIN)
1714endif
1815
16+ # CONTAINER_TOOL defines the container tool to be used for building images.
17+ # Be aware that the target commands are only tested with Docker which is
18+ # scaffolded by default. However, you might want to replace it to use other
19+ # tools. (i.e. podman)
20+ CONTAINER_TOOL ?= docker
21+
1922# Setting SHELL to bash allows bash commands to be executed by recipes.
2023# Options are set to exit when a recipe line exits non-zero or a piped command fails.
2124SHELL = /usr/bin/env bash -o pipefail
@@ -86,12 +89,12 @@ check: manifests generate check-license lint test
8689
8790.PHONY : start-docs
8891start-docs : # # Start the local mkdocs based development environment.
89- docker build -t ${MKDOCS_IMG} -f docs/Dockerfile .
90- docker run -p 8000:8000 -v ` pwd` /:/docs ${MKDOCS_IMG}
92+ $( CONTAINER_TOOL ) build -t ${MKDOCS_IMG} -f docs/Dockerfile .
93+ $( CONTAINER_TOOL ) run -p 8000:8000 -v ` pwd` /:/docs ${MKDOCS_IMG}
9194
9295.PHONY : clean-docs
9396clean-docs : # # Remove all local mkdocs Docker images (cleanup).
94- docker container prune --force --filter " label=project=ceph-provider_documentation"
97+ $( CONTAINER_TOOL ) container prune --force --filter " label=project=ceph-provider_documentation"
9598
9699# #@ Build
97100
@@ -113,13 +116,13 @@ run-bucket: manifests generate fmt vet ## Run a controller from your host.
113116
114117.PHONY : docker-build
115118docker-build : test # # Build docker image with the manager.
116- docker build --target ceph-volume-provider -t ${CEPH_VOLUME_PROVIDER_IMG} .
117- docker build --target ceph-bucket-provider -t ${CEPH_BUCKET_PROVIDER_IMG} .
119+ $( CONTAINER_TOOL ) build --target ceph-volume-provider -t ${CEPH_VOLUME_PROVIDER_IMG} .
120+ $( CONTAINER_TOOL ) build --target ceph-bucket-provider -t ${CEPH_BUCKET_PROVIDER_IMG} .
118121
119122.PHONY : docker-push
120123docker-push : # # Push docker image with the manager.
121- docker push ${CEPH_VOLUME_PROVIDER_IMG}
122- docker push ${CEPH_BUCKET_PROVIDER_IMG}
124+ $( CONTAINER_TOOL ) push ${CEPH_VOLUME_PROVIDER_IMG}
125+ $( CONTAINER_TOOL ) push ${CEPH_BUCKET_PROVIDER_IMG}
123126
124127# #@ Deployment
125128
@@ -143,33 +146,52 @@ ADDLICENSE ?= $(LOCALBIN)/addlicense
143146GOLANGCI_LINT ?= $(LOCALBIN ) /golangci-lint
144147
145148# # Tool Versions
146- KUSTOMIZE_VERSION ?= v5.1.1
147- CONTROLLER_TOOLS_VERSION ?= v0.17.2
148- ADDLICENSE_VERSION ?= v1.1.1
149- GOLANGCI_LINT_VERSION ?= v2.1
149+ KUSTOMIZE_VERSION ?= v5.7.1
150+ CONTROLLER_TOOLS_VERSION ?= v0.17.3
151+ ADDLICENSE_VERSION ?= v1.2.0
152+ GOLANGCI_LINT_VERSION ?= v2.5
153+ # ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
154+ ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-% d.% d", $$2, $$3}')
155+ # ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
156+ ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.% d.% d",$$3, $$2}')
150157
151- KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
152158.PHONY : kustomize
153159kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
154160$(KUSTOMIZE ) : $(LOCALBIN )
155- test -s $( LOCALBIN ) /kustomize || { curl -s $( KUSTOMIZE_INSTALL_SCRIPT ) | bash -s -- $( subst v, ,$( KUSTOMIZE_VERSION) ) $( LOCALBIN ) ; }
161+ $( call go-install-tool, $( KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v5 ,$(KUSTOMIZE_VERSION ) )
156162
157163.PHONY : controller-gen
158164controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
159165$(CONTROLLER_GEN ) : $(LOCALBIN )
160- test -s $( LOCALBIN ) /controller-gen || GOBIN= $( LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@ $(CONTROLLER_TOOLS_VERSION )
166+ $( call go-install-tool, $( CONTROLLER_GEN ) , sigs.k8s.io/controller-tools/cmd/controller-gen, $(CONTROLLER_TOOLS_VERSION ) )
161167
162168.PHONY : envtest
163169envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
164170$(ENVTEST ) : $(LOCALBIN )
165- test -s $( LOCALBIN ) /setup-envtest || GOBIN= $( LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
171+ $( call go-install-tool, $( ENVTEST ) , sigs.k8s.io/controller-runtime/tools/setup-envtest, $( ENVTEST_VERSION ) )
166172
167173.PHONY : addlicense
168174addlicense : $(ADDLICENSE ) # # Download addlicense locally if necessary.
169175$(ADDLICENSE ) : $(LOCALBIN )
170- test -s $( LOCALBIN ) /addlicense || GOBIN= $( LOCALBIN ) go install github.com/google/addlicense@ $(ADDLICENSE_VERSION )
176+ $( call go-install-tool, $( ADDLICENSE ) , github.com/google/addlicense, $(ADDLICENSE_VERSION ) )
171177
172178.PHONY : golangci-lint
173179golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
174180$(GOLANGCI_LINT ) : $(LOCALBIN )
175- test -s $(LOCALBIN ) /golangci-lint || GOBIN=$(LOCALBIN ) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION )
181+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
182+
183+ # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
184+ # $1 - target path with name of binary
185+ # $2 - package url which can be installed
186+ # $3 - specific version of package
187+ define go-install-tool
188+ @[ -f "$(1 ) -$(3 ) " ] && [ "$$(readlink -- "$(1 ) " 2>/dev/null ) " = "$(1 ) -$(3 ) " ] || { \
189+ set -e; \
190+ package=$(2 ) @$(3 ) ;\
191+ echo "Downloading $${package}" ;\
192+ rm -f $(1 ) ;\
193+ GOBIN=$(LOCALBIN ) go install $${package} ;\
194+ mv $(1 ) $(1 ) -$(3 ) ;\
195+ } ;\
196+ ln -sf $$(realpath $(1 ) -$(3 ) ) $(1 )
197+ endef
0 commit comments