forked from apecloud/kubeblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
724 lines (616 loc) · 28.5 KB
/
Makefile
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
#
# Copyright 2022 The KubeBlocks Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
# Variables #
################################################################################
APP_NAME = kubeblocks
VERSION ?= 0.7.0-alpha.0
GITHUB_PROXY ?=
INIT_ENV ?= false
TEST_TYPE ?= wesql
GIT_COMMIT = $(shell git rev-list -1 HEAD)
GIT_VERSION = $(shell git describe --always --abbrev=0 --tag)
GENERATED_CLIENT_PKG = "pkg/client"
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25.0
ENABLE_WEBHOOKS ?= false
SKIP_GO_GEN ?= true
CHART_PATH = deploy/helm
WEBHOOK_CERT_DIR ?= /tmp/k8s-webhook-server/serving-certs
# Go setup
export GO111MODULE = auto
export GOSUMDB = sum.golang.org
export GONOPROXY = github.com/apecloud
export GONOSUMDB = github.com/apecloud
export GOPRIVATE = github.com/apecloud
GO ?= go
GOFMT ?= gofmt
GOOS ?= $(shell $(GO) env GOOS)
GOARCH ?= $(shell $(GO) env GOARCH)
# 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
GOPROXY := $(shell go env GOPROXY)
ifeq ($(GOPROXY),)
GOPROXY := https://proxy.golang.org
## use following GOPROXY settings for Chinese mainland developers.
#GOPROXY := https://goproxy.cn
endif
export GOPROXY
LD_FLAGS="-s -w -X main.version=v${VERSION} -X main.buildDate=`date -u +'%Y-%m-%dT%H:%M:%SZ'` -X main.gitCommit=`git rev-parse HEAD`"
# Which architecture to build - see $(ALL_ARCH) for options.
# if the 'local' rule is being run, detect the ARCH from 'go env'
# if it wasn't specified by the caller.
local : ARCH ?= $(shell go env GOOS)-$(shell go env GOARCH)
ARCH ?= linux-amd64
# build tags
BUILD_TAGS="containers_image_openpgp"
TAG_LATEST ?= false
BUILDX_ENABLED ?= ""
ifeq ($(BUILDX_ENABLED), "")
ifeq ($(shell docker buildx inspect 2>/dev/null | awk '/Status/ { print $$2 }'), running)
BUILDX_ENABLED = true
else
BUILDX_ENABLED = false
endif
endif
BUILDX_BUILDER ?= "x-builder"
define BUILDX_ERROR
buildx not enabled, refusing to run this recipe
endef
DOCKER_BUILD_ARGS =
DOCKER_NO_BUILD_CACHE ?= false
ifeq ($(DOCKER_NO_BUILD_CACHE), true)
DOCKER_BUILD_ARGS = $(DOCKER_BUILD_ARGS) --no-cache
endif
.DEFAULT_GOAL := help
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## Display this help.
@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)
.PHONY: all
all: manager dataprotection kbcli lorry reloader ## Make all cmd binaries.
##@ Development
.PHONY: manifests
manifests: test-go-generate controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./cmd/manager/...;./apis/...;./controllers/..." output:crd:artifacts:config=config/crd/bases
@$(MAKE) label-crds --no-print-directory
@cp config/crd/bases/* $(CHART_PATH)/crds
@cp config/rbac/role.yaml $(CHART_PATH)/config/rbac/role.yaml
$(MAKE) client-sdk-gen
.PHONY: label-crds
label-crds:
@for f in config/crd/bases/*.yaml; do \
echo "applying app.kubernetes.io/name=kubeblocks label to $$f"; \
kubectl label --overwrite -f $$f --local=true -o yaml app.kubernetes.io/name=kubeblocks > bin/crd.yaml; \
mv bin/crd.yaml $$f; \
done
.PHONY: preflight-manifests
preflight-manifests: generate ## Generate external Preflight API
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./externalapis/preflight/..." output:crd:artifacts:config=config/crd/preflight
.PHONY: generate
generate: controller-gen build-kbcli-embed-chart ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./apis/...;./externalapis/..."
.PHONY: client-sdk-gen
client-sdk-gen: module ## Generate CRD client code.
@./hack/client-sdk-gen.sh
.PHONY: manager-go-generate
manager-go-generate: ## Run go generate against lifecycle manager code.
ifeq ($(SKIP_GO_GEN), false)
$(GO) generate -x ./internal/configuration/proto
endif
.PHONY: test-go-generate
test-go-generate: ## Run go generate against test code.
$(GO) generate -x ./internal/testutil/k8s/mocks/...
$(GO) generate -x ./internal/configuration/container/mocks/...
$(GO) generate -x ./internal/configuration/proto/mocks/...
.PHONY: fmt
fmt: ## Run go fmt against code.
$(GOFMT) -l -w -s $$(git ls-files --exclude-standard | grep "\.go$$" | grep -v $(GENERATED_CLIENT_PKG))
.PHONY: vet
vet: ## Run go vet against code.
GOOS=$(GOOS) $(GO) vet -tags $(BUILD_TAGS) -mod=mod ./...
.PHONY: cue-fmt
cue-fmt: cuetool ## Run cue fmt against code.
git ls-files --exclude-standard | grep "\.cue$$" | xargs $(CUE) fmt
git ls-files --exclude-standard | grep "\.cue$$" | xargs $(CUE) fix
.PHONY: lint-fast
lint-fast: staticcheck vet golangci-lint # [INTERNAL] Run all lint job against code.
.PHONY: lint
lint: test-go-generate generate ## Run default lint job against code.
$(MAKE) golangci-lint
.PHONY: golangci-lint
golangci-lint: golangci generate ## Run golangci-lint against code.
$(GOLANGCILINT) run ./...
.PHONY: staticcheck
staticcheck: staticchecktool test-go-generate generate ## Run staticcheck against code.
$(STATICCHECK) -tags $(BUILD_TAGS) ./...
.PHONY: build-checks
build-checks: generate fmt vet goimports lint-fast ## Run build checks.
.PHONY: mod-download
mod-download: ## Run go mod download against go modules.
$(GO) mod download
.PHONY: mod-vendor
mod-vendor: module ## Run go mod vendor against go modules.
$(GO) mod vendor
.PHONY: module
module: ## Run go mod tidy->verify against go modules.
$(GO) mod tidy -compat=1.20
$(GO) mod verify
TEST_PACKAGES ?= ./internal/... ./apis/... ./controllers/... ./cmd/...
CLUSTER_TYPES=minikube k3d
.PHONY: add-k8s-host
add-k8s-host: ## add DNS to /etc/hosts when k8s cluster is minikube or k3d
ifneq (, $(findstring $(EXISTING_CLUSTER_TYPE), $(CLUSTER_TYPES)))
ifeq (, $(shell sed -n "/^127.0.0.1[[:space:]]*host.$(EXISTING_CLUSTER_TYPE).internal/p" /etc/hosts))
sudo bash -c 'echo "127.0.0.1 host.$(EXISTING_CLUSTER_TYPE).internal" >> /etc/hosts'
endif
endif
OUTPUT_COVERAGE=-coverprofile cover.out.tmp && grep -v "zz_generated.deepcopy.go" cover.out.tmp > cover.out && rm cover.out.tmp
.PHONY: test-current-ctx
test-current-ctx: manifests generate add-k8s-host ## Run operator controller tests with current $KUBECONFIG context. if existing k8s cluster is k3d or minikube, specify EXISTING_CLUSTER_TYPE.
USE_EXISTING_CLUSTER=true KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(GO) test -tags $(BUILD_TAGS) -p 1 $(TEST_PACKAGES) $(OUTPUT_COVERAGE)
.PHONY: test-fast
test-fast: envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(GO) test -tags $(BUILD_TAGS) -short $(TEST_PACKAGES) $(OUTPUT_COVERAGE)
.PHONY: test
test: manifests generate test-go-generate add-k8s-host test-fast ## Run tests. if existing k8s cluster is k3d or minikube, specify EXISTING_CLUSTER_TYPE.
.PHONY: race
race:
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(GO) test -tags $(BUILD_TAGS) -race $(TEST_PACKAGES)
.PHONY: test-integration
test-integration: manifests generate envtest add-k8s-host ## Run tests. if existing k8s cluster is k3d or minikube, specify EXISTING_CLUSTER_TYPE.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(GO) test -tags $(BUILD_TAGS) ./test/integration
.PHONY: test-delve
test-delve: manifests generate envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" dlv --listen=:$(DEBUG_PORT) --headless=true --api-version=2 --accept-multiclient test $(TEST_PACKAGES)
.PHONY: test-webhook-enabled
test-webhook-enabled: ## Run tests with webhooks enabled.
$(MAKE) test ENABLE_WEBHOOKS=true
.PHONY: cover-report
cover-report: ## Generate cover.html from cover.out
$(GO) tool cover -html=cover.out -o cover.html
ifeq ($(GOOS), darwin)
open ./cover.html
else
echo "open cover.html with a HTML viewer."
endif
.PHONY: goimports
goimports: goimportstool ## Run goimports against code.
$(GOIMPORTS) -local github.com/apecloud/kubeblocks -w $$(git ls-files|grep "\.go$$" | grep -v $(GENERATED_CLIENT_PKG))
##@ CLI
K3S_VERSION ?= v1.23.8+k3s1
K3D_VERSION ?= 5.4.4
K3S_IMG_TAG ?= $(subst +,-,$(K3S_VERSION))
CLI_LD_FLAGS ="-s -w \
-X github.com/apecloud/kubeblocks/version.BuildDate=`date -u +'%Y-%m-%dT%H:%M:%SZ'` \
-X github.com/apecloud/kubeblocks/version.GitCommit=$(GIT_COMMIT) \
-X github.com/apecloud/kubeblocks/version.GitVersion=$(GIT_VERSION) \
-X github.com/apecloud/kubeblocks/version.Version=$(VERSION) \
-X github.com/apecloud/kubeblocks/version.K3sImageTag=$(K3S_IMG_TAG) \
-X github.com/apecloud/kubeblocks/version.K3dVersion=$(K3D_VERSION) \
-X github.com/apecloud/kubeblocks/version.DefaultKubeBlocksVersion=$(VERSION)"
bin/kbcli.%: test-go-generate ## Cross build bin/kbcli.$(OS).$(ARCH).
GOOS=$(word 2,$(subst ., ,$@)) GOARCH=$(word 3,$(subst ., ,$@)) $(GO) build -tags $(BUILD_TAGS) -ldflags=${CLI_LD_FLAGS} -o $@ cmd/cli/main.go
.PHONY: kbcli-fast
kbcli-fast: OS=$(shell $(GO) env GOOS)
kbcli-fast: ARCH=$(shell $(GO) env GOARCH)
kbcli-fast: build-kbcli-embed-chart
$(MAKE) bin/kbcli.$(OS).$(ARCH)
@mv bin/kbcli.$(OS).$(ARCH) bin/kbcli
create-kbcli-embed-charts-dir:
mkdir -p internal/cli/cluster/charts/
build-single-kbcli-embed-chart.%: chart=$(word 2,$(subst ., ,$@))
build-single-kbcli-embed-chart.%:
$(HELM) dependency update deploy/$(chart) --skip-refresh
ifeq ($(VERSION), latest)
$(HELM) package deploy/$(chart)
else
$(HELM) package deploy/$(chart) --version $(VERSION)
endif
mv $(chart)-*.tgz internal/cli/cluster/charts/$(chart).tgz
.PHONY: build-kbcli-embed-chart
build-kbcli-embed-chart: helmtool create-kbcli-embed-charts-dir \
build-single-kbcli-embed-chart.apecloud-mysql-cluster \
build-single-kbcli-embed-chart.redis-cluster \
build-single-kbcli-embed-chart.postgresql-cluster \
build-single-kbcli-embed-chart.kafka-cluster \
build-single-kbcli-embed-chart.mongodb-cluster \
# build-single-kbcli-embed-chart.neon-cluster
# build-single-kbcli-embed-chart.postgresql-cluster \
# build-single-kbcli-embed-chart.clickhouse-cluster \
# build-single-kbcli-embed-chart.milvus-cluster \
# build-single-kbcli-embed-chart.qdrant-cluster \
# build-single-kbcli-embed-chart.weaviate-cluster
.PHONY: kbcli
kbcli: test-go-generate build-checks kbcli-fast ## Build bin/kbcli.
.PHONY: clean-kbcli
clean-kbcli: ## Clean bin/kbcli*.
rm -f bin/kbcli*
.PHONY: kbcli-doc
kbcli-doc: generate test-go-generate ## generate CLI command reference manual.
$(GO) run -tags $(BUILD_TAGS) ./hack/docgen/cli/main.go ./docs/user_docs/cli
.PHONY: lorryctl-doc
lorryctl-doc: generate test-go-generate ## generate CLI command reference manual.
$(GO) run -tags $(BUILD_TAGS) ./hack/docgen/lorryctl/main.go ./docs/user_docs/lorryctl
.PHONY: api-doc
api-doc: ## generate API reference manual.
@./hack/docgen/api/generate.sh
##@ Operator Controller Manager
.PHONY: manager
manager: cue-fmt generate manager-go-generate test-go-generate build-checks ## Build manager binary.
$(GO) build -tags $(BUILD_TAGS) -ldflags=${LD_FLAGS} -o bin/manager ./cmd/manager/main.go
.PHONY: dataprotection
dataprotection: generate test-go-generate build-checks ## Build dataprotection binary.
$(GO) build -tags $(BUILD_TAGS) -ldflags=${LD_FLAGS} -o bin/dataprotection ./cmd/dataprotection/main.go
CERT_ROOT_CA ?= $(WEBHOOK_CERT_DIR)/rootCA.key
.PHONY: webhook-cert
webhook-cert: $(CERT_ROOT_CA) ## Create root CA certificates for admission webhooks testing.
$(CERT_ROOT_CA):
mkdir -p $(WEBHOOK_CERT_DIR)
cd $(WEBHOOK_CERT_DIR) && \
step certificate create $(APP_NAME) rootCA.crt rootCA.key --profile root-ca --insecure --no-password && \
step certificate create $(APP_NAME)-svc tls.crt tls.key --profile leaf \
--ca rootCA.crt --ca-key rootCA.key \
--san $(APP_NAME)-svc --san $(APP_NAME)-svc.$(APP_NAME) --san $(APP_NAME)-svc.$(APP_NAME).svc --not-after 43200h --insecure --no-password
.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
ifeq ($(ENABLE_WEBHOOKS), true)
$(MAKE) webhook-cert
endif
$(GO) run ./cmd/manager/main.go --zap-devel=false --zap-encoder=console --zap-time-encoding=iso8601
# Run with Delve for development purposes against the configured Kubernetes cluster in ~/.kube/config
# Delve is a debugger for the Go programming language. More info: https://github.com/go-delve/delve
GO_PACKAGE=./cmd/manager/main.go
ARGUMENTS=
DEBUG_PORT=2345
run-delve: manifests generate fmt vet ## Run Delve debugger.
dlv --listen=:$(DEBUG_PORT) --headless=true --api-version=2 --accept-multiclient debug $(GO_PACKAGE) -- $(ARGUMENTS)
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
($(KUSTOMIZE) build config/crd | kubectl replace -f -) || ($(KUSTOMIZE) build config/crd | kubectl create -f -)
.PHONY: uninstall
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.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
.PHONY: dry-run
dry-run: manifests kustomize ## Dry-run deploy job.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
mkdir -p dry-run
$(KUSTOMIZE) build config/default > dry-run/manifests.yaml
.PHONY: undeploy
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.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
##@ Contributor
.PHONY: reviewable
reviewable: generate build-checks test check-license-header ## Run code checks to proceed with PR reviews.
$(GO) mod tidy -compat=1.20
.PHONY: check-diff
check-diff: reviewable ## Run git code diff checker.
git --no-pager diff
git diff --quiet || (echo please run 'make reviewable' to include all changes && false)
echo branch is clean
.PHONY: check-license-header
check-license-header: ## Run license header check.
@./hack/license/header-check.sh
.PHONY: fix-license-header
fix-license-header: ## Run license header fix.
@./hack/license/header-check.sh fix
##@ Helm Chart Tasks
bump-single-chart-appver.%: chart=$*
bump-single-chart-appver.%:
ifeq ($(GOOS), darwin)
sed -i '' "s/^appVersion:.*/appVersion: $(VERSION)/" deploy/$(chart)/Chart.yaml
else
sed -i "s/^appVersion:.*/appVersion: $(VERSION)/" deploy/$(chart)/Chart.yaml
endif
bump-single-chart-ver.%: chart=$*
bump-single-chart-ver.%:
ifeq ($(GOOS), darwin)
sed -i '' "s/^version:.*/version: $(VERSION)/" deploy/$(chart)/Chart.yaml
else
sed -i "s/^version:.*/version: $(VERSION)/" deploy/$(chart)/Chart.yaml
endif
.PHONY: bump-chart-ver
bump-chart-ver: \
bump-single-chart-ver.helm \
bump-single-chart-appver.helm \
bump-single-chart-ver.apecloud-mysql \
bump-single-chart-ver.apecloud-mysql-cluster \
bump-single-chart-ver.clickhouse \
bump-single-chart-ver.clickhouse-cluster \
bump-single-chart-ver.kafka \
bump-single-chart-ver.kafka-cluster \
bump-single-chart-ver.mongodb \
bump-single-chart-ver.mongodb-cluster \
bump-single-chart-ver.nyancat \
bump-single-chart-appver.nyancat \
bump-single-chart-ver.postgresql \
bump-single-chart-ver.postgresql-cluster \
bump-single-chart-ver.redis \
bump-single-chart-ver.redis-cluster \
bump-single-chart-ver.milvus \
bump-single-chart-ver.milvus-cluster \
bump-single-chart-ver.qdrant \
bump-single-chart-ver.qdrant-cluster \
bump-single-chart-ver.weaviate \
bump-single-chart-ver.weaviate-cluster \
bump-single-chart-ver.chatgpt-retrieval-plugin \
bump-single-chart-ver.tdengine \
bump-single-chart-ver.tdengine-cluster
bump-chart-ver: ## Bump helm chart version.
.PHONY: helm-package
helm-package: bump-chart-ver ## Do helm package.
$(HELM) package $(CHART_PATH)
##@ Build Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
## Tool Versions
KUSTOMIZE_VERSION ?= v5.1.1
CONTROLLER_TOOLS_VERSION ?= v0.12.1
CUE_VERSION ?= v0.4.3
KUSTOMIZE_INSTALL_SCRIPT ?= "$(GITHUB_PROXY)https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
ifeq (, $(shell ls $(LOCALBIN)/kustomize 2>/dev/null))
curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
endif
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
ifeq (, $(shell ls $(LOCALBIN)/controller-gen 2>/dev/null))
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
endif
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
ifeq (, $(shell ls $(LOCALBIN)/setup-envtest 2>/dev/null))
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
endif
.PHONY: install-docker-buildx
install-docker-buildx: ## Create `docker buildx` builder.
@if ! docker buildx inspect $(BUILDX_BUILDER) > /dev/null; then \
echo "Buildx builder $(BUILDX_BUILDER) does not exist, creating..."; \
docker buildx create --name=$(BUILDX_BUILDER) --use --driver=docker-container --platform linux/amd64,linux/arm64; \
else \
echo "Buildx builder $(BUILDX_BUILDER) already exists"; \
fi
.PHONY: golangci
golangci: GOLANGCILINT_VERSION = v1.51.2
golangci: ## Download golangci-lint locally if necessary.
ifneq ($(shell which golangci-lint),)
@echo golangci-lint is already installed
GOLANGCILINT=$(shell which golangci-lint)
else ifeq (, $(shell which $(GOBIN)/golangci-lint))
@{ \
set -e ;\
echo 'installing golangci-lint-$(GOLANGCILINT_VERSION)' ;\
curl -sSfL $(GITHUB_PROXY)https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) $(GOLANGCILINT_VERSION) ;\
echo 'Successfully installed' ;\
}
GOLANGCILINT=$(GOBIN)/golangci-lint
else
@echo golangci-lint is already installed
GOLANGCILINT=$(GOBIN)/golangci-lint
endif
.PHONY: staticchecktool
staticchecktool: ## Download staticcheck locally if necessary.
ifeq (, $(shell which staticcheck))
@{ \
set -e ;\
echo 'installing honnef.co/go/tools/cmd/staticcheck' ;\
go install honnef.co/go/tools/cmd/staticcheck@latest;\
}
STATICCHECK=$(GOBIN)/staticcheck
else
STATICCHECK=$(shell which staticcheck)
endif
.PHONY: goimportstool
goimportstool: ## Download goimports locally if necessary.
ifeq (, $(shell which goimports))
@{ \
set -e ;\
go install golang.org/x/tools/cmd/goimports@latest ;\
}
GOIMPORTS=$(GOBIN)/goimports
else
GOIMPORTS=$(shell which goimports)
endif
.PHONY: cuetool
cuetool: ## Download cue locally if necessary.
ifeq (, $(shell which cue))
@{ \
set -e ;\
go install cuelang.org/go/cmd/cue@$(CUE_VERSION) ;\
}
CUE=$(GOBIN)/cue
else
CUE=$(shell which cue)
endif
.PHONY: helmtool
helmtool: ## Download helm locally if necessary.
ifeq (, $(shell which helm))
@{ \
set -e ;\
echo 'installing helm' ;\
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash;\
echo 'Successfully installed' ;\
}
HELM=$(GOBIN)/helm
else
HELM=$(shell which helm)
endif
.PHONY: kubectl
kubectl: ## Download kubectl locally if necessary.
ifeq (, $(shell which kubectl))
@{ \
set -e ;\
echo 'installing kubectl' ;\
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/$(GOOS)/$(GOARCH)/kubectl" && chmod +x kubectl && sudo mv kubectl /usr/local/bin ;\
echo 'Successfully installed' ;\
}
endif
KUBECTL=$(shell which kubectl)
##@ End-to-end (E2E) tests
.PHONY: render-smoke-testdata-manifests
render-smoke-testdata-manifests: ## Update E2E test dataset
ifeq ($(TEST_TYPE), wesql)
$(HELM) dependency build deploy/apecloud-mysql-cluster --skip-refresh
$(HELM) template mysql-cluster deploy/apecloud-mysql-cluster > test/e2e/testdata/smoketest/wesql/00_wesqlcluster.yaml
else ifeq ($(TEST_TYPE), postgresql)
$(HELM) dependency build deploy/postgresql-cluster --skip-refresh
$(HELM) template pg-cluster deploy/postgresql-cluster > test/e2e/testdata/smoketest/postgresql/00_postgresqlcluster.yaml
else ifeq ($(TEST_TYPE), redis)
$(HELM) dependency build deploy/redis-cluster --skip-refresh
$(HELM) template redis-cluster deploy/redis-cluster > test/e2e/testdata/smoketest/redis/00_rediscluster.yaml
else ifeq ($(TEST_TYPE), mongodb)
$(HELM) dependency build deploy/mongodb-cluster --skip-refresh
$(HELM) template mongodb-cluster deploy/mongodb-cluster > test/e2e/testdata/smoketest/mongodb/00_mongodbcluster.yaml
else ifeq ($(TEST_TYPE), pulsar)
$(HELM) dependency build deploy/pulsar-cluster --skip-refresh
$(HELM) template pulsar-cluster deploy/pulsar-cluster > test/e2e/testdata/smoketest/pulsar/00_pulsarcluster.yaml
else ifeq ($(TEST_TYPE), nebula)
$(HELM) dependency build deploy/nebula-cluster --skip-refresh
$(HELM) upgrade --install nebula deploy/nebula
$(HELM) template nebula-cluster deploy/nebula-cluster > test/e2e/testdata/smoketest/nebula/00_nebulacluster.yaml
else ifeq ($(TEST_TYPE), greptimedb)
$(HELM) dependency build deploy/greptimedb-cluster --skip-refresh
$(HELM) upgrade --install greptimedb deploy/greptimedb
$(HELM) template greptimedb-cluster deploy/greptimedb-cluster > test/e2e/testdata/smoketest/greptimedb/00_greptimedbcluster.yaml
else ifeq ($(TEST_TYPE), starrocks)
$(HELM) dependency build deploy/starrocks-cluster --skip-refresh
$(HELM) upgrade --install starrocks deploy/starrocks
$(HELM) template starrocks-cluster deploy/starrocks-cluster > test/e2e/testdata/smoketest/starrocks/00_starrocksbcluster.yaml
else ifeq ($(TEST_TYPE), risingwave)
$(HELM) dependency build deploy/risingwave-cluster --skip-refresh
$(HELM) upgrade --install etcd deploy/etcd
$(HELM) upgrade --install risingwave deploy/risingwave
$(HELM) template risingwave-cluster deploy/risingwave-cluster > test/e2e/testdata/smoketest/risingwave/00_risingwavecluster.yaml
else ifeq ($(TEST_TYPE), etcd)
$(HELM) dependency build deploy/etcd-cluster --skip-refresh
$(HELM) upgrade --install etcd deploy/etcd
$(HELM) template etcd-cluster deploy/etcd-cluster > test/e2e/testdata/smoketest/etcd/00_etcdcluster.yaml
else ifeq ($(TEST_TYPE), oracle)
$(HELM) dependency build deploy/oracle-mysql-cluster --skip-refresh
$(HELM) upgrade --install oracle deploy/oracle-mysql
$(HELM) template oracle-cluster deploy/oracle-mysql-cluster > test/e2e/testdata/smoketest/oracle/00_oraclecluster.yaml
else ifeq ($(TEST_TYPE), kafka)
$(HELM) dependency build deploy/kafka-cluster --skip-refresh
$(HELM) upgrade --install kafka deploy/kafka
$(HELM) template kafka-cluster deploy/kafka-cluster > test/e2e/testdata/smoketest/kafka/00_kafkacluster.yaml
else ifeq ($(TEST_TYPE), foxlake)
$(HELM) dependency build deploy/foxlake-cluster --skip-refresh
$(HELM) upgrade --install foxlake deploy/foxlake
$(HELM) template foxlake-cluster deploy/foxlake-cluster > test/e2e/testdata/smoketest/foxlake/00_foxlakecluster.yaml
else ifeq ($(TEST_TYPE), oceanbase)
$(HELM) dependency build deploy/oceanbase-cluster --skip-refresh
$(HELM) upgrade --install oceanbase deploy/oceanbase
$(HELM) template oceanbase-cluster deploy/oceanbase-cluster > test/e2e/testdata/smoketest/oceanbase/00_oceanbasecluster.yaml
else ifeq ($(TEST_TYPE), official-postgresql)
$(HELM) dependency build deploy/official-postgresql-cluster --skip-refresh
$(HELM) upgrade --install official-postgresql deploy/official-postgresql
$(HELM) template official-pg deploy/official-postgresql-cluster > test/e2e/testdata/smoketest/official-postgresql/00_official_pgcluster.yaml
else ifeq ($(TEST_TYPE), openldap)
$(HELM) dependency build deploy/openldap-cluster --skip-refresh
$(HELM) upgrade --install openldap deploy/openldap
$(HELM) template openldap-cluster deploy/openldap-cluster > test/e2e/testdata/smoketest/openldap/00_openldapcluster.yaml
else ifeq ($(TEST_TYPE), orioledb)
$(HELM) dependency build deploy/orioledb-cluster --skip-refresh
$(HELM) upgrade --install orioledb deploy/orioledb
$(HELM) template oriole-cluster deploy/orioledb-cluster > test/e2e/testdata/smoketest/orioledb/00_orioledbcluster.yaml
else
$(error "test type does not exist")
endif
.PHONY: test-e2e
test-e2e: helm-package render-smoke-testdata-manifests ## Run E2E tests.
$(MAKE) -e VERSION=$(VERSION) PROVIDER=$(PROVIDER) REGION=$(REGION) SECRET_ID=$(SECRET_ID) SECRET_KEY=$(SECRET_KEY) INIT_ENV=$(INIT_ENV) TEST_TYPE=$(TEST_TYPE) SKIP_CASE=$(SKIP_CASE) -C test/e2e run
.PHONY: render-smoke-testdata-manifests-local
render-smoke-testdata-manifests-local: ## Helm Install CD And CV
ifeq ($(TEST_TYPE), wesql)
$(HELM) upgrade --install wesql deploy/apecloud-mysql
else ifeq ($(TEST_TYPE), postgresql)
$(HELM) upgrade --install postgresql deploy/postgresql
else ifeq ($(TEST_TYPE), mongodb)
$(HELM) upgrade --install mongodb deploy/mongodb
else ifeq ($(TEST_TYPE), redis)
$(HELM) upgrade --install redis deploy/redis
else ifeq ($(TEST_TYPE), pulsar)
$(HELM) upgrade --install pulsar deploy/pulsar
else ifeq ($(TEST_TYPE), nebula)
$(HELM) upgrade --install nebula deploy/nebula
else ifeq ($(TEST_TYPE), greptimedb)
$(HELM) upgrade --install greptimedb deploy/greptimedb
else ifeq ($(TEST_TYPE), starrocks)
$(HELM) upgrade --install starrocks deploy/starrocks
else ifeq ($(TEST_TYPE), risingwave)
$(HELM) upgrade --install etcd deploy/etcd
$(HELM) upgrade --install risingwave deploy/risingwave
else ifeq ($(TEST_TYPE), etcd)
$(HELM) upgrade --install etcd deploy/etcd
else ifeq ($(TEST_TYPE), oracle)
$(HELM) upgrade --install oracle-mysql deploy/oracle-mysql
else ifeq ($(TEST_TYPE), kafka)
$(HELM) upgrade --install kafka deploy/kafka
else ifeq ($(TEST_TYPE), foxlake)
$(HELM) upgrade --install foxlake deploy/foxlake
else ifeq ($(TEST_TYPE), oceanbase)
$(HELM) upgrade --install oceanbase deploy/oceanbase
else ifeq ($(TEST_TYPE), oceanbase)
$(HELM) upgrade --install official-postgresql deploy/official-postgresql
else ifeq ($(TEST_TYPE), openldap)
$(HELM) upgrade --install openldap deploy/openldap
else
$(error "test type does not exist")
endif
.PHONY: test-e2e-local
test-e2e-local: generate-cluster-role render-smoke-testdata-manifests-local render-smoke-testdata-manifests ## Run E2E tests on local.
$(MAKE) -e TEST_TYPE=$(TEST_TYPE) -C test/e2e run
.PHONY: generate-cluster-role
generate-cluster-role:
$(HELM) template -s templates/rbac/cluster_pod_required_role.yaml deploy/helm | kubectl apply -f -
# NOTE: include must be placed at the end
include docker/docker.mk
include cmd/cmd.mk