11#
2- # Copyright (c) 2022 , Oracle and/or its affiliates.
2+ # Copyright (c) 2025 , Oracle and/or its affiliates.
33# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
44#
55
@@ -18,14 +18,14 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
1818
1919# Image URL to use all building/pushing image targets
2020IMG ?= controller:latest
21- # Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
22- # API version has to be v1 to use defaulting (https://github.com/kubernetes-sigs/controller-tools/issues/478)
23- CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
21+ # Enable allowDangerousTypes to use float type in CRD
22+ # Remove the Desc to avoid YAML getting too long. See the discussion:
23+ # https://github.com/kubernetes-sigs/kubebuilder/issues/1140
24+ CRD_OPTIONS ?= "crd:maxDescLen=0,allowDangerousTypes=true"
2425# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
25- ENVTEST_K8S_VERSION = 1.21
26+ ENVTEST_K8S_VERSION = 1.29.0
2627# Operator YAML file
2728OPERATOR_YAML =$$(basename $$(pwd ) ) .yaml
28-
2929# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
3030ifeq (,$(shell go env GOBIN) )
3131GOBIN =$(shell go env GOPATH) /bin
@@ -40,127 +40,145 @@ SHELL = /usr/bin/env bash -o pipefail
4040.SHELLFLAGS = -ec
4141
4242all : build
43-
4443# #@ Development
4544
4645manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
4746 $(CONTROLLER_GEN ) $(CRD_OPTIONS ) rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
48-
47+
4948generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
5049 $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
51-
50+
5251fmt : # # Run go fmt against code.
5352 go fmt ./...
54-
53+
5554vet : # # Run go vet against code.
5655 go vet ./...
57-
56+
5857TEST ?= ./apis/database/v1alpha1 ./commons/... ./controllers/...
5958test : manifests generate fmt vet envtest # # Run unit tests.
6059 KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test $(TEST ) -coverprofile cover.out
61-
60+
6261E2ETEST ?= ./test/e2e/
6362e2e : manifests generate fmt vet envtest # # Run e2e tests.
6463 KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test $(E2ETEST ) -test.timeout 0 -test.v --ginkgo.fail-fast
65-
64+
6665# #@ Build
67-
66+
6867build : generate fmt vet # # Build manager binary.
6968 go build -o bin/manager main.go
70-
69+
7170run : manifests generate fmt vet # # Run a controller from your host.
7271 go run ./main.go
73-
74- GOLANG_VERSION ?= 1.21.7
72+
73+ GOLANG_VERSION ?= 1.23.3
7574# # Download golang in the Dockerfile if BUILD_INTERNAL is set to true.
7675# # Otherwise, use golang image from docker hub as the builder.
7776ifeq ($(BUILD_INTERNAL ) , true)
78- BUILDER_IMG = oraclelinux:8
77+ BUILDER_IMG = oraclelinux:9
7978BUILD_ARGS = --build-arg BUILDER_IMG=$(BUILDER_IMG ) --build-arg GOLANG_VERSION=$(GOLANG_VERSION ) --build-arg INSTALL_GO=true
8079else
8180BUILDER_IMG = golang:$(GOLANG_VERSION )
82- BUILD_ARGS = --build-arg BUILDER_IMG=$(BUILDER_IMG ) --build-arg INSTALL_GO=false
81+ BUILD_ARGS = --build-arg BUILDER_IMG=$(BUILDER_IMG ) --build-arg INSTALL_GO="false" --build-arg GOLANG_VERSION=$(GOLANG_VERSION )
82+ endif
83+ ifeq ($(BUILD_MANIFEST ) , true)
84+ BUILD_ARGS := $(BUILD_ARGS ) --platform=linux/arm64,linux/amd64 --jobs=2 --manifest
85+ PUSH_ARGS := manifest
86+ else
87+ BUILD_ARGS := $(BUILD_ARGS ) --platform=linux/amd64 --tag
8388endif
8489docker-build : # manifests generate fmt vet #test ## Build docker image with the manager. Disable the test but keep the validations to fail fast
8590 docker build --no-cache=true --build-arg http_proxy=$(HTTP_PROXY ) --build-arg https_proxy=$(HTTPS_PROXY ) \
86- --build-arg CI_COMMIT_SHA=$(CI_COMMIT_SHA ) --build-arg CI_COMMIT_BRANCH=$(CI_COMMIT_BRANCH ) \
87- $(BUILD_ARGS ) . -t $(IMG )
88-
91+ --build-arg CI_COMMIT_SHA=$(CI_COMMIT_SHA) --build-arg CI_COMMIT_BRANCH=$(CI_COMMIT_BRANCH) \
92+ $(BUILD_ARGS) $(IMG) .
93+
8994docker-push : # # Push docker image with the manager.
90- docker push $(IMG )
95+ docker $( PUSH_ARGS ) push $(IMG )
9196
92- # #@ Deployment
97+ # Push to minikube's local registry enabled by registry add-on
98+ minikube-push :
99+ docker tag $(IMG ) $$(minikube ip ) :5000/$(IMG )
100+ docker push --tls-verify=false $$(minikube ip ) :5000/$(IMG )
93101
102+ # #@ Deployment
103+
94104install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
95105 $(KUSTOMIZE ) build config/crd | kubectl apply -f -
96-
106+
97107uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
98108 $(KUSTOMIZE ) build config/crd | kubectl delete -f -
99-
109+
100110deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
101111 cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
102112 $(KUSTOMIZE ) build config/default | kubectl apply -f -
103113
114+ minikube-deploy : minikube-operator-yaml minikube-push
115+ kubectl apply -f $(OPERATOR_YAML )
116+
104117# Bug:34265574
105- # Used sed to reposition the controller-manager Deployment after the certificate creation in the OPERATOR_YAML
118+ # Used sed to reposition the controller-manager Deployment after the certificate creation in the OPERATOR_YAML
106119operator-yaml : manifests kustomize
107120 cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
108121 $(KUSTOMIZE ) build config/default > " $( OPERATOR_YAML) "
109122 sed -i.bak -e ' /^apiVersion: apps\/v1/,/---/d' " $( OPERATOR_YAML) "
110123 (echo --- && sed ' /^apiVersion: apps\/v1/,/---/!d' " $( OPERATOR_YAML) .bak" ) >> " $( OPERATOR_YAML) "
111124 rm " $( OPERATOR_YAML) .bak"
112125
126+ minikube-operator-yaml : IMG:=localhost:5000/$(IMG )
127+ minikube-operator-yaml : operator-yaml
128+ sed -i.bak ' s/\(replicas.\) 3/\1 1/g' " $( OPERATOR_YAML) "
129+ rm " $( OPERATOR_YAML) .bak"
130+
113131undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config.
114132 $(KUSTOMIZE ) build config/default | kubectl delete -f -
115-
133+
116134# #@ Build Dependencies
117-
135+
118136# # Location to install dependencies to
119137LOCALBIN ?= $(shell pwd) /bin
120138$(LOCALBIN ) :
121139 mkdir -p $(LOCALBIN )
122-
140+
123141# # Tool Binaries
124142KUSTOMIZE ?= $(LOCALBIN ) /kustomize
125143CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
126144ENVTEST ?= $(LOCALBIN ) /setup-envtest
127-
145+
128146# # Tool Versions
129- KUSTOMIZE_VERSION ?= v3.8.7
130- CONTROLLER_TOOLS_VERSION ?= v0.6.1
131-
147+ KUSTOMIZE_VERSION ?= v5.3.0
148+ CONTROLLER_TOOLS_VERSION ?= v0.16.5
149+
132150KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
133151.PHONY : kustomize
134152kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
135153$(KUSTOMIZE ) : $(LOCALBIN )
136154 curl -s $(KUSTOMIZE_INSTALL_SCRIPT ) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION ) ) $(LOCALBIN )
137-
155+
138156.PHONY : controller-gen
139157controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
140158$(CONTROLLER_GEN ) : $(LOCALBIN )
141159 GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
142-
160+
143161.PHONY : envtest
144162envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
145163$(ENVTEST ) : $(LOCALBIN )
146164 GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
147-
148-
165+
166+
149167.PHONY : bundle
150168bundle : manifests kustomize # # Generate bundle manifests and metadata, then validate generated files.
151169 operator-sdk generate kustomize manifests -q
152170 cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
153171 $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION ) $(BUNDLE_METADATA_OPTS )
154172 operator-sdk bundle validate ./bundle
155-
173+
156174.PHONY : bundle-build
157175bundle-build : # # Build the bundle image.
158176 docker build -f bundle.Dockerfile -t $(BUNDLE_IMG ) .
159-
177+
160178.PHONY : bundle-push
161179bundle-push : # # Push the bundle image.
162180 $(MAKE ) docker-push IMG=$(BUNDLE_IMG )
163-
181+
164182.PHONY : opm
165183OPM = ./bin/opm
166184opm : # # Download opm locally if necessary.
@@ -172,33 +190,32 @@ ifeq (,$(shell which opm 2>/dev/null))
172190 OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
173191 curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
174192 chmod +x $(OPM) ;\
175- }
193+ }
176194else
177195OPM = $(shell which opm)
178196endif
179197endif
180-
198+
181199# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
182200# These images MUST exist in a registry and be pull-able.
183201BUNDLE_IMGS ?= $(BUNDLE_IMG )
184-
202+
185203# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
186204CATALOG_IMG ?= $(IMAGE_TAG_BASE ) -catalog:v$(VERSION )
187-
205+
188206# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
189207ifneq ($(origin CATALOG_BASE_IMG ) , undefined)
190208FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG )
191209endif
192-
210+
193211# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
194212# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
195213# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
196214.PHONY : catalog-build
197215catalog-build : opm # # Build a catalog image.
198216 $(OPM ) index add --container-tool docker --mode semver --tag $(CATALOG_IMG ) --bundles $(BUNDLE_IMGS ) $(FROM_INDEX_OPT )
199-
217+
200218# Push the catalog image.
201219.PHONY : catalog-push
202220catalog-push : # # Push a catalog image.
203221 $(MAKE ) docker-push IMG=$(CATALOG_IMG )
204-
0 commit comments