3
3
# To re-generate a bundle for another specific version without changing the standard setup, you can:
4
4
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
5
5
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
6
- VERSION ?= 0.2.0
6
+ VERSION ?= 0.0.1
7
7
8
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 = "preview ,fast,stable")
9
+ # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate ,fast,stable")
10
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=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")
13
13
ifneq ($(origin CHANNELS ) , undefined)
14
14
BUNDLE_CHANNELS := --channels=$(CHANNELS )
15
15
endif
@@ -24,14 +24,32 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
24
24
endif
25
25
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS ) $(BUNDLE_DEFAULT_CHANNEL )
26
26
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
+
27
34
# BUNDLE_IMG defines the image:tag used for the bundle.
28
35
# 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
30
48
31
49
# 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
35
53
36
54
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
37
55
ifeq (,$(shell go env GOBIN) )
40
58
GOBIN =$(shell go env GOBIN)
41
59
endif
42
60
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
43
68
all : build
44
69
45
70
# #@ General
@@ -55,71 +80,88 @@ all: build
55
80
# More info on the awk command:
56
81
# http://linuxcommand.org/lc3_adv_awk.php
57
82
83
+ .PHONY : help
58
84
help : # # Display this help.
59
85
@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 )
60
86
61
87
# #@ Development
62
88
89
+ .PHONY : manifests
63
90
manifests : 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
65
92
93
+ .PHONY : generate
66
94
generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
67
95
$(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
68
96
97
+ .PHONY : fmt
69
98
fmt : # # Run go fmt against code.
70
99
go fmt ./...
71
100
101
+ .PHONY : vet
72
102
vet : # # Run go vet against code.
73
103
go vet ./...
74
104
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
84
108
85
109
# #@ Build
86
110
111
+ .PHONY : build
87
112
build : generate fmt vet # # Build manager binary.
88
113
go build -o bin/manager main.go
89
114
115
+ .PHONY : run
90
116
run : manifests generate fmt vet # # Run a controller from your host.
91
117
go run ./main.go
92
118
119
+ .PHONY : docker-build
93
120
docker-build : # # Build docker image with the manager.
94
121
docker build -t ${IMG} .
95
122
123
+ .PHONY : docker-push
96
124
docker-push : # # Push docker image with the manager.
97
125
docker push ${IMG}
98
126
99
127
# #@ Deployment
100
128
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
103
132
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 -
106
136
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 -
110
140
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 -
113
145
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 -
114
149
115
150
CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
151
+ .PHONY : controller-gen
116
152
controller-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 )
118
154
119
155
KUSTOMIZE = $(shell pwd) /bin/kustomize
156
+ .PHONY : kustomize
120
157
kustomize : # # Download kustomize locally if necessary.
121
158
$(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/[email protected] )
122
159
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
+
123
165
# go-get-tool will 'go get' any package $2 and install it to $1.
124
166
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
125
167
define go-get-tool
@@ -134,19 +176,62 @@ rm -rf $$TMP_DIR ;\
134
176
}
135
177
endef
136
178
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
143
222
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 )
147
229
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 )
149
234
150
- release : manifests kustomize # # Release kubectl apply -f ready file
235
+ generate-manifests : manifests kustomize # # Generate kubectl apply -f ready file
151
236
cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
152
237
$(KUSTOMIZE ) build config/default > deploy/external-database-controller.yml
0 commit comments