1
- # VERSION defines the project version for the bundle.
2
- # Update this value when you upgrade the version of your project.
3
- # To re-generate a bundle for another specific version without changing the standard setup, you can:
4
- # - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
5
- # - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
6
- VERSION ?= 0.0.31
7
-
8
- # CHANNELS define the bundle channels used in the bundle.
9
- # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
10
- # To re-generate a bundle for other specific channels without changing the standard setup, you can:
11
- # - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
12
- # - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
13
- ifneq ($(origin CHANNELS ) , undefined)
14
- BUNDLE_CHANNELS := --channels=$(CHANNELS )
15
- endif
16
-
17
- # DEFAULT_CHANNEL defines the default channel used in the bundle.
18
- # Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
19
- # To re-generate a bundle for any other default channel without changing the default setup, you can:
20
- # - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
21
- # - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
22
- ifneq ($(origin DEFAULT_CHANNEL ) , undefined)
23
- BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL )
24
- endif
25
- BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS ) $(BUNDLE_DEFAULT_CHANNEL )
26
-
27
1
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
28
2
# This variable is used to construct full image tags for bundle and catalog images.
29
3
#
@@ -32,25 +6,10 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
32
6
IMAGE_TAG_BASE ?= lightruncom/lightrun-k8s-operator
33
7
# IMAGE_TAG_BASE ?= local-registry:5432/lightrun-k8s-operator
34
8
35
- # BUNDLE_IMG defines the image:tag used for the bundle.
36
- # You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
37
- BUNDLE_IMG ?= $(IMAGE_TAG_BASE ) -bundle:v$(VERSION )
38
-
39
- # BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
40
- BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION ) $(BUNDLE_METADATA_OPTS )
41
-
42
- # USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
43
- # You can enable this value if you would like to use SHA Based Digests
44
- # To enable set flag to true
45
- USE_IMAGE_DIGESTS ?= false
46
- ifeq ($(USE_IMAGE_DIGESTS ) , true)
47
- BUNDLE_GEN_FLAGS += --use-image-digests
48
- endif
49
-
50
9
# Image URL to use all building/pushing image targets
51
- IMG ?= $( IMAGE_TAG_BASE ) : $( VERSION )
10
+ IMG ?= controller:latest
52
11
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
53
- ENVTEST_K8S_VERSION = 1.24 .1
12
+ ENVTEST_K8S_VERSION = 1.27 .1
54
13
55
14
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
56
15
ifeq (,$(shell go env GOBIN) )
59
18
GOBIN =$(shell go env GOBIN)
60
19
endif
61
20
21
+ # CONTAINER_TOOL defines the container tool to be used for building images.
22
+ # Be aware that the target commands are only tested with Docker which is
23
+ # scaffolded by default. However, you might want to replace it to use other
24
+ # tools. (i.e. podman)
25
+ CONTAINER_TOOL ?= docker
62
26
# Setting SHELL to bash allows bash commands to be executed by recipes.
63
- # This is a requirement for 'setup-envtest.sh' in the test target.
64
27
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
65
28
SHELL = /usr/bin/env bash -o pipefail
66
29
.SHELLFLAGS = -ec
@@ -105,39 +68,56 @@ vet: ## Run go vet against code.
105
68
106
69
.PHONY : test
107
70
test : manifests generate fmt vet envtest # # Run tests.
108
- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test ./... -covermode count -coverprofile cover.out
71
+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN ) - p path) " go test ./... -covermode count -coverprofile cover.out
109
72
go tool cover -html=cover.out -o coverage-report.html
110
73
111
74
.PHONY : test-report
112
75
test-report : manifests generate fmt vet envtest gocov gocov-xml go-junit-report # # Run tests.
113
- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test ./... -covermode count -coverprofile coverage/cover.out 2>&1 | $(GO_JUNIT ) > coverage/report.xml
76
+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN ) - p path) " go test ./... -covermode count -coverprofile coverage/cover.out 2>&1 | $(GO_JUNIT ) > coverage/report.xml
114
77
$(GOCOV ) convert coverage/cover.out | $(GOCOV_XML ) > coverage/coverage.xml
115
78
116
79
117
80
# #@ Build
118
81
119
82
.PHONY : build
120
- build : generate fmt vet # # Build manager binary.
121
- go build -o bin/manager main.go
83
+ build : manifests generate fmt vet # # Build manager binary.
84
+ go build -o bin/manager cmd/ main.go
122
85
123
86
.PHONY : run
124
87
run : manifests generate fmt vet # # Run a controller from your host.
125
- go run ./main.go
88
+ go run ./cmd/ main.go
126
89
127
90
128
91
129
92
130
93
.PHONY : docker-build
131
94
docker-build : test # # Build docker image with the manager.
132
- docker build -t ${IMG} -t ${IMAGE_TAG_BASE} .
95
+ $( CONTAINER_TOOL ) build -t ${IMG} -t ${IMAGE_TAG_BASE} .
133
96
134
97
.PHONY : docker-push
135
98
docker-push : # # Push docker image with the manager.
136
- docker push ${IMG}
99
+ $( CONTAINER_TOOL ) push ${IMG}
137
100
138
101
.PHONY : docker-push-latest
139
102
docker-push-latest : # # Push docker image with the manager.
140
- docker push ${IMAGE_TAG_BASE}
103
+ $(CONTAINER_TOOL ) push ${IMAGE_TAG_BASE}
104
+
105
+ # PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
106
+ # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
107
+ # - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
108
+ # - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
109
+ # - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
110
+ # To properly provided solutions that supports more than one platform you should use this option.
111
+ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
112
+ .PHONY : docker-buildx
113
+ docker-buildx : test # # Build and push docker image for the manager for cross-platform support
114
+ # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
115
+ sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
116
+ - $(CONTAINER_TOOL ) buildx create --name project-v3-builder
117
+ $(CONTAINER_TOOL ) buildx use project-v3-builder
118
+ - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
119
+ - $(CONTAINER_TOOL ) buildx rm project-v3-builder
120
+ rm Dockerfile.cross
141
121
142
122
# #@ Deployment
143
123
@@ -147,20 +127,20 @@ endif
147
127
148
128
.PHONY : install
149
129
install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
150
- $(KUSTOMIZE ) build config/crd | kubectl apply -f -
130
+ $(KUSTOMIZE ) build config/crd | $( KUBECTL ) apply -f -
151
131
152
132
.PHONY : uninstall
153
133
uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
154
- $(KUSTOMIZE ) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
134
+ $(KUSTOMIZE ) build config/crd | $( KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
155
135
156
136
.PHONY : deploy
157
137
deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
158
138
cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
159
- $(KUSTOMIZE ) build config/default | kubectl apply -f -
139
+ $(KUSTOMIZE ) build config/default | $( KUBECTL ) apply -f -
160
140
161
141
.PHONY : undeploy
162
142
undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
163
- $(KUSTOMIZE ) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
143
+ $(KUSTOMIZE ) build config/default | $( KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
164
144
165
145
# #@ Build Dependencies
166
146
@@ -196,6 +176,7 @@ $(LOCALBIN):
196
176
mkdir -p $(LOCALBIN )
197
177
198
178
# # Tool Binaries
179
+ KUBECTL ?= kubectl
199
180
KUSTOMIZE ?= $(LOCALBIN ) /kustomize
200
181
CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
201
182
ENVTEST ?= $(LOCALBIN ) /setup-envtest
@@ -204,24 +185,29 @@ GOCOV ?= $(LOCALBIN)/gocov
204
185
GO_JUNIT ?= $(LOCALBIN ) /go-junit-report
205
186
206
187
# # Tool Versions
207
- KUSTOMIZE_VERSION ?= v4.5.5
208
- CONTROLLER_TOOLS_VERSION ?= v0.9 .0
188
+ KUSTOMIZE_VERSION ?= v5.0.1
189
+ CONTROLLER_TOOLS_VERSION ?= v0.12 .0
209
190
210
191
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
211
192
.PHONY : kustomize
212
- kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
193
+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
213
194
$(KUSTOMIZE ) : $(LOCALBIN )
214
- curl -s $(KUSTOMIZE_INSTALL_SCRIPT ) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION ) ) $(LOCALBIN )
195
+ @if test -x $(LOCALBIN ) /kustomize && ! $(LOCALBIN ) /kustomize version | grep -q $(KUSTOMIZE_VERSION ) ; then \
196
+ echo " $( LOCALBIN) /kustomize version is not expected $( KUSTOMIZE_VERSION) . Removing it before installing." ; \
197
+ rm -rf $(LOCALBIN ) /kustomize; \
198
+ fi
199
+ test -s $(LOCALBIN ) /kustomize || GOBIN=$(LOCALBIN ) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION )
215
200
216
201
.PHONY : controller-gen
217
- controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
202
+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
218
203
$(CONTROLLER_GEN ) : $(LOCALBIN )
204
+ test -s $(LOCALBIN ) /controller-gen && $(LOCALBIN ) /controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION ) || \
219
205
GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
220
206
221
207
.PHONY : envtest
222
208
envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
223
209
$(ENVTEST ) : $(LOCALBIN )
224
- GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
210
+ test -s $( LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
225
211
226
212
.PHONY : gocov
227
213
gocov : $(GOCOV )
@@ -237,59 +223,3 @@ $(GOCOV_XML): $(LOCALBIN)
237
223
go-junit-report : $(GO_JUNIT )
238
224
$(GO_JUNIT ) : $(LOCALBIN )
239
225
GOBIN=$(LOCALBIN ) go install github.com/jstemmer/go-junit-report/v2@latest
240
-
241
- .PHONY : bundle
242
- bundle : manifests kustomize # # Generate bundle manifests and metadata, then validate generated files.
243
- operator-sdk generate kustomize manifests -q
244
- cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
245
- $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS )
246
- operator-sdk bundle validate ./bundle
247
-
248
- .PHONY : bundle-build
249
- bundle-build : # # Build the bundle image.
250
- docker build -f bundle.Dockerfile -t $(BUNDLE_IMG ) .
251
-
252
- .PHONY : bundle-push
253
- bundle-push : # # Push the bundle image.
254
- $(MAKE ) docker-push IMG=$(BUNDLE_IMG )
255
-
256
- .PHONY : opm
257
- OPM = ./bin/opm
258
- opm : # # Download opm locally if necessary.
259
- ifeq (,$(wildcard $(OPM ) ) )
260
- ifeq (,$(shell which opm 2>/dev/null) )
261
- @{ \
262
- set -e ;\
263
- mkdir -p $(dir $(OPM)) ;\
264
- OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
265
- curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
266
- chmod +x $(OPM) ;\
267
- }
268
- else
269
- OPM = $(shell which opm)
270
- endif
271
- endif
272
-
273
- # 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).
274
- # These images MUST exist in a registry and be pull-able.
275
- BUNDLE_IMGS ?= $(BUNDLE_IMG )
276
-
277
- # The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
278
- CATALOG_IMG ?= $(IMAGE_TAG_BASE ) -catalog:v$(VERSION )
279
-
280
- # Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
281
- ifneq ($(origin CATALOG_BASE_IMG ) , undefined)
282
- FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG )
283
- endif
284
-
285
- # Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
286
- # This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
287
- # https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
288
- .PHONY : catalog-build
289
- catalog-build : opm # # Build a catalog image.
290
- $(OPM ) index add --container-tool docker --mode semver --tag $(CATALOG_IMG ) --bundles $(BUNDLE_IMGS ) $(FROM_INDEX_OPT )
291
-
292
- # Push the catalog image.
293
- .PHONY : catalog-push
294
- catalog-push : # # Push a catalog image.
295
- $(MAKE ) docker-push IMG=$(CATALOG_IMG )
0 commit comments