1
1
SHELL := bash
2
2
platform := $(shell uname | tr A-Z a-z)
3
3
4
+ # ## Helper functions
5
+ # ## https://stackoverflow.com/questions/10858261/how-to-abort-makefile-if-variable-not-set
6
+ check_defined = \
7
+ $(strip $(foreach 1,$1, \
8
+ $(call __check_defined,$1,$(strip $(value 2) ) ) ) )
9
+ __check_defined = \
10
+ $(if $(value $1) ,, \
11
+ $(error Undefined $1$(if $2, ($2) )$(if $(value @) , \
12
+ required by target '$@ ') ) )
13
+ # ##
14
+
4
15
# runs the target list by default
5
16
.DEFAULT_GOAL = list
6
17
7
18
# Insert a comment starting with '##' after a target, and it will be printed by 'make' and 'make list'
8
- list : # # list Makefile targets
19
+ list : # # List Makefile targets
9
20
@grep -E ' ^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST ) | sort | awk ' BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
10
21
11
- # ## Tools
12
- # Allows flexbility to use other build kits, like nerdctl
13
- BUILD_KIT ?= /usr/local/bin/docker
22
+ # ############
23
+ # ## Tools ###
24
+ # ############
25
+
26
+ # Allows flexibility to use other build kits, like nerdctl
27
+ BUILD_KIT ?= docker
14
28
15
29
define get_mod_code_generator
16
30
echo "Only go get & mod k8s.io/code-generator, but do not install it"
17
31
echo "⚠️ Keep it at the same version as captured in go.mod, otherwise we may end up with version inconsistencies"
18
32
awk '/k8s.io\/code-generator/ { system("go get -d " $$1 "@" $$2) }' go.mod
19
33
endef
20
- install-tools :
34
+ install-tools : # # Install tooling required to configure and build this repo
21
35
go mod download
22
36
@echo " Install all tools..."
23
37
@awk -F ' "' ' /_/ && !/k8s.io\/code-generator/ { system("go install " $$2) }' tools/tools.go
@@ -52,8 +66,21 @@ kubebuilder-assets: $(KUBEBUILDER_ASSETS)
52
66
$(KUBEBUILDER_ASSETS ) :
53
67
setup-envtest --os $(platform ) --arch $(ARCHITECTURE ) --bin-dir $(LOCAL_TESTBIN ) use $(ENVTEST_K8S_VERSION )
54
68
55
- # ## Targets
56
-
69
+ # https://github.com/carvel-dev/ytt/releases
70
+ YTT_VERSION ?= v0.50.0
71
+ YTT = $(LOCAL_BIN ) /ytt-$(YTT_VERSION ) -$(platform ) -$(ARCHITECTURE )
72
+ .PHONY : ytt
73
+ ytt : | $(YTT )
74
+ $(YTT ) : | $(LOCAL_BIN )
75
+ @printf " Downloading and installing Carvel YTT\n"
76
+ @curl -sSL -o $(YTT ) https://github.com/carvel-dev/ytt/releases/download/$(YTT_VERSION ) /ytt-$(platform ) -$(ARCHITECTURE )
77
+ @chmod +x $(YTT )
78
+ @ln -s $(LOCAL_BIN ) /ytt-$(YTT_VERSION ) -$(platform ) -$(ARCHITECTURE ) $(LOCAL_BIN ) /ytt
79
+ @printf " Carvel YTT $( YTT_VERSION) installed locally\n"
80
+
81
+ # #############
82
+ # ### Tests ###
83
+ # #############
57
84
.PHONY : unit-tests
58
85
unit-tests ::install-tools # # Run unit tests
59
86
unit-tests ::$(KUBEBUILDER_ASSETS )
@@ -79,12 +106,18 @@ integration-tests::just-integration-tests
79
106
just-integration-tests : $(KUBEBUILDER_ASSETS )
80
107
ginkgo --randomize-all -r -p $(GINKGO_EXTRA ) controllers/
81
108
109
+ .PHONY : local-tests
82
110
local-tests : unit-tests integration-tests # # Run all local tests (unit & integration)
83
111
84
- system-tests : # # run end-to-end tests against Kubernetes cluster defined in ~/.kube/config. Expects cluster operator and messaging topology operator to be installed in the cluster
112
+ .PHONY : system-tests
113
+ system-tests : # # Run E2E tests using current context in ~/.kube/config. Expects cluster operator and topology operator to be installed in the cluster
85
114
NAMESPACE=" rabbitmq-system" ginkgo --randomize-all -r $(GINKGO_EXTRA ) system_tests/
86
115
87
- # Build manager binary
116
+
117
+ # ##################
118
+ # ## Build & Run ###
119
+ # ##################
120
+ .PHONY : manager
88
121
manager : generate fmt vet vuln
89
122
go build -o bin/manager main.go
90
123
@@ -95,49 +128,32 @@ manager: generate fmt vet vuln
95
128
# https://github.com/telepresenceio/telepresence is one way to do this (just run
96
129
# `telepresence connect` and services like `test-service.test-namespace.svc.cluster.local`
97
130
# will resolve properly).
131
+ .PHONY : run
98
132
run : generate fmt vet vuln manifests install just-run
99
133
134
+ .PHONY : just-run
100
135
just-run : # # Just runs 'go run main.go' without regenerating any manifests or deploying RBACs
101
136
KUBE_CONFIG=${HOME} /.kube/config OPERATOR_NAMESPACE=rabbitmq-system ENABLE_WEBHOOKS=false ENABLE_DEBUG_PPROF=true go run ./main.go -metrics-bind-address 127.0.0.1:8080
102
137
103
- # Install CRDs into a cluster
138
+ .PHONY : install
104
139
install : manifests
105
140
kustomize build config/crd | kubectl apply -f -
106
141
107
- # Uninstall CRDs from a cluster
142
+ .PHONY : uninstall
108
143
uninstall : manifests
109
144
kustomize build config/crd | kubectl delete -f -
110
145
146
+ .PHONY : deploy-manager
111
147
deploy-manager : cmctl
112
148
$(CMCTL ) check api --wait=2m
113
149
kustomize build config/default/overlays/cert-manager/ | kubectl apply -f -
114
150
115
- deploy : manifests deploy-rbac deploy-manager
116
-
117
- destroy :
118
- kustomize build config/rbac | kubectl delete --ignore-not-found=true -f -
119
- kustomize build config/default/base | kubectl delete --ignore-not-found=true -f -
120
-
121
- # Deploy operator with local changes
122
- deploy-dev : check-env-docker-credentials cmctl docker-build-dev manifests deploy-rbac docker-registry-secret set-operator-image-repo
123
- $(CMCTL ) check api --wait=2m
124
- kustomize build config/default/overlays/dev | sed ' s@((operator_docker_image))@"$(DOCKER_REGISTRY_SERVER)/$(OPERATOR_IMAGE):$(GIT_COMMIT)"@' | kubectl apply -f -
125
-
126
- # Load operator image and deploy operator into current KinD cluster
127
- deploy-kind : manifests cmctl deploy-rbac
128
- $(BUILD_KIT ) buildx build --build-arg=GIT_COMMIT=$(GIT_COMMIT ) -t $(DOCKER_REGISTRY_SERVER ) /$(OPERATOR_IMAGE ) :$(GIT_COMMIT ) .
129
- kind load docker-image $(DOCKER_REGISTRY_SERVER ) /$(OPERATOR_IMAGE ) :$(GIT_COMMIT )
130
- $(CMCTL ) check api --wait=2m
131
- kustomize build config/default/overlays/kind | sed ' s@((operator_docker_image))@"$(DOCKER_REGISTRY_SERVER)/$(OPERATOR_IMAGE):$(GIT_COMMIT)"@' | kubectl apply -f -
132
-
133
- deploy-rbac :
134
- kustomize build config/rbac | kubectl apply -f -
135
-
136
151
# Generate manifests e.g. CRD, RBAC etc.
137
152
manifests : install-tools
138
153
controller-gen crd rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
139
154
140
155
# Generate API reference documentation
156
+ .PHONY : api-reference
141
157
api-reference :
142
158
crd-ref-docs \
143
159
--source-path ./api \
@@ -146,6 +162,14 @@ api-reference:
146
162
--output-path ./docs/api/rabbitmq.com.ref.asciidoc \
147
163
--max-depth 30
148
164
165
+ # # used in CI pipeline to create release artifact
166
+ .PHONY : generate-manifests
167
+ generate-manifests :
168
+ mkdir -p releases
169
+ kustomize build config/installation/ > releases/messaging-topology-operator.bak
170
+ sed ' /CERTIFICATE_NAMESPACE.*CERTIFICATE_NAME/d' releases/messaging-topology-operator.bak > releases/messaging-topology-operator.yaml
171
+ kustomize build config/installation/cert-manager/ > releases/messaging-topology-operator-with-certmanager.yaml
172
+
149
173
# Run go fmt against code
150
174
fmt :
151
175
go fmt ./...
@@ -162,61 +186,90 @@ vuln:
162
186
generate : install-tools api-reference
163
187
controller-gen object:headerFile=" hack/NOTICE.go.txt" paths=" ./..."
164
188
189
+ .PHONY : generate-client-set
165
190
generate-client-set :
166
191
$(get_mod_code_generator )
167
192
go mod vendor
168
193
./hack/update-codegen.sh
169
194
170
- check-env-docker-credentials : check-env-registry-server
171
- ifndef DOCKER_REGISTRY_USERNAME
172
- $(error DOCKER_REGISTRY_USERNAME is undefined: Username for accessing the docker registry)
173
- endif
174
- ifndef DOCKER_REGISTRY_PASSWORD
175
- $(error DOCKER_REGISTRY_PASSWORD is undefined: Password for accessing the docker registry)
176
- endif
177
- ifndef DOCKER_REGISTRY_SECRET
178
- $(error DOCKER_REGISTRY_SECRET is undefined: Name of Kubernetes secret in which to store the Docker registry username and password)
179
- endif
180
-
181
195
GIT_COMMIT =$(shell git rev-parse --short HEAD) -dev
182
-
183
- docker-build-dev : check-env-docker-repo
196
+ OPERATOR_IMAGE ?= rabbitmqoperator/messaging-topology-operator
197
+ .PHONY : docker-build-dev
198
+ docker-build-dev :
199
+ $(call check_defined, DOCKER_REGISTRY_SERVER, URL of docker registry containing the Operator image (e.g. registry.my-company.com) )
184
200
$(BUILD_KIT ) buildx build --build-arg=GIT_COMMIT=$(GIT_COMMIT ) -t $(DOCKER_REGISTRY_SERVER ) /$(OPERATOR_IMAGE ) :$(GIT_COMMIT ) .
185
201
$(BUILD_KIT ) push $(DOCKER_REGISTRY_SERVER ) /$(OPERATOR_IMAGE ) :$(GIT_COMMIT )
186
202
187
- docker-registry-secret : check-env-docker-credentials operator-namespace
188
- echo " creating registry secret and patching default service account"
189
- @kubectl -n $(K8S_OPERATOR_NAMESPACE ) create secret docker-registry $(DOCKER_REGISTRY_SECRET ) --docker-server=' $(DOCKER_REGISTRY_SERVER)' --docker-username=" $$ DOCKER_REGISTRY_USERNAME" --docker-password=" $$ DOCKER_REGISTRY_PASSWORD" || true
203
+ # docker-build-local and deploy-local work in local Kubernetes installations where the Kubernetes API
204
+ # server runs in the same Docker Context as the build process. This is the case for Rancher Desktop
205
+ # and probably for Docker Desktop. These two commands won't have the desired effect if Kubernetes API
206
+ # is running remotely e.g. Cloud, or if the build context is not shared with Kubernetes API e.g. containerd
207
+ .PHONY : docker-build-local
208
+ docker-build-local :
209
+ $(BUILD_KIT ) buildx build --build-arg=GIT_COMMIT=$(GIT_COMMIT ) -t localhost/topology-operator:$(GIT_COMMIT ) .
210
+
211
+ K8S_OPERATOR_NAMESPACE ?= rabbitmq-system
212
+ .PHONY : docker-registry-secret
213
+ docker-registry-secret :
214
+ $(call check_defined, DOCKER_REGISTRY_USERNAME, Username for accessing the docker registry)
215
+ $(call check_defined, DOCKER_REGISTRY_PASSWORD. Password for accessing the docker registry)
216
+ $(call check_defined, DOCKER_REGISTRY_SECRET, Name of Kubernetes secret in which to store the Docker registry username and password)
217
+ $(call check_defined, DOCKER_REGISTRY_SERVER, URL of docker registry containing the Operator image (e.g. registry.my-company.com) )
218
+ @echo " Creating registry secret and patching default service account"
219
+ @kubectl -n $(K8S_OPERATOR_NAMESPACE ) create secret docker-registry $(DOCKER_REGISTRY_SECRET ) \
220
+ --docker-server=' $(DOCKER_REGISTRY_SERVER)' \
221
+ --docker-username=" $$ DOCKER_REGISTRY_USERNAME" \
222
+ --docker-password=" $$ DOCKER_REGISTRY_PASSWORD" || true
190
223
@kubectl -n $(K8S_OPERATOR_NAMESPACE ) patch serviceaccount messaging-topology-operator -p ' {"imagePullSecrets": [{"name": "$(DOCKER_REGISTRY_SECRET)"}]}'
191
224
192
- check-env-registry-server :
193
- ifndef DOCKER_REGISTRY_SERVER
194
- $(error DOCKER_REGISTRY_SERVER is undefined: URL of docker registry containing the Operator image (e.g. registry.my-company.com))
195
- endif
225
+ # ########################
226
+ # ## Deploy & Teardown ###
227
+ # ########################
228
+ .PHONY : deploy
229
+ deploy : manifests deploy-rbac deploy-manager # # Deploy latest version of this Operator
196
230
197
- check-env-docker-repo : check-env-registry-server set-operator-image-repo
231
+ .PHONY : destroy
232
+ destroy : # # Delete all resources of this Operator
233
+ kustomize build config/rbac | kubectl delete --ignore-not-found=true -f -
234
+ kustomize build config/default/base | kubectl delete --ignore-not-found=true -f -
198
235
199
- set-operator-image-repo :
200
- OPERATOR_IMAGE? =p-rabbitmq-for-kubernetes/messaging-topology-operator
236
+ # Deploy operator with local changes
237
+ .PHONY : deploy-dev
238
+ deploy-dev : cmctl docker-build-dev manifests deploy-rbac docker-registry-secret # # Build current code as a Docker image, push the image, and deploy to current Kubernetes context
239
+ $(call check_defined, DOCKER_REGISTRY_USERNAME, Username for accessing the docker registry)
240
+ $(call check_defined, DOCKER_REGISTRY_PASSWORD. Password for accessing the docker registry)
241
+ $(call check_defined, DOCKER_REGISTRY_SECRET, Name of Kubernetes secret in which to store the Docker registry username and password)
242
+ $(call check_defined, DOCKER_REGISTRY_SERVER, URL of docker registry containing the Operator image (e.g. registry.my-company.com) )
243
+ $(CMCTL ) check api --wait=2m
244
+ kustomize build config/default/overlays/dev | sed ' s@((operator_docker_image))@"$(DOCKER_REGISTRY_SERVER)/$(OPERATOR_IMAGE):$(GIT_COMMIT)"@' | kubectl apply -f -
201
245
202
- operator-namespace :
203
- ifeq (, $(K8S_OPERATOR_NAMESPACE ) )
204
- K8S_OPERATOR_NAMESPACE =rabbitmq-system
205
- endif
246
+ # Load operator image and deploy operator into current KinD cluster
247
+ .PHONY : deploy-kind
248
+ deploy-kind : manifests cmctl deploy-rbac
249
+ $(BUILD_KIT ) buildx build --build-arg=GIT_COMMIT=$(GIT_COMMIT ) -t $(DOCKER_REGISTRY_SERVER ) /$(OPERATOR_IMAGE ) :$(GIT_COMMIT ) .
250
+ kind load docker-image $(DOCKER_REGISTRY_SERVER ) /$(OPERATOR_IMAGE ) :$(GIT_COMMIT )
251
+ $(CMCTL ) check api --wait=2m
252
+ kustomize build config/default/overlays/kind | sed ' s@((operator_docker_image))@"$(DOCKER_REGISTRY_SERVER)/$(OPERATOR_IMAGE):$(GIT_COMMIT)"@' | kubectl apply -f -
253
+
254
+ .PHONY : deploy-local
255
+ deploy-local : cmctl deploy-rbac $(YTT )
256
+ $(CMCTL ) check api --wait=2m
257
+ kustomize build config/default/overlays/cert-manager | $(YTT ) -f- -f config/ytt_overlays/change_deployment_image.yml \
258
+ --data-value operator_image=" localhost/topology-operator:$( GIT_COMMIT) " \
259
+ -f config/ytt_overlays/never_pull.yml | kubectl apply -f-
260
+
261
+ .PHONY : deploy-rbac
262
+ deploy-rbac :
263
+ kustomize build config/rbac | kubectl apply -f -
206
264
265
+ .PHONY : cluster-operator
207
266
cluster-operator :
208
267
@kubectl apply -f https://github.com/rabbitmq/cluster-operator/releases/latest/download/cluster-operator.yml
209
268
269
+ .PHONY : destroy-cluster-operator
210
270
destroy-cluster-operator :
211
271
@kubectl delete -f https://github.com/rabbitmq/cluster-operator/releases/latest/download/cluster-operator.yml --ignore-not-found
212
272
213
- # # used in CI pipeline to create release artifact
214
- generate-manifests :
215
- mkdir -p releases
216
- kustomize build config/installation/ > releases/messaging-topology-operator.bak
217
- sed ' /CERTIFICATE_NAMESPACE.*CERTIFICATE_NAME/d' releases/messaging-topology-operator.bak > releases/messaging-topology-operator.yaml
218
- kustomize build config/installation/cert-manager/ > releases/messaging-topology-operator-with-certmanager.yaml
219
-
220
273
# ###############
221
274
# Cert Manager #
222
275
# ###############
@@ -234,8 +287,10 @@ $(CMCTL): | $(LOCAL_BIN) $(LOCAL_TMP)
234
287
235
288
CERT_MANAGER_VERSION ?= v1.15.1
236
289
CERT_MANAGER_MANIFEST ?= https://github.com/jetstack/cert-manager/releases/download/$(CERT_MANAGER_VERSION ) /cert-manager.yaml
290
+ .PHONY : cert-manager
237
291
cert-manager : # # Deploys Cert Manager from JetStack repo. Use CERT_MANAGER_VERSION to customise version e.g. v1.2.0
238
292
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/$(CERT_MANAGER_VERSION ) /cert-manager.yaml
239
293
294
+ .PHONY : destroy-cert-manager
240
295
destroy-cert-manager : # # Deletes Cert Manager deployment created by 'make cert-manager'
241
296
kubectl delete -f https://github.com/jetstack/cert-manager/releases/download/$(CERT_MANAGER_VERSION ) /cert-manager.yaml
0 commit comments