22# Image URL to use all building/pushing image targets
33IMG ?= controller:latest
44# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5- ENVTEST_K8S_VERSION = 1.24
5+ ENVTEST_K8S_VERSION = 1.25.0
66
77# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
88ifeq (,$(shell go env GOBIN) )
@@ -12,7 +12,6 @@ GOBIN=$(shell go env GOBIN)
1212endif
1313
1414# Setting SHELL to bash allows bash commands to be executed by recipes.
15- # This is a requirement for 'setup-envtest.sh' in the test target.
1615# Options are set to exit when a recipe line exits non-zero or a piped command fails.
1716SHELL = /usr/bin/env bash -o pipefail
1817.SHELLFLAGS = -ec
@@ -41,7 +40,7 @@ help: ## Display this help.
4140
4241.PHONY : manifests
4342manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
44- $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd
43+ $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
4544
4645.PHONY : generate
4746generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@@ -57,18 +56,21 @@ vet: ## Run go vet against code.
5756
5857.PHONY : test
5958test : manifests generate fmt vet envtest # # Run tests.
60- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test ./... -coverprofile cover.out
59+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN ) - p path) " go test ./... -coverprofile cover.out
6160
6261# #@ Build
6362
6463.PHONY : build
65- build : generate fmt vet # # Build manager binary.
64+ build : manifests generate fmt vet # # Build manager binary.
6665 go build -o bin/manager main.go
6766
6867.PHONY : run
6968run : manifests generate fmt vet # # Run a controller from your host.
7069 go run ./main.go
7170
71+ # If you wish built the manager image targeting other platforms you can use the --platform flag.
72+ # (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
73+ # More info: https://docs.docker.com/develop/develop-images/build_enhancements/
7274.PHONY : docker-build
7375docker-build : test # # Build docker image with the manager.
7476 docker build -t ${IMG} .
@@ -77,6 +79,23 @@ docker-build: test ## Build docker image with the manager.
7779docker-push : # # Push docker image with the manager.
7880 docker push ${IMG}
7981
82+ # PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
83+ # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
84+ # - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
85+ # - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
86+ # - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
87+ # To properly provided solutions that supports more than one platform you should use this option.
88+ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
89+ .PHONY : docker-buildx
90+ docker-buildx : test # # Build and push docker image for the manager for cross-platform support
91+ # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
92+ sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
93+ - docker buildx create --name project-v3-builder
94+ docker buildx use project-v3-builder
95+ - docker buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
96+ - docker buildx rm project-v3-builder
97+ rm Dockerfile.cross
98+
8099# #@ Deployment
81100
82101ifndef ignore-not-found
@@ -114,20 +133,20 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
114133
115134# # Tool Versions
116135KUSTOMIZE_VERSION ?= v3.8.7
117- CONTROLLER_TOOLS_VERSION ?= v0.8 .0
136+ CONTROLLER_TOOLS_VERSION ?= v0.10 .0
118137
119138KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
120139.PHONY : kustomize
121140kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
122141$(KUSTOMIZE ) : $(LOCALBIN )
123- curl -s $(KUSTOMIZE_INSTALL_SCRIPT ) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION ) ) $(LOCALBIN )
142+ test -s $(LOCALBIN ) /kustomize || { curl -Ss $( KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $( subst v,,$( KUSTOMIZE_VERSION) ) $( LOCALBIN) ; }
124143
125144.PHONY : controller-gen
126145controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
127146$(CONTROLLER_GEN ) : $(LOCALBIN )
128- GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
147+ test -s $( LOCALBIN ) /controller-gen || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
129148
130149.PHONY : envtest
131150envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
132151$(ENVTEST ) : $(LOCALBIN )
133- GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
152+ test -s $( LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
0 commit comments