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-
271# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
282# This variable is used to construct full image tags for bundle and catalog images.
293#
@@ -32,25 +6,10 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
326IMAGE_TAG_BASE ?= lightruncom/lightrun-k8s-operator
337# IMAGE_TAG_BASE ?= local-registry:5432/lightrun-k8s-operator
348
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-
509# Image URL to use all building/pushing image targets
51- IMG ?= $( IMAGE_TAG_BASE ) : $( VERSION )
10+ IMG ?= controller:latest
5211# 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
5413
5514# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
5615ifeq (,$(shell go env GOBIN) )
5918GOBIN =$(shell go env GOBIN)
6019endif
6120
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
6226# 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.
6427# Options are set to exit when a recipe line exits non-zero or a piped command fails.
6528SHELL = /usr/bin/env bash -o pipefail
6629.SHELLFLAGS = -ec
@@ -105,39 +68,56 @@ vet: ## Run go vet against code.
10568
10669.PHONY : test
10770test : 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
10972 go tool cover -html=cover.out -o coverage-report.html
11073
11174.PHONY : test-report
11275test-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
11477 $(GOCOV ) convert coverage/cover.out | $(GOCOV_XML ) > coverage/coverage.xml
11578
11679
11780# #@ Build
11881
11982.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
12285
12386.PHONY : run
12487run : manifests generate fmt vet # # Run a controller from your host.
125- go run ./main.go
88+ go run ./cmd/ main.go
12689
12790
12891
12992
13093.PHONY : docker-build
13194docker-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} .
13396
13497.PHONY : docker-push
13598docker-push : # # Push docker image with the manager.
136- docker push ${IMG}
99+ $( CONTAINER_TOOL ) push ${IMG}
137100
138101.PHONY : docker-push-latest
139102docker-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
141121
142122# #@ Deployment
143123
@@ -147,20 +127,20 @@ endif
147127
148128.PHONY : install
149129install : 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 -
151131
152132.PHONY : uninstall
153133uninstall : 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 -
155135
156136.PHONY : deploy
157137deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
158138 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 -
160140
161141.PHONY : undeploy
162142undeploy : # # 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 -
164144
165145# #@ Build Dependencies
166146
@@ -196,6 +176,7 @@ $(LOCALBIN):
196176 mkdir -p $(LOCALBIN )
197177
198178# # Tool Binaries
179+ KUBECTL ?= kubectl
199180KUSTOMIZE ?= $(LOCALBIN ) /kustomize
200181CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
201182ENVTEST ?= $(LOCALBIN ) /setup-envtest
@@ -204,24 +185,29 @@ GOCOV ?= $(LOCALBIN)/gocov
204185GO_JUNIT ?= $(LOCALBIN ) /go-junit-report
205186
206187# # 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
209190
210191KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
211192.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.
213194$(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 )
215200
216201.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.
218203$(CONTROLLER_GEN ) : $(LOCALBIN )
204+ test -s $(LOCALBIN ) /controller-gen && $(LOCALBIN ) /controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION ) || \
219205 GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
220206
221207.PHONY : envtest
222208envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
223209$(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
225211
226212.PHONY : gocov
227213gocov : $(GOCOV )
@@ -237,59 +223,3 @@ $(GOCOV_XML): $(LOCALBIN)
237223go-junit-report : $(GO_JUNIT )
238224$(GO_JUNIT ) : $(LOCALBIN )
239225 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