1
1
#
2
- # Copyright (c) 2022 , Oracle and/or its affiliates.
2
+ # Copyright (c) 2025 , Oracle and/or its affiliates.
3
3
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
4
4
#
5
5
@@ -18,14 +18,14 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
18
18
19
19
# Image URL to use all building/pushing image targets
20
20
IMG ?= 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"
24
25
# 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
26
27
# Operator YAML file
27
28
OPERATOR_YAML =$$(basename $$(pwd ) ) .yaml
28
-
29
29
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
30
30
ifeq (,$(shell go env GOBIN) )
31
31
GOBIN =$(shell go env GOPATH) /bin
@@ -40,127 +40,145 @@ SHELL = /usr/bin/env bash -o pipefail
40
40
.SHELLFLAGS = -ec
41
41
42
42
all : build
43
-
44
43
# #@ Development
45
44
46
45
manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
47
46
$(CONTROLLER_GEN ) $(CRD_OPTIONS ) rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
48
-
47
+
49
48
generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
50
49
$(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
51
-
50
+
52
51
fmt : # # Run go fmt against code.
53
52
go fmt ./...
54
-
53
+
55
54
vet : # # Run go vet against code.
56
55
go vet ./...
57
-
56
+
58
57
TEST ?= ./apis/database/v1alpha1 ./commons/... ./controllers/...
59
58
test : manifests generate fmt vet envtest # # Run unit tests.
60
59
KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test $(TEST ) -coverprofile cover.out
61
-
60
+
62
61
E2ETEST ?= ./test/e2e/
63
62
e2e : manifests generate fmt vet envtest # # Run e2e tests.
64
63
KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test $(E2ETEST ) -test.timeout 0 -test.v --ginkgo.fail-fast
65
-
64
+
66
65
# #@ Build
67
-
66
+
68
67
build : generate fmt vet # # Build manager binary.
69
68
go build -o bin/manager main.go
70
-
69
+
71
70
run : manifests generate fmt vet # # Run a controller from your host.
72
71
go run ./main.go
73
-
74
- GOLANG_VERSION ?= 1.21.7
72
+
73
+ GOLANG_VERSION ?= 1.23.3
75
74
# # Download golang in the Dockerfile if BUILD_INTERNAL is set to true.
76
75
# # Otherwise, use golang image from docker hub as the builder.
77
76
ifeq ($(BUILD_INTERNAL ) , true)
78
- BUILDER_IMG = oraclelinux:8
77
+ BUILDER_IMG = oraclelinux:9
79
78
BUILD_ARGS = --build-arg BUILDER_IMG=$(BUILDER_IMG ) --build-arg GOLANG_VERSION=$(GOLANG_VERSION ) --build-arg INSTALL_GO=true
80
79
else
81
80
BUILDER_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
83
88
endif
84
89
docker-build : # manifests generate fmt vet #test ## Build docker image with the manager. Disable the test but keep the validations to fail fast
85
90
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
+
89
94
docker-push : # # Push docker image with the manager.
90
- docker push $(IMG )
95
+ docker $( PUSH_ARGS ) push $(IMG )
91
96
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 )
93
101
102
+ # #@ Deployment
103
+
94
104
install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
95
105
$(KUSTOMIZE ) build config/crd | kubectl apply -f -
96
-
106
+
97
107
uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
98
108
$(KUSTOMIZE ) build config/crd | kubectl delete -f -
99
-
109
+
100
110
deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
101
111
cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
102
112
$(KUSTOMIZE ) build config/default | kubectl apply -f -
103
113
114
+ minikube-deploy : minikube-operator-yaml minikube-push
115
+ kubectl apply -f $(OPERATOR_YAML )
116
+
104
117
# 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
106
119
operator-yaml : manifests kustomize
107
120
cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
108
121
$(KUSTOMIZE ) build config/default > " $( OPERATOR_YAML) "
109
122
sed -i.bak -e ' /^apiVersion: apps\/v1/,/---/d' " $( OPERATOR_YAML) "
110
123
(echo --- && sed ' /^apiVersion: apps\/v1/,/---/!d' " $( OPERATOR_YAML) .bak" ) >> " $( OPERATOR_YAML) "
111
124
rm " $( OPERATOR_YAML) .bak"
112
125
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
+
113
131
undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config.
114
132
$(KUSTOMIZE ) build config/default | kubectl delete -f -
115
-
133
+
116
134
# #@ Build Dependencies
117
-
135
+
118
136
# # Location to install dependencies to
119
137
LOCALBIN ?= $(shell pwd) /bin
120
138
$(LOCALBIN ) :
121
139
mkdir -p $(LOCALBIN )
122
-
140
+
123
141
# # Tool Binaries
124
142
KUSTOMIZE ?= $(LOCALBIN ) /kustomize
125
143
CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
126
144
ENVTEST ?= $(LOCALBIN ) /setup-envtest
127
-
145
+
128
146
# # 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
+
132
150
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
133
151
.PHONY : kustomize
134
152
kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
135
153
$(KUSTOMIZE ) : $(LOCALBIN )
136
154
curl -s $(KUSTOMIZE_INSTALL_SCRIPT ) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION ) ) $(LOCALBIN )
137
-
155
+
138
156
.PHONY : controller-gen
139
157
controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
140
158
$(CONTROLLER_GEN ) : $(LOCALBIN )
141
159
GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
142
-
160
+
143
161
.PHONY : envtest
144
162
envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
145
163
$(ENVTEST ) : $(LOCALBIN )
146
164
GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
147
-
148
-
165
+
166
+
149
167
.PHONY : bundle
150
168
bundle : manifests kustomize # # Generate bundle manifests and metadata, then validate generated files.
151
169
operator-sdk generate kustomize manifests -q
152
170
cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
153
171
$(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION ) $(BUNDLE_METADATA_OPTS )
154
172
operator-sdk bundle validate ./bundle
155
-
173
+
156
174
.PHONY : bundle-build
157
175
bundle-build : # # Build the bundle image.
158
176
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG ) .
159
-
177
+
160
178
.PHONY : bundle-push
161
179
bundle-push : # # Push the bundle image.
162
180
$(MAKE ) docker-push IMG=$(BUNDLE_IMG )
163
-
181
+
164
182
.PHONY : opm
165
183
OPM = ./bin/opm
166
184
opm : # # Download opm locally if necessary.
@@ -172,33 +190,32 @@ ifeq (,$(shell which opm 2>/dev/null))
172
190
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
173
191
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
174
192
chmod +x $(OPM) ;\
175
- }
193
+ }
176
194
else
177
195
OPM = $(shell which opm)
178
196
endif
179
197
endif
180
-
198
+
181
199
# 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).
182
200
# These images MUST exist in a registry and be pull-able.
183
201
BUNDLE_IMGS ?= $(BUNDLE_IMG )
184
-
202
+
185
203
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
186
204
CATALOG_IMG ?= $(IMAGE_TAG_BASE ) -catalog:v$(VERSION )
187
-
205
+
188
206
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
189
207
ifneq ($(origin CATALOG_BASE_IMG ) , undefined)
190
208
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG )
191
209
endif
192
-
210
+
193
211
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
194
212
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
195
213
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
196
214
.PHONY : catalog-build
197
215
catalog-build : opm # # Build a catalog image.
198
216
$(OPM ) index add --container-tool docker --mode semver --tag $(CATALOG_IMG ) --bundles $(BUNDLE_IMGS ) $(FROM_INDEX_OPT )
199
-
217
+
200
218
# Push the catalog image.
201
219
.PHONY : catalog-push
202
220
catalog-push : # # Push a catalog image.
203
221
$(MAKE ) docker-push IMG=$(CATALOG_IMG )
204
-
0 commit comments