github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/Makefile (about)

     1  #
     2  # Copyright 2022 The KubeBlocks Authors
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #     http://www.apache.org/licenses/LICENSE-2.0
     7  # Unless required by applicable law or agreed to in writing, software
     8  # distributed under the License is distributed on an "AS IS" BASIS,
     9  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    10  # See the License for the specific language governing permissions and
    11  # limitations under the License.
    12  #
    13  
    14  ################################################################################
    15  # Variables                                                                    #
    16  ################################################################################
    17  APP_NAME = kubeblocks
    18  VERSION ?= 0.8.0-alpha.0
    19  GITHUB_PROXY ?=
    20  INIT_ENV ?= false
    21  TEST_TYPE ?= wesql
    22  GIT_COMMIT  = $(shell git rev-list -1 HEAD)
    23  GIT_VERSION = $(shell git describe --always --abbrev=0 --tag)
    24  GENERATED_CLIENT_PKG = "pkg/client"
    25  # Setting SHELL to bash allows bash commands to be executed by recipes.
    26  # This is a requirement for 'setup-envtest.sh' in the test target.
    27  # Options are set to exit when a recipe line exits non-zero or a piped command fails.
    28  SHELL = /usr/bin/env bash -o pipefail
    29  .SHELLFLAGS = -ec
    30  
    31  # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
    32  ENVTEST_K8S_VERSION = 1.25.0
    33  ENABLE_WEBHOOKS ?= false
    34  SKIP_GO_GEN ?= true
    35  CHART_PATH = deploy/helm
    36  WEBHOOK_CERT_DIR ?= /tmp/k8s-webhook-server/serving-certs
    37  
    38  
    39  
    40  # Go setup
    41  export GO111MODULE = auto
    42  export GOSUMDB = sum.golang.org
    43  export GONOPROXY = github.com/apecloud
    44  export GONOSUMDB = github.com/apecloud
    45  export GOPRIVATE = github.com/apecloud
    46  GO ?= go
    47  GOFMT ?= gofmt
    48  GOOS ?= $(shell $(GO) env GOOS)
    49  GOARCH ?= $(shell $(GO) env GOARCH)
    50  # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
    51  ifeq (,$(shell $(GO) env GOBIN))
    52  GOBIN=$(shell $(GO) env GOPATH)/bin
    53  else
    54  GOBIN=$(shell $(GO) env GOBIN)
    55  endif
    56  GOPROXY := $(shell go env GOPROXY)
    57  ifeq ($(GOPROXY),)
    58  GOPROXY := https://proxy.golang.org
    59  ## use following GOPROXY settings for Chinese mainland developers.
    60  #GOPROXY := https://goproxy.cn
    61  endif
    62  export GOPROXY
    63  
    64  
    65  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`"
    66  # Which architecture to build - see $(ALL_ARCH) for options.
    67  # if the 'local' rule is being run, detect the ARCH from 'go env'
    68  # if it wasn't specified by the caller.
    69  local : ARCH ?= $(shell go env GOOS)-$(shell go env GOARCH)
    70  ARCH ?= linux-amd64
    71  
    72  # build tags
    73  BUILD_TAGS="containers_image_openpgp"
    74  
    75  
    76  TAG_LATEST ?= false
    77  BUILDX_ENABLED ?= ""
    78  ifeq ($(BUILDX_ENABLED), "")
    79  	ifeq ($(shell docker buildx inspect 2>/dev/null | awk '/Status/ { print $$2 }'), running)
    80  		BUILDX_ENABLED = true
    81  	else
    82  		BUILDX_ENABLED = false
    83  	endif
    84  endif
    85  BUILDX_BUILDER ?= "x-builder"
    86  
    87  define BUILDX_ERROR
    88  buildx not enabled, refusing to run this recipe
    89  endef
    90  
    91  DOCKER_BUILD_ARGS =
    92  DOCKER_NO_BUILD_CACHE ?= false
    93  
    94  ifeq ($(DOCKER_NO_BUILD_CACHE), true)
    95  	DOCKER_BUILD_ARGS = $(DOCKER_BUILD_ARGS) --no-cache
    96  endif
    97  
    98  
    99  .DEFAULT_GOAL := help
   100  
   101  ##@ General
   102  
   103  # The help target prints out all targets with their descriptions organized
   104  # beneath their categories. The categories are represented by '##@' and the
   105  # target descriptions by '##'. The awk commands is responsible for reading the
   106  # entire set of makefiles included in this invocation, looking for lines of the
   107  # file as xyz: ## something, and then pretty-format the target and help. Then,
   108  # if there's a line with ##@ something, that gets pretty-printed as a category.
   109  # More info on the usage of ANSI control characters for terminal formatting:
   110  # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
   111  # More info on the awk command:
   112  # http://linuxcommand.org/lc3_adv_awk.php
   113  # https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
   114  
   115  .PHONY: help
   116  help: ## Display this help.
   117  	@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)
   118  
   119  .PHONY: all
   120  all: manager dataprotection kbcli lorry reloader ## Make all cmd binaries.
   121  
   122  ##@ Development
   123  
   124  .PHONY: manifests
   125  manifests: test-go-generate controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
   126  	$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./cmd/manager/...;./apis/...;./controllers/..." output:crd:artifacts:config=config/crd/bases
   127  	@$(MAKE) label-crds --no-print-directory
   128  	@cp config/crd/bases/* $(CHART_PATH)/crds
   129  	@cp config/rbac/role.yaml $(CHART_PATH)/config/rbac/role.yaml
   130  	$(MAKE) client-sdk-gen
   131  
   132  .PHONY: label-crds
   133  label-crds:
   134  	@for f in config/crd/bases/*.yaml; do \
   135  		echo "applying app.kubernetes.io/name=kubeblocks label to $$f"; \
   136  		kubectl label --overwrite -f $$f --local=true -o yaml app.kubernetes.io/name=kubeblocks > bin/crd.yaml; \
   137  		mv bin/crd.yaml $$f; \
   138  	done
   139  
   140  .PHONY: preflight-manifests
   141  preflight-manifests: generate ## Generate external Preflight API
   142  	$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./externalapis/preflight/..." output:crd:artifacts:config=config/crd/preflight
   143  
   144  .PHONY: generate
   145  generate: controller-gen build-kbcli-embed-chart ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
   146  	$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./apis/...;./externalapis/..."
   147  
   148  .PHONY: client-sdk-gen
   149  client-sdk-gen: module ## Generate CRD client code.
   150  	@./hack/client-sdk-gen.sh
   151  
   152  .PHONY: manager-go-generate
   153  manager-go-generate: ## Run go generate against lifecycle manager code.
   154  ifeq ($(SKIP_GO_GEN), false)
   155  	$(GO) generate -x ./pkg/configuration/proto
   156  endif
   157  
   158  .PHONY: test-go-generate
   159  test-go-generate: ## Run go generate against test code.
   160  	$(GO) generate -x ./pkg/testutil/k8s/mocks/...
   161  	$(GO) generate -x ./pkg/configuration/container/mocks/...
   162  	$(GO) generate -x ./pkg/configuration/proto/mocks/...
   163  
   164  .PHONY: fmt
   165  fmt: ## Run go fmt against code.
   166  	$(GOFMT) -l -w -s $$(git ls-files --exclude-standard | grep "\.go$$" | grep -v $(GENERATED_CLIENT_PKG))
   167  
   168  .PHONY: vet
   169  vet: ## Run go vet against code.
   170  	GOOS=$(GOOS) $(GO) vet -tags $(BUILD_TAGS) -mod=mod ./...
   171  
   172  .PHONY: cue-fmt
   173  cue-fmt: cuetool ## Run cue fmt against code.
   174  	git ls-files --exclude-standard | grep "\.cue$$" | xargs $(CUE) fmt
   175  	git ls-files --exclude-standard | grep "\.cue$$" | xargs $(CUE) fix
   176  
   177  .PHONY: lint-fast
   178  lint-fast: staticcheck vet golangci-lint # [INTERNAL] Run all lint job against code.
   179  
   180  .PHONY: lint
   181  lint: test-go-generate generate ## Run default lint job against code.
   182  	$(MAKE) golangci-lint
   183  
   184  .PHONY: golangci-lint
   185  golangci-lint: golangci generate ## Run golangci-lint against code.
   186  	$(GOLANGCILINT) run ./...
   187  
   188  .PHONY: staticcheck
   189  staticcheck: staticchecktool test-go-generate generate ## Run staticcheck against code.
   190  	$(STATICCHECK) -tags $(BUILD_TAGS) ./...
   191  
   192  .PHONY: build-checks
   193  build-checks: generate fmt vet goimports lint-fast ## Run build checks.
   194  
   195  .PHONY: mod-download
   196  mod-download: ## Run go mod download against go modules.
   197  	$(GO) mod download
   198  
   199  .PHONY: mod-vendor
   200  mod-vendor: module ## Run go mod vendor against go modules.
   201  	$(GO) mod vendor
   202  
   203  .PHONY: module
   204  module: ## Run go mod tidy->verify against go modules.
   205  	$(GO) mod tidy -compat=1.21
   206  	$(GO) mod verify
   207  
   208  TEST_PACKAGES ?= ./pkg/... ./apis/... ./controllers/... ./cmd/...
   209  
   210  CLUSTER_TYPES=minikube k3d
   211  .PHONY: add-k8s-host
   212  add-k8s-host:  ## add DNS to /etc/hosts when k8s cluster is minikube or k3d
   213  ifneq (, $(findstring $(EXISTING_CLUSTER_TYPE), $(CLUSTER_TYPES)))
   214  ifeq (, $(shell sed -n "/^127.0.0.1[[:space:]]*host.$(EXISTING_CLUSTER_TYPE).internal/p" /etc/hosts))
   215  	sudo bash -c 'echo "127.0.0.1 host.$(EXISTING_CLUSTER_TYPE).internal" >> /etc/hosts'
   216  endif
   217  endif
   218  
   219  
   220  OUTPUT_COVERAGE=-coverprofile cover.out.tmp && grep -v "zz_generated.deepcopy.go" cover.out.tmp > cover.out && rm cover.out.tmp
   221  .PHONY: test-current-ctx
   222  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.
   223  	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)
   224  
   225  .PHONY: test-fast
   226  test-fast: envtest
   227  	KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(GO) test -tags $(BUILD_TAGS) -short $(TEST_PACKAGES)  $(OUTPUT_COVERAGE)
   228  
   229  .PHONY: test
   230  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.
   231  
   232  .PHONY: race
   233  race:
   234  	KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(GO) test -tags $(BUILD_TAGS) -race $(TEST_PACKAGES)
   235  
   236  .PHONY: test-integration
   237  test-integration: manifests generate envtest add-k8s-host ## Run tests. if existing k8s cluster is k3d or minikube, specify EXISTING_CLUSTER_TYPE.
   238  	KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(GO) test -tags $(BUILD_TAGS) ./test/integration
   239  
   240  .PHONY: test-delve
   241  test-delve: manifests generate envtest ## Run tests.
   242  	KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" dlv --listen=:$(DEBUG_PORT) --headless=true --api-version=2 --accept-multiclient test $(TEST_PACKAGES)
   243  
   244  .PHONY: test-webhook-enabled
   245  test-webhook-enabled: ## Run tests with webhooks enabled.
   246  	$(MAKE) test ENABLE_WEBHOOKS=true
   247  
   248  .PHONY: cover-report
   249  cover-report: ## Generate cover.html from cover.out
   250  	$(GO) tool cover -html=cover.out -o cover.html
   251  ifeq ($(GOOS), darwin)
   252  	open ./cover.html
   253  else
   254  	echo "open cover.html with a HTML viewer."
   255  endif
   256  
   257  .PHONY: goimports
   258  goimports: goimportstool ## Run goimports against code.
   259  	$(GOIMPORTS) -local github.com/apecloud/kubeblocks -w $$(git ls-files|grep "\.go$$" | grep -v $(GENERATED_CLIENT_PKG))
   260  
   261  
   262  ##@ CLI
   263  K3S_VERSION ?= v1.23.8+k3s1
   264  K3D_VERSION ?= 5.4.4
   265  K3S_IMG_TAG ?= $(subst +,-,$(K3S_VERSION))
   266  
   267  CLI_LD_FLAGS ="-s -w \
   268  	-X github.com/apecloud/kubeblocks/version.BuildDate=`date -u +'%Y-%m-%dT%H:%M:%SZ'` \
   269  	-X github.com/apecloud/kubeblocks/version.GitCommit=$(GIT_COMMIT) \
   270  	-X github.com/apecloud/kubeblocks/version.GitVersion=$(GIT_VERSION) \
   271  	-X github.com/apecloud/kubeblocks/version.Version=$(VERSION) \
   272  	-X github.com/apecloud/kubeblocks/version.K3sImageTag=$(K3S_IMG_TAG) \
   273  	-X github.com/apecloud/kubeblocks/version.K3dVersion=$(K3D_VERSION) \
   274  	-X github.com/apecloud/kubeblocks/version.DefaultKubeBlocksVersion=$(VERSION)"
   275  
   276  bin/kbcli.%: test-go-generate ## Cross build bin/kbcli.$(OS).$(ARCH).
   277  	GOOS=$(word 2,$(subst ., ,$@)) GOARCH=$(word 3,$(subst ., ,$@)) $(GO) build -tags $(BUILD_TAGS) -ldflags=${CLI_LD_FLAGS} -o $@ cmd/cli/main.go
   278  
   279  .PHONY: kbcli-fast
   280  kbcli-fast: OS=$(shell $(GO) env GOOS)
   281  kbcli-fast: ARCH=$(shell $(GO) env GOARCH)
   282  kbcli-fast: build-kbcli-embed-chart
   283  	$(MAKE) bin/kbcli.$(OS).$(ARCH)
   284  	@mv bin/kbcli.$(OS).$(ARCH) bin/kbcli
   285  
   286  create-kbcli-embed-charts-dir:
   287  	mkdir -p pkg/cli/cluster/charts/
   288  build-single-kbcli-embed-chart.%: chart=$(word 2,$(subst ., ,$@))
   289  build-single-kbcli-embed-chart.%:
   290  	$(HELM) dependency update deploy/$(chart) --skip-refresh
   291  ifeq ($(VERSION), latest)
   292  	$(HELM) package deploy/$(chart)
   293  else
   294  	$(HELM) package deploy/$(chart) --version $(VERSION)
   295  endif
   296  	mv $(chart)-*.tgz pkg/cli/cluster/charts/$(chart).tgz
   297  
   298  .PHONY: build-kbcli-embed-chart
   299  build-kbcli-embed-chart: helmtool create-kbcli-embed-charts-dir \
   300  	build-single-kbcli-embed-chart.apecloud-mysql-cluster \
   301  	build-single-kbcli-embed-chart.redis-cluster \
   302  	build-single-kbcli-embed-chart.postgresql-cluster \
   303  	build-single-kbcli-embed-chart.kafka-cluster \
   304  	build-single-kbcli-embed-chart.mongodb-cluster \
   305  	build-single-kbcli-embed-chart.llm-cluster \
   306  #	build-single-kbcli-embed-chart.neon-cluster
   307  #	build-single-kbcli-embed-chart.postgresql-cluster \
   308  #	build-single-kbcli-embed-chart.clickhouse-cluster \
   309  #	build-single-kbcli-embed-chart.milvus-cluster \
   310  #	build-single-kbcli-embed-chart.qdrant-cluster \
   311  #	build-single-kbcli-embed-chart.weaviate-cluster
   312  
   313  .PHONY: kbcli
   314  kbcli: test-go-generate build-checks kbcli-fast ## Build bin/kbcli.
   315  
   316  .PHONY: clean-kbcli
   317  clean-kbcli: ## Clean bin/kbcli*.
   318  	rm -f bin/kbcli*
   319  
   320  .PHONY: kbcli-doc
   321  kbcli-doc: generate test-go-generate ## generate CLI command reference manual.
   322  	$(GO) run -tags $(BUILD_TAGS) ./hack/docgen/cli/main.go ./docs/user_docs/cli
   323  
   324  .PHONY: lorryctl-doc
   325  lorryctl-doc: generate test-go-generate ## generate CLI command reference manual.
   326  	$(GO) run -tags $(BUILD_TAGS) ./hack/docgen/lorryctl/main.go ./docs/user_docs/lorryctl
   327  
   328  .PHONY: api-doc
   329  api-doc:  ## generate API reference manual.
   330  	@./hack/docgen/api/generate.sh
   331  
   332  
   333  ##@ Operator Controller Manager
   334  
   335  .PHONY: manager
   336  manager: cue-fmt generate manager-go-generate test-go-generate build-checks ## Build manager binary.
   337  	$(GO) build -tags $(BUILD_TAGS) -ldflags=${LD_FLAGS} -o bin/manager ./cmd/manager/main.go
   338  
   339  .PHONY: dataprotection
   340  dataprotection: generate test-go-generate build-checks ## Build dataprotection binary.
   341  	$(GO) build -tags $(BUILD_TAGS) -ldflags=${LD_FLAGS} -o bin/dataprotection ./cmd/dataprotection/main.go
   342  
   343  CERT_ROOT_CA ?= $(WEBHOOK_CERT_DIR)/rootCA.key
   344  .PHONY: webhook-cert
   345  webhook-cert: $(CERT_ROOT_CA) ## Create root CA certificates for admission webhooks testing.
   346  $(CERT_ROOT_CA):
   347  	mkdir -p $(WEBHOOK_CERT_DIR)
   348  	cd $(WEBHOOK_CERT_DIR) && \
   349  		step certificate create $(APP_NAME) rootCA.crt rootCA.key --profile root-ca --insecure --no-password && \
   350  		step certificate create $(APP_NAME)-svc tls.crt tls.key --profile leaf \
   351  			--ca rootCA.crt --ca-key rootCA.key \
   352  			--san $(APP_NAME)-svc --san $(APP_NAME)-svc.$(APP_NAME) --san $(APP_NAME)-svc.$(APP_NAME).svc --not-after 43200h --insecure --no-password
   353  
   354  .PHONY: run
   355  run: manifests generate fmt vet ## Run a controller from your host.
   356  ifeq ($(ENABLE_WEBHOOKS), true)
   357  	$(MAKE) webhook-cert
   358  endif
   359  	$(GO) run ./cmd/manager/main.go --zap-devel=false --zap-encoder=console --zap-time-encoding=iso8601
   360  
   361  # Run with Delve for development purposes against the configured Kubernetes cluster in ~/.kube/config
   362  # Delve is a debugger for the Go programming language. More info: https://github.com/go-delve/delve
   363  GO_PACKAGE=./cmd/manager/main.go
   364  ARGUMENTS=
   365  DEBUG_PORT=2345
   366  run-delve: manifests generate fmt vet  ## Run Delve debugger.
   367  	dlv --listen=:$(DEBUG_PORT) --headless=true --api-version=2 --accept-multiclient debug $(GO_PACKAGE) -- $(ARGUMENTS)
   368  ##@ Deployment
   369  
   370  ifndef ignore-not-found
   371    ignore-not-found = false
   372  endif
   373  
   374  .PHONY: install
   375  install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
   376  	($(KUSTOMIZE) build config/crd | kubectl replace -f -) || ($(KUSTOMIZE) build config/crd | kubectl create -f -)
   377  
   378  .PHONY: uninstall
   379  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.
   380  	$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
   381  
   382  .PHONY: deploy
   383  deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
   384  	cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
   385  	$(KUSTOMIZE) build config/default | kubectl apply -f -
   386  
   387  .PHONY: dry-run
   388  dry-run: manifests kustomize ## Dry-run deploy job.
   389  	cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
   390  	mkdir -p dry-run
   391  	$(KUSTOMIZE) build config/default > dry-run/manifests.yaml
   392  
   393  .PHONY: undeploy
   394  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.
   395  	$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
   396  
   397  ##@ Contributor
   398  
   399  .PHONY: reviewable
   400  reviewable: generate build-checks test check-license-header ## Run code checks to proceed with PR reviews.
   401  	$(GO) mod tidy -compat=1.21
   402  
   403  .PHONY: check-diff
   404  check-diff: reviewable ## Run git code diff checker.
   405  	git --no-pager diff
   406  	git diff --quiet || (echo please run 'make reviewable' to include all changes && false)
   407  	echo branch is clean
   408  
   409  .PHONY: check-license-header
   410  check-license-header: ## Run license header check.
   411  	@./hack/license/header-check.sh
   412  
   413  .PHONY: fix-license-header
   414  fix-license-header: ## Run license header fix.
   415  	@./hack/license/header-check.sh fix
   416  
   417  ##@ Helm Chart Tasks
   418  
   419  bump-single-chart-appver.%: chart=$*
   420  bump-single-chart-appver.%:
   421  ifeq ($(GOOS), darwin)
   422  	sed -i '' "s/^appVersion:.*/appVersion: $(VERSION)/" deploy/$(chart)/Chart.yaml
   423  else
   424  	sed -i "s/^appVersion:.*/appVersion: $(VERSION)/" deploy/$(chart)/Chart.yaml
   425  endif
   426  
   427  bump-single-chart-ver.%: chart=$*
   428  bump-single-chart-ver.%:
   429  ifeq ($(GOOS), darwin)
   430  	sed -i '' "s/^version:.*/version: $(VERSION)/" deploy/$(chart)/Chart.yaml
   431  else
   432  	sed -i "s/^version:.*/version: $(VERSION)/" deploy/$(chart)/Chart.yaml
   433  endif
   434  
   435  .PHONY: bump-chart-ver
   436  bump-chart-ver: \
   437  	bump-single-chart-ver.helm \
   438  	bump-single-chart-appver.helm \
   439  	bump-single-chart-ver.apecloud-mysql \
   440  	bump-single-chart-ver.apecloud-mysql-cluster \
   441  	bump-single-chart-ver.clickhouse \
   442  	bump-single-chart-ver.clickhouse-cluster \
   443  	bump-single-chart-ver.kafka \
   444  	bump-single-chart-ver.kafka-cluster \
   445  	bump-single-chart-ver.mongodb \
   446  	bump-single-chart-ver.mongodb-cluster \
   447  	bump-single-chart-ver.nyancat \
   448  	bump-single-chart-appver.nyancat \
   449  	bump-single-chart-ver.postgresql \
   450  	bump-single-chart-ver.postgresql-cluster \
   451  	bump-single-chart-ver.redis \
   452  	bump-single-chart-ver.redis-cluster \
   453  	bump-single-chart-ver.milvus \
   454  	bump-single-chart-ver.milvus-cluster \
   455  	bump-single-chart-ver.qdrant \
   456  	bump-single-chart-ver.qdrant-cluster \
   457  	bump-single-chart-ver.weaviate \
   458  	bump-single-chart-ver.weaviate-cluster \
   459  	bump-single-chart-ver.chatgpt-retrieval-plugin \
   460  	bump-single-chart-ver.tdengine \
   461  	bump-single-chart-ver.tdengine-cluster
   462  bump-chart-ver: ## Bump helm chart version.
   463  
   464  .PHONY: helm-package
   465  helm-package: bump-chart-ver ## Do helm package.
   466  	$(HELM) package $(CHART_PATH)
   467  
   468  ##@ Build Dependencies
   469  
   470  ## Location to install dependencies to
   471  LOCALBIN ?= $(shell pwd)/bin
   472  $(LOCALBIN):
   473  	mkdir -p $(LOCALBIN)
   474  
   475  ## Tool Binaries
   476  KUSTOMIZE ?= $(LOCALBIN)/kustomize
   477  CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
   478  ENVTEST ?= $(LOCALBIN)/setup-envtest
   479  
   480  ## Tool Versions
   481  KUSTOMIZE_VERSION ?= v5.1.1
   482  CONTROLLER_TOOLS_VERSION ?= v0.12.1
   483  CUE_VERSION ?= v0.4.3
   484  
   485  KUSTOMIZE_INSTALL_SCRIPT ?= "$(GITHUB_PROXY)https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
   486  .PHONY: kustomize
   487  kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
   488  $(KUSTOMIZE): $(LOCALBIN)
   489  ifeq (, $(shell ls $(LOCALBIN)/kustomize 2>/dev/null))
   490  	curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
   491  endif
   492  
   493  .PHONY: controller-gen
   494  controller-gen: $(LOCALBIN) ## Download controller-gen locally if necessary.
   495  	@{ \
   496  	set -e ;\
   497  	if [ ! -f "$(CONTROLLER_GEN)" ] || [ "$$($(CONTROLLER_GEN) --version 2>&1 | awk '{print $$NF}')" != "$(CONTROLLER_TOOLS_VERSION)" ]; then \
   498          echo 'Installing controller-gen@$(CONTROLLER_TOOLS_VERSION)...' ;\
   499          GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) ;\
   500          echo 'Successfully installed' ;\
   501      fi \
   502  	}
   503  
   504  .PHONY: envtest
   505  envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
   506  $(ENVTEST): $(LOCALBIN)
   507  ifeq (, $(shell ls $(LOCALBIN)/setup-envtest 2>/dev/null))
   508  	GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
   509  endif
   510  
   511  .PHONY: install-docker-buildx
   512  install-docker-buildx: ## Create `docker buildx` builder.
   513  	@if ! docker buildx inspect $(BUILDX_BUILDER) > /dev/null; then \
   514  		echo "Buildx builder $(BUILDX_BUILDER) does not exist, creating..."; \
   515  		docker buildx create --name=$(BUILDX_BUILDER) --use --driver=docker-container --platform linux/amd64,linux/arm64; \
   516  	else \
   517  		echo "Buildx builder $(BUILDX_BUILDER) already exists"; \
   518  	fi
   519  
   520  .PHONY: golangci
   521  golangci: GOLANGCILINT_VERSION = v1.54.2
   522  golangci: ## Download golangci-lint locally if necessary.
   523  ifneq ($(shell which golangci-lint),)
   524  	@echo golangci-lint is already installed
   525  GOLANGCILINT=$(shell which golangci-lint)
   526  else ifeq (, $(shell which $(GOBIN)/golangci-lint))
   527  	@{ \
   528  	set -e ;\
   529  	echo 'installing golangci-lint-$(GOLANGCILINT_VERSION)' ;\
   530  	curl -sSfL $(GITHUB_PROXY)https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) $(GOLANGCILINT_VERSION) ;\
   531  	echo 'Successfully installed' ;\
   532  	}
   533  GOLANGCILINT=$(GOBIN)/golangci-lint
   534  else
   535  	@echo golangci-lint is already installed
   536  GOLANGCILINT=$(GOBIN)/golangci-lint
   537  endif
   538  
   539  .PHONY: staticchecktool
   540  staticchecktool: ## Download staticcheck locally if necessary.
   541  ifeq (, $(shell which staticcheck))
   542  	@{ \
   543  	set -e ;\
   544  	echo 'installing honnef.co/go/tools/cmd/staticcheck' ;\
   545  	go install honnef.co/go/tools/cmd/staticcheck@latest;\
   546  	}
   547  STATICCHECK=$(GOBIN)/staticcheck
   548  else
   549  STATICCHECK=$(shell which staticcheck)
   550  endif
   551  
   552  .PHONY: goimportstool
   553  goimportstool: ## Download goimports locally if necessary.
   554  ifeq (, $(shell which goimports))
   555  	@{ \
   556  	set -e ;\
   557  	go install golang.org/x/tools/cmd/goimports@latest ;\
   558  	}
   559  GOIMPORTS=$(GOBIN)/goimports
   560  else
   561  GOIMPORTS=$(shell which goimports)
   562  endif
   563  
   564  .PHONY: cuetool
   565  cuetool: ## Download cue locally if necessary.
   566  ifeq (, $(shell which cue))
   567  	@{ \
   568  	set -e ;\
   569  	go install cuelang.org/go/cmd/cue@$(CUE_VERSION) ;\
   570  	}
   571  CUE=$(GOBIN)/cue
   572  else
   573  CUE=$(shell which cue)
   574  endif
   575  
   576  .PHONY: helmtool
   577  helmtool: ## Download helm locally if necessary.
   578  ifeq (, $(shell which helm))
   579  	@{ \
   580  	set -e ;\
   581  	echo 'installing helm' ;\
   582  	curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash;\
   583  	echo 'Successfully installed' ;\
   584  	}
   585  HELM=$(GOBIN)/helm
   586  else
   587  HELM=$(shell which helm)
   588  endif
   589  
   590  .PHONY: kubectl
   591  kubectl: ## Download kubectl locally if necessary.
   592  ifeq (, $(shell which kubectl))
   593  	@{ \
   594  	set -e ;\
   595  	echo 'installing kubectl' ;\
   596  	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 ;\
   597  	echo 'Successfully installed' ;\
   598  	}
   599  endif
   600  KUBECTL=$(shell which kubectl)
   601  
   602  ##@ End-to-end (E2E) tests
   603  .PHONY: render-smoke-testdata-manifests
   604  render-smoke-testdata-manifests: ## Update E2E test dataset
   605  ifeq ($(TEST_TYPE), wesql)
   606  	$(HELM) dependency build deploy/apecloud-mysql-cluster --skip-refresh
   607  	$(HELM) template mysql-cluster deploy/apecloud-mysql-cluster > test/e2e/testdata/smoketest/wesql/00_wesqlcluster.yaml
   608  else ifeq ($(TEST_TYPE), postgresql)
   609  	$(HELM) dependency build deploy/postgresql-cluster --skip-refresh
   610  	$(HELM) template pg-cluster deploy/postgresql-cluster > test/e2e/testdata/smoketest/postgresql/00_postgresqlcluster.yaml
   611  else ifeq ($(TEST_TYPE), redis)
   612  	$(HELM) dependency build deploy/redis-cluster --skip-refresh
   613  	$(HELM) template redis-cluster deploy/redis-cluster > test/e2e/testdata/smoketest/redis/00_rediscluster.yaml
   614  else ifeq ($(TEST_TYPE), mongodb)
   615  	$(HELM) dependency build deploy/mongodb-cluster --skip-refresh
   616  	$(HELM) template mongodb-cluster deploy/mongodb-cluster > test/e2e/testdata/smoketest/mongodb/00_mongodbcluster.yaml
   617  else ifeq ($(TEST_TYPE), pulsar)
   618  	$(HELM) dependency build deploy/pulsar-cluster --skip-refresh
   619  	$(HELM) template pulsar-cluster -s templates/cluster.yaml deploy/pulsar-cluster > test/e2e/testdata/smoketest/pulsar/00_pulsarcluster.yaml
   620  else ifeq ($(TEST_TYPE), nebula)
   621  	$(HELM) dependency build deploy/nebula-cluster --skip-refresh
   622  	$(HELM) upgrade --install nebula deploy/nebula
   623  	$(HELM) template nebula-cluster deploy/nebula-cluster > test/e2e/testdata/smoketest/nebula/00_nebulacluster.yaml
   624  else ifeq ($(TEST_TYPE), greptimedb)
   625  	$(HELM) dependency build deploy/greptimedb-cluster --skip-refresh
   626  	$(HELM) upgrade --install greptimedb deploy/greptimedb
   627  	$(HELM) template greptimedb-cluster deploy/greptimedb-cluster > test/e2e/testdata/smoketest/greptimedb/00_greptimedbcluster.yaml
   628  else ifeq ($(TEST_TYPE), starrocks)
   629  	$(HELM) dependency build deploy/starrocks-cluster --skip-refresh
   630  	$(HELM) upgrade --install starrocks deploy/starrocks
   631  	$(HELM) template starrocks-cluster deploy/starrocks-cluster > test/e2e/testdata/smoketest/starrocks/00_starrocksbcluster.yaml
   632  else ifeq ($(TEST_TYPE), risingwave)
   633  	$(HELM) dependency build deploy/risingwave-cluster --skip-refresh
   634  	$(HELM) upgrade --install etcd deploy/etcd
   635  	$(HELM) upgrade --install risingwave deploy/risingwave
   636  	$(HELM) template risingwave-cluster deploy/risingwave-cluster > test/e2e/testdata/smoketest/risingwave/00_risingwavecluster.yaml
   637  else ifeq ($(TEST_TYPE), etcd)
   638  	$(HELM) dependency build deploy/etcd-cluster --skip-refresh
   639  	$(HELM) upgrade --install etcd deploy/etcd
   640  	$(HELM) template etcd-cluster -s templates/cluster.yaml deploy/etcd-cluster > test/e2e/testdata/smoketest/etcd/00_etcdcluster.yaml
   641  else ifeq ($(TEST_TYPE), oracle)
   642  	$(HELM) dependency build deploy/oracle-mysql-cluster --skip-refresh
   643  	$(HELM) upgrade --install oracle deploy/oracle-mysql
   644  	$(HELM) template oracle-cluster deploy/oracle-mysql-cluster > test/e2e/testdata/smoketest/oracle/00_oraclecluster.yaml
   645  else ifeq ($(TEST_TYPE), kafka)
   646  	$(HELM) dependency build deploy/kafka-cluster --skip-refresh
   647  	$(HELM) upgrade --install kafka deploy/kafka
   648  	$(HELM) template kafka-cluster deploy/kafka-cluster > test/e2e/testdata/smoketest/kafka/00_kafkacluster.yaml
   649  else ifeq ($(TEST_TYPE), foxlake)
   650  	$(HELM) dependency build deploy/foxlake-cluster --skip-refresh
   651  	$(HELM) upgrade --install foxlake deploy/foxlake
   652  	$(HELM) template foxlake-cluster deploy/foxlake-cluster > test/e2e/testdata/smoketest/foxlake/00_foxlakecluster.yaml
   653  else ifeq ($(TEST_TYPE), oceanbase)
   654  	$(HELM) dependency build deploy/oceanbase-cluster --skip-refresh
   655  	$(HELM) upgrade --install oceanbase deploy/oceanbase
   656  	$(HELM) template oceanbase-cluster deploy/oceanbase-cluster > test/e2e/testdata/smoketest/oceanbase/00_oceanbasecluster.yaml
   657  else ifeq ($(TEST_TYPE), official-postgresql)
   658  	$(HELM) dependency build deploy/official-postgresql-cluster --skip-refresh
   659  	$(HELM) upgrade --install official-postgresql deploy/official-postgresql
   660  	$(HELM) template official-pg deploy/official-postgresql-cluster > test/e2e/testdata/smoketest/official-postgresql/00_official_pgcluster.yaml
   661  else ifeq ($(TEST_TYPE), openldap)
   662  	$(HELM) dependency build deploy/openldap-cluster --skip-refresh
   663  	$(HELM) upgrade --install openldap deploy/openldap
   664  	$(HELM) template openldap-cluster deploy/openldap-cluster > test/e2e/testdata/smoketest/openldap/00_openldapcluster.yaml
   665  else ifeq ($(TEST_TYPE), orioledb)
   666  	$(HELM) dependency build deploy/orioledb-cluster --skip-refresh
   667  	$(HELM) upgrade --install orioledb deploy/orioledb
   668  	$(HELM) template oriole-cluster deploy/orioledb-cluster > test/e2e/testdata/smoketest/orioledb/00_orioledbcluster.yaml
   669  else ifeq ($(TEST_TYPE), weaviate)
   670  	$(HELM) dependency build deploy/weaviate-cluster --skip-refresh
   671  	$(HELM) upgrade --install weaviate deploy/weaviate
   672  	$(HELM) template weaviate-cluster deploy/weaviate-cluster > test/e2e/testdata/smoketest/weaviate/00_weaviatecluster.yaml
   673  else ifeq ($(TEST_TYPE), mysql-80)
   674  	$(HELM) dependency build deploy/mysql-cluster --skip-refresh
   675  	$(HELM) upgrade --install mysql deploy/mysql
   676  	$(HELM) template mysqlcluster deploy/mysql-cluster > test/e2e/testdata/smoketest/mysql-80/00_mysqlcluster.yaml
   677  else ifeq ($(TEST_TYPE), mysql-57)
   678  	$(HELM) dependency build deploy/mysql-cluster --skip-refresh
   679  	$(HELM) upgrade --install mysql deploy/mysql
   680  else ifeq ($(TEST_TYPE), polardbx)
   681  	$(HELM) dependency build deploy/polardbx-cluster --skip-refresh
   682  	$(HELM) upgrade --install polardbx deploy/polardbx
   683  	$(HELM) template pxc deploy/polardbx-cluster > test/e2e/testdata/smoketest/polardbx/00_polardbxcluster.yaml
   684  else ifeq ($(TEST_TYPE), opensearch)
   685  	$(HELM) dependency build deploy/opensearch-cluster --skip-refresh
   686  	$(HELM) upgrade --install opensearch deploy/opensearch
   687  	$(HELM) template opensearch-cluster deploy/opensearch-cluster > test/e2e/testdata/smoketest/opensearch/00_opensearchcluster.yaml
   688  else ifeq ($(TEST_TYPE), elasticsearch)
   689  	$(HELM) dependency build deploy/elasticsearch-cluster --skip-refresh
   690  	$(HELM) upgrade --install elasticsearch deploy/elasticsearch
   691  	$(HELM) template elasticsearch-cluster deploy/elasticsearch-cluster > test/e2e/testdata/smoketest/elasticsearch/00_elasticsearchcluster.yaml
   692  else ifeq ($(TEST_TYPE), llm)
   693  	$(HELM) dependency build deploy/llm-cluster --skip-refresh
   694  	$(HELM) upgrade --install llm deploy/llm
   695  	$(HELM) template llm-cluster deploy/llm-cluster > test/e2e/testdata/smoketest/llm/00_llmcluster.yaml
   696  else ifeq ($(TEST_TYPE), tdengine)
   697  	$(HELM) dependency build deploy/tdengine-cluster --skip-refresh
   698  	$(HELM) upgrade --install tdengine deploy/tdengine
   699  	$(HELM) template td-cluster deploy/tdengine-cluster > test/e2e/testdata/smoketest/tdengine/00_tdenginecluster.yaml
   700  else ifeq ($(TEST_TYPE), milvus)
   701  	$(HELM) dependency build deploy/milvus-cluster --skip-refresh
   702  	$(HELM) upgrade --install milvus deploy/milvus
   703  	$(HELM) template milvus-cluster deploy/milvus-cluster > test/e2e/testdata/smoketest/milvus/00_milvuscluster.yaml
   704  else ifeq ($(TEST_TYPE), clickhouse)
   705  	$(HELM) dependency build deploy/clickhouse-cluster --skip-refresh
   706  	$(HELM) upgrade --install clickhouse deploy/clickhouse
   707  	$(HELM) template test -s templates/cluster.yaml deploy/clickhouse-cluster > test/e2e/testdata/smoketest/clickhouse/00_clickhousecluster.yaml
   708  else ifeq ($(TEST_TYPE), zookeeper)
   709  	$(HELM) dependency build deploy/zookeeper-cluster --skip-refresh
   710  	$(HELM) upgrade --install zookeeper deploy/zookeeper
   711  	$(HELM) template zk-cluster deploy/zookeeper-cluster > test/e2e/testdata/smoketest/zookeeper/00_zookeepercluster.yaml
   712  else ifeq ($(TEST_TYPE), mariadb)
   713  	$(HELM) dependency build deploy/mariadb-cluster --skip-refresh
   714  	$(HELM) upgrade --install mariadb deploy/mariadb
   715  	$(HELM) template mariadb-cluster deploy/mariadb-cluster > test/e2e/testdata/smoketest/mariadb/00_mariadbcluster.yaml
   716  else
   717  	$(error "test type does not exist")
   718  endif
   719  
   720  .PHONY: test-e2e
   721  test-e2e: helm-package install-s3-csi-driver render-smoke-testdata-manifests ## Run E2E tests.
   722  	$(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) CONFIG_TYPE=$(CONFIG_TYPE) -C test/e2e run
   723  
   724  .PHONY: render-smoke-testdata-manifests-local
   725  render-smoke-testdata-manifests-local: ## Helm Install CD And CV
   726  ifeq ($(TEST_TYPE), wesql)
   727  	$(HELM) upgrade --install wesql deploy/apecloud-mysql
   728  else ifeq ($(TEST_TYPE), postgresql)
   729  	$(HELM) upgrade --install postgresql deploy/postgresql
   730  else ifeq ($(TEST_TYPE), mongodb)
   731  	$(HELM) upgrade --install  mongodb deploy/mongodb
   732  else ifeq ($(TEST_TYPE), redis)
   733  	$(HELM) upgrade --install redis deploy/redis
   734  else ifeq ($(TEST_TYPE), pulsar)
   735  	$(HELM) upgrade --install pulsar deploy/pulsar
   736  else ifeq ($(TEST_TYPE), nebula)
   737  	$(HELM) upgrade --install nebula deploy/nebula
   738  else ifeq ($(TEST_TYPE), greptimedb)
   739  	$(HELM) upgrade --install greptimedb deploy/greptimedb
   740  else ifeq ($(TEST_TYPE), starrocks)
   741  	$(HELM) upgrade --install starrocks deploy/starrocks
   742  else ifeq ($(TEST_TYPE), risingwave)
   743  	$(HELM) upgrade --install etcd deploy/etcd
   744  	$(HELM) upgrade --install risingwave deploy/risingwave
   745  else ifeq ($(TEST_TYPE), etcd)
   746  	$(HELM) upgrade --install etcd deploy/etcd
   747  else ifeq ($(TEST_TYPE), oracle)
   748  	$(HELM) upgrade --install oracle-mysql deploy/oracle-mysql
   749  else ifeq ($(TEST_TYPE), kafka)
   750  	$(HELM) upgrade --install kafka deploy/kafka
   751  else ifeq ($(TEST_TYPE), foxlake)
   752  	$(HELM) upgrade --install foxlake deploy/foxlake
   753  else ifeq ($(TEST_TYPE), oceanbase)
   754  	$(HELM) upgrade --install oceanbase deploy/oceanbase
   755  else ifeq ($(TEST_TYPE), oceanbase)
   756  	$(HELM) upgrade --install official-postgresql deploy/official-postgresql
   757  else ifeq ($(TEST_TYPE), openldap)
   758  	$(HELM) upgrade --install openldap deploy/openldap
   759  else ifeq ($(TEST_TYPE), weaviate)
   760  	$(HELM) upgrade --install weaviate deploy/weaviate
   761  else ifeq ($(TEST_TYPE), mysql-80)
   762  	$(HELM) upgrade --install mysql deploy/mysql
   763  else ifeq ($(TEST_TYPE), mysql-57)
   764  	$(HELM) upgrade --install mysql deploy/mysql
   765  else ifeq ($(TEST_TYPE), polardbx)
   766  	$(HELM) upgrade --install polardbx deploy/polardbx
   767  else ifeq ($(TEST_TYPE), opensearch)
   768  	$(HELM) upgrade --install opensearch deploy/opensearch
   769  else ifeq ($(TEST_TYPE), elasticsearch)
   770  	$(HELM) upgrade --install elasticsearch deploy/elasticsearch
   771  else ifeq ($(TEST_TYPE), llm)
   772  	$(HELM) upgrade --install llm deploy/llm
   773  else ifeq ($(TEST_TYPE), milvus)
   774  	$(HELM) upgrade --install milvus deploy/milvus
   775  else ifeq ($(TEST_TYPE), clickhouse)
   776  	$(HELM) upgrade --install clickhouse deploy/clickhouse
   777  else ifeq ($(TEST_TYPE), zookeeper)
   778  	$(HELM) upgrade --install zookeeper deploy/zookeeper
   779  else ifeq ($(TEST_TYPE), mariadb)
   780  	$(HELM) upgrade --install mariadb deploy/mariadb
   781  else
   782  	$(error "test type does not exist")
   783  endif
   784  
   785  .PHONY: test-e2e-local
   786  test-e2e-local: generate-cluster-role install-s3-csi-driver render-smoke-testdata-manifests-local render-smoke-testdata-manifests ## Run E2E tests on local.
   787  	$(MAKE) -e TEST_TYPE=$(TEST_TYPE) -C test/e2e run
   788  
   789  .PHONY: generate-cluster-role
   790  generate-cluster-role:
   791  	$(HELM) template -s templates/rbac/cluster_pod_required_role.yaml deploy/helm | kubectl apply -f -
   792  
   793  .PHONY: install-s3-csi-driver
   794  install-s3-csi-driver:
   795  	$(HELM) upgrade --install csi-s3 deploy/csi-s3
   796  
   797  # NOTE: include must be placed at the end
   798  include docker/docker.mk
   799  include cmd/cmd.mk