33# To re-generate a bundle for another specific version without changing the standard setup, you can:
44# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
55# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
6- VERSION ?= 0.2.0
6+ VERSION ?= 0.0.1
77
88# 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 = "preview ,fast,stable")
9+ # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate ,fast,stable")
1010# 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=preview ,fast,stable)
12- # - use environment variables to overwrite this value (e.g export CHANNELS="preview ,fast,stable")
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")
1313ifneq ($(origin CHANNELS ) , undefined)
1414BUNDLE_CHANNELS := --channels=$(CHANNELS )
1515endif
@@ -24,14 +24,32 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
2424endif
2525BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS ) $(BUNDLE_DEFAULT_CHANNEL )
2626
27+ # IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
28+ # This variable is used to construct full image tags for bundle and catalog images.
29+ #
30+ # For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
31+ # example.com/new-bundle:$VERSION and example.com/new-catalog:$VERSION.
32+ IMAGE_TAG_BASE ?= anbraten/external-database-operator
33+
2734# BUNDLE_IMG defines the image:tag used for the bundle.
2835# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
29- BUNDLE_IMG ?= controller-bundle:$(VERSION )
36+ BUNDLE_IMG ?= $(IMAGE_TAG_BASE ) -bundle:v$(VERSION )
37+
38+ # BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
39+ BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION ) $(BUNDLE_METADATA_OPTS )
40+
41+ # USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
42+ # You can enable this value if you would like to use SHA Based Digests
43+ # To enable set flag to true
44+ USE_IMAGE_DIGESTS ?= false
45+ ifeq ($(USE_IMAGE_DIGESTS ) , true)
46+ BUNDLE_GEN_FLAGS += --use-image-digests
47+ endif
3048
3149# Image URL to use all building/pushing image targets
32- IMG ?= anbraten/external-database-operator: $( VERSION )
33- # Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
34- CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
50+ IMG ?= controller:latest
51+ # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
52+ ENVTEST_K8S_VERSION = 1.23
3553
3654# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
3755ifeq (,$(shell go env GOBIN) )
4058GOBIN =$(shell go env GOBIN)
4159endif
4260
61+ # Setting SHELL to bash allows bash commands to be executed by recipes.
62+ # This is a requirement for 'setup-envtest.sh' in the test target.
63+ # Options are set to exit when a recipe line exits non-zero or a piped command fails.
64+ SHELL = /usr/bin/env bash -o pipefail
65+ .SHELLFLAGS = -ec
66+
67+ .PHONY : all
4368all : build
4469
4570# #@ General
@@ -55,71 +80,88 @@ all: build
5580# More info on the awk command:
5681# http://linuxcommand.org/lc3_adv_awk.php
5782
83+ .PHONY : help
5884help : # # Display this help.
5985 @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
6086
6187# #@ Development
6288
89+ .PHONY : manifests
6390manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
64- $(CONTROLLER_GEN ) $( CRD_OPTIONS ) rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
91+ $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
6592
93+ .PHONY : generate
6694generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
6795 $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
6896
97+ .PHONY : fmt
6998fmt : # # Run go fmt against code.
7099 go fmt ./...
71100
101+ .PHONY : vet
72102vet : # # Run go vet against code.
73103 go vet ./...
74104
75- ENVTEST_ASSETS_DIR =$(shell pwd) /testbin
76- test : manifests generate fmt vet # # Run tests.
77- docker-compose up -d
78- sleep 3s
79- go test -timeout 30s ./adapters/...
80- docker-compose down
81- # mkdir -p ${ENVTEST_ASSETS_DIR}
82- # test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
83- # source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
105+ .PHONY : test
106+ test : manifests generate fmt vet envtest # # Run tests.
107+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test ./... -coverprofile cover.out
84108
85109# #@ Build
86110
111+ .PHONY : build
87112build : generate fmt vet # # Build manager binary.
88113 go build -o bin/manager main.go
89114
115+ .PHONY : run
90116run : manifests generate fmt vet # # Run a controller from your host.
91117 go run ./main.go
92118
119+ .PHONY : docker-build
93120docker-build : # # Build docker image with the manager.
94121 docker build -t ${IMG} .
95122
123+ .PHONY : docker-push
96124docker-push : # # Push docker image with the manager.
97125 docker push ${IMG}
98126
99127# #@ Deployment
100128
101- # install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
102- # $(KUSTOMIZE) build config/crd | kubectl apply -f -
129+ ifndef ignore-not-found
130+ ignore-not-found = false
131+ endif
103132
104- # uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
105- # $(KUSTOMIZE) build config/crd | kubectl delete -f -
133+ .PHONY : install
134+ install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
135+ $(KUSTOMIZE ) build config/crd | kubectl apply -f -
106136
107- # deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
108- # cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
109- # $(KUSTOMIZE) build config/default | kubectl apply -f -
137+ .PHONY : uninstall
138+ 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.
139+ $(KUSTOMIZE ) build config/crd | kubectl delete --ignore-not-found= $( ignore-not-found ) -f -
110140
111- # undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
112- # $(KUSTOMIZE) build config/default | kubectl delete -f -
141+ .PHONY : deploy
142+ deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
143+ cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
144+ $(KUSTOMIZE ) build config/default | kubectl apply -f -
113145
146+ .PHONY : undeploy
147+ 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.
148+ $(KUSTOMIZE ) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
114149
115150CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
151+ .PHONY : controller-gen
116152controller-gen : # # Download controller-gen locally if necessary.
117- $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1 )
153+ $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0 )
118154
119155KUSTOMIZE = $(shell pwd) /bin/kustomize
156+ .PHONY : kustomize
120157kustomize : # # Download kustomize locally if necessary.
121158 $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/[email protected] ) 122159
160+ ENVTEST = $(shell pwd) /bin/setup-envtest
161+ .PHONY : envtest
162+ envtest : # # Download envtest-setup locally if necessary.
163+ $(call go-get-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
164+
123165# go-get-tool will 'go get' any package $2 and install it to $1.
124166PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
125167define go-get-tool
@@ -134,19 +176,62 @@ rm -rf $$TMP_DIR ;\
134176}
135177endef
136178
137- # .PHONY: bundle ## Generate bundle manifests and metadata, then validate generated files.
138- # bundle: manifests kustomize
139- # operator-sdk generate kustomize manifests -q
140- # cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
141- # $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
142- # operator-sdk bundle validate ./bundle
179+ .PHONY : bundle
180+ bundle : manifests kustomize # # Generate bundle manifests and metadata, then validate generated files.
181+ operator-sdk generate kustomize manifests -q
182+ cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
183+ $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS )
184+ operator-sdk bundle validate ./bundle
185+
186+ .PHONY : bundle-build
187+ bundle-build : # # Build the bundle image.
188+ docker build -f bundle.Dockerfile -t $(BUNDLE_IMG ) .
189+
190+ .PHONY : bundle-push
191+ bundle-push : # # Push the bundle image.
192+ $(MAKE ) docker-push IMG=$(BUNDLE_IMG )
193+
194+ .PHONY : opm
195+ OPM = ./bin/opm
196+ opm : # # Download opm locally if necessary.
197+ ifeq (,$(wildcard $(OPM ) ) )
198+ ifeq (,$(shell which opm 2>/dev/null) )
199+ @{ \
200+ set -e ;\
201+ mkdir -p $(dir $(OPM)) ;\
202+ OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
203+ curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.19.1/$${OS}-$${ARCH}-opm ;\
204+ chmod +x $(OPM) ;\
205+ }
206+ else
207+ OPM = $(shell which opm)
208+ endif
209+ endif
210+
211+ # 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).
212+ # These images MUST exist in a registry and be pull-able.
213+ BUNDLE_IMGS ?= $(BUNDLE_IMG )
214+
215+ # The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
216+ CATALOG_IMG ?= $(IMAGE_TAG_BASE ) -catalog:v$(VERSION )
217+
218+ # Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
219+ ifneq ($(origin CATALOG_BASE_IMG ) , undefined)
220+ FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG )
221+ endif
143222
144- # .PHONY: bundle-build ## Build the bundle image.
145- # bundle-build:
146- # docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
223+ # Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
224+ # This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
225+ # https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
226+ .PHONY : catalog-build
227+ catalog-build : opm # # Build a catalog image.
228+ $(OPM ) index add --container-tool docker --mode semver --tag $(CATALOG_IMG ) --bundles $(BUNDLE_IMGS ) $(FROM_INDEX_OPT )
147229
148- # #@ Release
230+ # Push the catalog image.
231+ .PHONY : catalog-push
232+ catalog-push : # # Push a catalog image.
233+ $(MAKE ) docker-push IMG=$(CATALOG_IMG )
149234
150- release : manifests kustomize # # Release kubectl apply -f ready file
235+ generate-manifests : manifests kustomize # # Generate kubectl apply -f ready file
151236 cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
152237 $(KUSTOMIZE ) build config/default > deploy/external-database-controller.yml
0 commit comments