-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathMakefile
More file actions
377 lines (295 loc) · 15.7 KB
/
Makefile
File metadata and controls
377 lines (295 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
SHELL := /bin/bash
all: manager
export MAKEFLAGS="-j 16" # enable parallelism
# Version tag used for locally built dev images (override with: make target DEV_VERSION=custom)
DEV_VERSION ?= $(USER)-dev
usage:
@ echo "Development utility to work with Operator on daily basis. Just edit your configuration in '~/.operator-dev/contexts', "
@ echo "switch to it using 'make switch', make sure Ops Manager is running (use 'make om') "
@ echo "and call 'make' to start the Kubernetes cluster and the Operator"
@ echo
@ echo "More information can be found by the link https://wiki.corp.mongodb.com/display/MMS/Setting+up+local+development+and+E2E+testing"
@ echo
@ echo "Usage:"
@ echo " prerequisites: installs the command line applications necessary for working with this tool and adds git pre-commit hook."
@ echo " switch: switch current dev context, e.g 'make switch context=kops'. Note, that it switches"
@ echo " kubectl context as well and sets the current namespace to the one configured as the default"
@ echo " one"
@ echo " database: build and push Database image"
@ echo " reset: cleans all Operator related state from Kubernetes and Ops Manager. Pass the 'light=true'"
@ echo " to perform a \"light\" cleanup - delete only Mongodb resources"
@ echo " e2e: runs the e2e test, e.g. 'make e2e test=e2e_sharded_cluster_pv'. The Operator is redeployed before"
@ echo " the test, the namespace is cleaned. The e2e app image is built and pushed. Use a 'light=true'"
@ echo " in case you are developing tests and not changing the application code - this will allow to"
@ echo " avoid rebuilding Operator/Database/Init images. Use 'debug=true' to run operator in debug mode."
@ echo " Use a 'local=true' to run the test locally using 'pytest'."
@ echo " Use a 'skip=true' to skip cleaning resources (this may help developing long-running tests like for Ops Manager)"
@ echo " Sometimes you may need to pass some custom configuration, this can be done this way:"
@ echo " make e2e test=e2e_om_ops_manager_upgrade CUSTOM_OM_VERSION=4.2.8"
@ echo " recreate-e2e-multicluster-kind Recreates local (Kind-based) development environment for running tests"
@ echo " open-automation-config/ac: displays the contents of the Automation Config in in $EDITOR using ~/.operator-dev configuration"
# install all necessary software, must be run only once
prerequisites:
@ scripts/dev/install.sh
precommit:
@ source scripts/dev/set_env_context.sh && pre-commit run --all-files
precommit-full:
@ source scripts/dev/set_env_context.sh && MDB_UPDATE_LICENSES=true MDB_REGENERATE_RBAC=true pre-commit run --all-files
switch:
@ scripts/dev/switch_context.sh $(context) $(additional_override)
switcht:
@ scripts/dev/switch_context_by_test.sh $(test)
# runs the e2e test: make e2e test=e2e_sharded_cluster_pv. The Operator is redeployed before the test, the namespace is cleaned.
# The e2e test image is built and pushed together with all main ones (operator, database, init containers)
# Use 'light=true' parameter to skip images rebuilding - use this mode when you are focused on e2e tests development only
e2e: build-and-push-test-image
@ if [[ -z "$(skip)" ]]; then \
$(MAKE) reset; \
fi
@ if [[ -z "$(light)" ]]; then \
$(MAKE) build-and-push-images; \
fi
@ scripts/dev/launch_e2e.sh
mco-e2e: aws_login build-and-push-mco-test-image
@ if [[ -z "$(skip)" ]]; then \
$(MAKE) reset; \
fi
@ scripts/dev/launch_e2e.sh
reset-helm-leftovers: ## sometimes you didn't cleanly uninstall a helm release, this cleans the existing helm artifacts
@ scripts/dev/reset_helm.sh
e2e-telepresence: build-and-push-test-image
telepresence connect --context $(test_pod_cluster); scripts/dev/launch_e2e.sh; telepresence quit
# clean all kubernetes cluster resources and OM state
reset: reset-mco
go build -o bin/reset ./scripts/dev/reset/ && bin/reset
reset-mco: ## Cleans up e2e test env
kubectl delete mdbc,all,secrets -l e2e-test=true || true
# opens the automation config in your editor
open-automation-config: ac
ac:
@ scripts/dev/print_automation_config.sh
###############################################################################
# Internal Targets
# These won't do anything bad if you call them, they just aren't the ones that
# were designed to be helpful by themselves. Anything below won't be documented
# in the usage target above.
###############################################################################
# dev note on '&> /dev/null || true': if the 'aws_login' is run in parallel (e.g. 'make' launches builds for images
# in parallel and both call 'aws_login') then Docker login may return an error "Error saving credentials:..The
# specified item already exists in the keychain". Seems this allows to ignore the error
aws_login:
@ scripts/dev/configure_container_auth.sh
# cleans up aws resources, including s3 buckets which are older than 5 hours
aws_cleanup:
@ scripts/evergreen/prepare_aws.sh
build-and-push-operator-image: aws_login
@ $(MAKE) operator-image
build-and-push-test-image: aws_login
@ if [[ -z "$(local)" ]]; then \
$(MAKE) test-image; \
fi
build-and-push-mco-test-image: aws_login
@ if [[ -z "$(local)" ]]; then \
$(MAKE) mco-test-image; \
fi
# builds all app images in parallel
build-and-push-images: build-and-push-operator-image om-init-image database operator-image database-init-image
@ $(MAKE) agent-image
# builds all init images
build-and-push-init-images: om-init-image database-init-image
database:
@ scripts/dev/run_python.sh scripts/release/pipeline.py database -b patch -v $(DEV_VERSION)
database-init-image:
@ scripts/dev/run_python.sh scripts/release/pipeline.py init-database -b patch -v $(DEV_VERSION)
# Not setting a parallel-factor will default to 0 which will lead to using all CPUs, that can cause docker to die.
# Here we are defaulting to 6, a higher value might work for you.
agent-image:
@ scripts/dev/run_python.sh scripts/release/pipeline.py --parallel --parallel-factor 6 agent -b patch -v current
agent-image-slow:
@ scripts/dev/run_python.sh scripts/release/pipeline.py --parallel-factor 1 agent -b patch -v current
operator-image:
@ scripts/dev/run_python.sh scripts/release/pipeline.py operator -b patch -v $(DEV_VERSION)
operator-image-staging:
@ scripts/dev/run_python.sh scripts/release/pipeline.py operator -b staging -v $(DEV_VERSION)
om-init-image:
@ scripts/dev/run_python.sh scripts/release/pipeline.py init-ops-manager -b patch -v $(DEV_VERSION)
om-image:
@ scripts/dev/run_python.sh scripts/release/pipeline.py ops-manager -b patch -v 8.0.19
test-image:
@ scripts/dev/run_python.sh scripts/release/pipeline.py meko-tests -b patch -v $(DEV_VERSION)
mco-test-image:
@ scripts/dev/run_python.sh scripts/release/pipeline.py mco-test -b patch -v $(DEV_VERSION)
readiness_probe: aws_login
@ scripts/dev/run_python.sh scripts/release/pipeline.py readiness-probe -b patch -v $(DEV_VERSION)
upgrade_hook: aws_login
@ scripts/dev/run_python.sh scripts/release/pipeline.py upgrade-hook -b patch -v $(DEV_VERSION)
configure-operator:
@ scripts/dev/configure_operator.sh
cert:
@ openssl req -nodes -new -x509 -keyout ca-tls.key -out ca-tls.crt -extensions v3_ca -days 3650
@ mv ca-tls.key ca-tls.crt docker/mongodb-kubernetes-tests/tests/opsmanager/fixtures/
@ cat docker/mongodb-kubernetes-tests/tests/opsmanager/fixtures/ca-tls.crt \
docker/mongodb-kubernetes-tests/tests/opsmanager/fixtures/mongodb-download.crt \
> docker/mongodb-kubernetes-tests/tests/opsmanager/fixtures/ca-tls-full-chain.crt
.PHONY: recreate-e2e-multicluster-kind
recreate-e2e-multicluster-kind:
scripts/dev/recreate_kind_clusters.sh
####################################
## operator-sdk provided Makefile ##
####################################
#
# The next section is the Makefile provided by operator-sdk.
# We'll start moving to use some of the targets provided by it, like
# `manifests` and `bundle`. For now we'll try to maintain both.
# VERSION defines the project version for the bundle.
# Update this value when you upgrade the version of your project.
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 1.15.0
# EXPIRES sets a label to expire images (quay specific)
EXPIRES := --label quay.expires-after=48h
# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable")
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=preview,fast,stable)
# - use environment variables to overwrite this value (e.g export CHANNELS="preview,fast,stable")
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
# DEFAULT_CHANNEL defines the default channel used in the bundle.
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
# To re-generate a bundle for any other default channel without changing the default setup, you can:
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# BUNDLE_IMG defines the image:tag used for the bundle.
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
BUNDLE_IMG ?= controller-bundle:$(VERSION)
# Image URL to use all building/pushing image targets
IMG ?= mongodb-kubernetes-operator:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd"
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
golang-tests:
USE_RACE=false USE_COVERAGE=false scripts/evergreen/unit-tests-golang.sh
golang-tests-race:
USE_RACE=true USE_COVERAGE=true scripts/evergreen/unit-tests-golang.sh
sbom-tests:
scripts/evergreen/unit-tests-sbom.sh
# e2e tests are also in python and we will need to ignore them as they are in the docker/mongodb-kubernetes-tests folder
# additionally, we have one lib which we want to test which is in the =docker/mongodb-kubernetes-tests folder.
python-tests:
scripts/evergreen/unit-tests-python.sh
generate-ssdlc-report:
@ scripts/dev/run_python.sh generate_ssdlc_report.py
# test-race runs golang test with race enabled
test-race: generate fmt vet manifests golang-tests-race
test: generate fmt vet manifests golang-tests
# helm-tests will run helm chart unit tests
helm-tests:
@echo "Running helm chart unit tests..."
helm version
helm plugin list || true
@if ! helm unittest --help >/dev/null 2>&1; then \
echo "helm-unittest plugin not working/not installed, reinstalling..."; \
helm plugin uninstall unittest 2>/dev/null || true; \
helm plugin install https://github.com/helm-unittest/helm-unittest; \
fi
helm unittest helm_chart --color
# all-tests will run golang, python, and helm tests without race (used locally)
all-tests: test python-tests helm-tests
# Build manager binary
manager: generate fmt vet
GOOS=linux GOARCH=amd64 go build -o docker/mongodb-kubernetes-operator/content/mongodb-kubernetes-operator main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
go run ./main.go
# Install CRDs into a cluster
install: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
uninstall: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl delete -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/default | kubectl apply -f -
# UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config
undeploy:
$(KUSTOMIZE) build config/default | kubectl delete -f -
# Generate manifests e.g. CRD etc.
# Uses a sentinel file so Make skips regeneration when api/ sources are unchanged. (the step takes a few second)
CRD_SENTINEL := .generated/crd.sentinel
API_SOURCES := $(shell find api -name "*.go")
manifests: $(CRD_SENTINEL)
$(CRD_SENTINEL): $(API_SOURCES) | controller-gen
@echo "API sources changed. Regenerating CRDs..."
@mkdir -p .generated
export PATH="$(PATH)"; export GOROOT=$(GOROOT); $(CONTROLLER_GEN) $(CRD_OPTIONS) paths=./... output:crd:artifacts:config=config/crd/bases
cp config/crd/bases/* helm_chart/crds/
cat "helm_chart/crds/"* > public/crds.yaml
@touch $(CRD_SENTINEL)
# Run go fmt against code
fmt:
go fmt ./...
# Run go vet against code
vet:
go vet ./...
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Download controller-gen locally if necessary
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen:
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.18.0)
# Download kustomize locally if necessary
KUSTOMIZE ?= $(shell which kustomize 2>/dev/null || echo $(shell pwd)/bin/kustomize)
kustomize:
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.4)
# go-install-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-install-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cp $(PROJECT_DIR)/.tool-versions $$TMP_DIR/.tool-versions || true ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
bundle: manifests kustomize
# we want to create a file that only has the deployment. Note: this will not work if something is added
# after the deployment in openshift.yaml
operator-sdk generate kustomize manifests -q
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)\
--channels=stable --default-channel=stable\
--output-dir ./bundle/$(VERSION)/
operator-sdk bundle validate ./bundle/$(VERSION)
# Build the bundle image.
.PHONY: bundle-build
bundle-build:
docker build $(EXPIRES) --platform linux/amd64 -f ./bundle/$(VERSION)/bundle.Dockerfile -t $(BUNDLE_IMG) .
prepare-local-e2e: reset-mco # prepares the local environment to run a local operator
scripts/dev/prepare_local_e2e_run.sh
prepare-local-olm-e2e:
DIGEST_PINNING_ENABLED=false VERSION_ID=latest scripts/evergreen/operator-sdk/prepare-openshift-bundles-for-e2e.sh
scripts/dev/prepare_local_e2e_olm_run.sh
prepare-operator-configmap: # prepares the local environment to run a local operator
source scripts/dev/set_env_context.sh && source scripts/funcs/printing && source scripts/funcs/operator_deployment && prepare_operator_config_map "$(kubectl config current-context)"
# Lint the helm chart using helm chart-testing tool (`ct`) using the default configuration available at `helm_chart/tests/schemas/`
lint-chart:
scripts/dev/lint_helm_chart.sh