github.com/percona/percona-xtradb-cluster-operator@v1.14.0/Makefile (about) 1 NAME ?= percona-xtradb-cluster-operator 2 IMAGE_TAG_OWNER ?= perconalab 3 IMAGE_TAG_BASE ?= $(IMAGE_TAG_OWNER)/$(NAME) 4 VERSION ?= $(shell git rev-parse --abbrev-ref HEAD | sed -e 's^/^-^g; s^[.]^-^g;' | tr '[:upper:]' '[:lower:]') 5 IMAGE ?= $(IMAGE_TAG_BASE):$(VERSION) 6 DEPLOYDIR = ./deploy 7 8 # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. 9 ENVTEST_K8S_VERSION = 1.23 10 11 all: build 12 13 help: ## Display this help. 14 @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) 15 16 generate: controller-gen ## Generate CRDs and RBAC files 17 $(CONTROLLER_GEN) crd:maxDescLen=0,allowDangerousTypes=true rbac:roleName=$(NAME) webhook paths="./..." output:crd:artifacts:config=config/crd/bases ## Generate WebhookConfiguration, Role and CustomResourceDefinition objects. 18 $(CONTROLLER_GEN) object paths="./..." ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. 19 20 $(DEPLOYDIR)/crd.yaml: kustomize generate 21 $(KUSTOMIZE) build config/crd/ > $(DEPLOYDIR)/crd.yaml 22 23 $(DEPLOYDIR)/bundle.yaml: $(DEPLOYDIR)/crd.yaml $(DEPLOYDIR)/rbac.yaml $(DEPLOYDIR)/operator.yaml ## Generate deploy/bundle.yaml 24 cat $(DEPLOYDIR)/crd.yaml > $(DEPLOYDIR)/bundle.yaml; echo "---" >> $(DEPLOYDIR)/bundle.yaml; cat $(DEPLOYDIR)/rbac.yaml >> $(DEPLOYDIR)/bundle.yaml; echo "---" >> $(DEPLOYDIR)/bundle.yaml; cat $(DEPLOYDIR)/operator.yaml >> $(DEPLOYDIR)/bundle.yaml 25 26 $(DEPLOYDIR)/cw-bundle.yaml: $(DEPLOYDIR)/crd.yaml $(DEPLOYDIR)/cw-rbac.yaml $(DEPLOYDIR)/cw-operator.yaml ## Generate deploy/cw-bundle.yaml 27 cat $(DEPLOYDIR)/crd.yaml > $(DEPLOYDIR)/cw-bundle.yaml; echo "---" >> $(DEPLOYDIR)/cw-bundle.yaml; cat $(DEPLOYDIR)/cw-rbac.yaml >> $(DEPLOYDIR)/cw-bundle.yaml; echo "---" >> $(DEPLOYDIR)/cw-bundle.yaml; cat $(DEPLOYDIR)/cw-operator.yaml >> $(DEPLOYDIR)/cw-bundle.yaml 28 29 manifests: $(DEPLOYDIR)/crd.yaml $(DEPLOYDIR)/bundle.yaml $(DEPLOYDIR)/cw-bundle.yaml ## Put generated manifests to deploy directory 30 31 fmt: ## Run go fmt against code. 32 go fmt ./... 33 34 vet: ## Run go vet against code. 35 go vet ./... 36 37 test: manifests generate fmt vet envtest ## Run tests. 38 DISABLE_TELEMETRY=true KUBEBUILDER_ASSETS="$(shell $(ENVTEST) --arch=amd64 use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out 39 40 ##@ Build 41 42 .PHONY: build 43 build: generate ## Build docker image for operator 44 VERSION=$(VERSION) IMAGE=$(IMAGE) ./e2e-tests/build 45 46 ##@ Deployment 47 48 install: manifests ## Install CRDs, rbac 49 kubectl apply --server-side -f $(DEPLOYDIR)/crd.yaml 50 kubectl apply -f $(DEPLOYDIR)/rbac.yaml 51 52 uninstall: manifests ## Uninstall CRDs, rbac 53 kubectl delete -f $(DEPLOYDIR)/crd.yaml 54 kubectl delete -f $(DEPLOYDIR)/rbac.yaml 55 56 .PHONY: deploy 57 deploy: ## Deploy operator 58 yq eval '(.spec.template.spec.containers[] | select(.name=="$(NAME)") | .image) = "$(IMAGE)"' $(DEPLOYDIR)/operator.yaml \ 59 | yq eval '(.spec.template.spec.containers[] | select(.name=="$(NAME)") | .env[] | select(.name=="DISABLE_TELEMETRY") | .value) = "true"' - \ 60 | yq eval '(.spec.template.spec.containers[] | select(.name=="$(NAME)") | .env[] | select(.name=="LOG_LEVEL") | .value) = "DEBUG"' - \ 61 | kubectl apply -f - 62 63 undeploy: ## Undeploy operator 64 kubectl delete -f $(DEPLOYDIR)/operator.yaml 65 66 # go-get-tool will 'go get' any package $2 and install it to $1. 67 PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) 68 define go-get-tool 69 @[ -f $(1) ] || { \ 70 set -e ;\ 71 TMP_DIR=$$(mktemp -d) ;\ 72 cd $$TMP_DIR ;\ 73 go mod init tmp ;\ 74 echo "Downloading $(2)" ;\ 75 GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\ 76 rm -rf $$TMP_DIR ;\ 77 } 78 endef 79 80 CONTROLLER_GEN = $(shell pwd)/bin/controller-gen 81 controller-gen: ## Download controller-gen locally if necessary. 82 $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0) 83 84 KUSTOMIZE = $(shell pwd)/bin/kustomize 85 kustomize: ## Download kustomize locally if necessary. 86 $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.3) 87 88 ENVTEST = $(shell pwd)/bin/setup-envtest 89 envtest: ## Download envtest-setup locally if necessary. 90 $(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) 91