-
Notifications
You must be signed in to change notification settings - Fork 147
/
Makefile
140 lines (113 loc) · 6.94 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
NAME ?= percona-server-mongodb-operator
IMAGE_TAG_OWNER ?= perconalab
SED := $(shell which gsed || which sed)
IMAGE_TAG_BASE ?= $(IMAGE_TAG_OWNER)/$(NAME)
VERSION ?= $(shell git rev-parse --abbrev-ref HEAD | $(SED) -e 's^/^-^g; s^[.]^-^g;' | tr '[:upper:]' '[:lower:]')
IMAGE ?= $(IMAGE_TAG_BASE):$(VERSION)
DEPLOYDIR = ./deploy
ENVTEST_K8S_VERSION = 1.31
all: build
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)
generate: controller-gen ## Generate CRDs and RBAC files
$(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.
$(CONTROLLER_GEN) object paths="./..." ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(DEPLOYDIR)/crd.yaml: kustomize generate
$(KUSTOMIZE) build config/crd/ > $(DEPLOYDIR)/crd.yaml
cp $(DEPLOYDIR)/crd.yaml ./e2e-tests/version-service/conf/crd.yaml
.PHONY: $(DEPLOYDIR)/operator.yaml
$(DEPLOYDIR)/operator.yaml:
$(SED) -i "/^ containers:/,/^ image:/{s#image: .*#image: $(IMAGE_TAG_BASE):$(VERSION)#}" deploy/operator.yaml
.PHONY: $(DEPLOYDIR)/cw-operator.yaml
$(DEPLOYDIR)/cw-operator.yaml:
$(SED) -i "/^ containers:/,/^ image:/{s#image: .*#image: $(IMAGE_TAG_BASE):$(VERSION)#}" deploy/cw-operator.yaml
$(DEPLOYDIR)/bundle.yaml: $(DEPLOYDIR)/crd.yaml $(DEPLOYDIR)/rbac.yaml $(DEPLOYDIR)/operator.yaml ## Generate deploy/bundle.yaml
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
$(DEPLOYDIR)/cw-bundle.yaml: $(DEPLOYDIR)/crd.yaml $(DEPLOYDIR)/cw-rbac.yaml $(DEPLOYDIR)/cw-operator.yaml ## Generate deploy/cw-bundle.yaml
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
manifests: $(DEPLOYDIR)/crd.yaml $(DEPLOYDIR)/bundle.yaml $(DEPLOYDIR)/cw-bundle.yaml ## Put generated manifests to deploy directory
e2e-test:
IMAGE=$(IMAGE) ./e2e-tests/$(TEST)/run
##@ Build
.PHONY: build
build: generate ## Build docker image for operator
VERSION=$(VERSION) IMAGE=$(IMAGE) ./e2e-tests/build
##@ Deployment
install: manifests ## Install CRDs, rbac
kubectl apply --server-side -f $(DEPLOYDIR)/crd.yaml
kubectl apply -f $(DEPLOYDIR)/rbac.yaml
uninstall: manifests ## Uninstall CRDs, rbac
kubectl delete -f $(DEPLOYDIR)/crd.yaml
kubectl delete -f $(DEPLOYDIR)/rbac.yaml
.PHONY: deploy
deploy: ## Deploy operator
yq eval '(.spec.template.spec.containers[] | select(.name=="percona-server-mongodb-operator")).image = "$(IMAGE)"' $(DEPLOYDIR)/operator.yaml \
| yq eval '(.spec.template.spec.containers[] | select(.name=="percona-server-mongodb-operator").env[] | select(.name=="LOG_LEVEL")).value="DEBUG"' - \
| kubectl apply -f -
undeploy: ## Undeploy operator
kubectl delete -f $(DEPLOYDIR)/operator.yaml
test: envtest ## Run tests.
DISABLE_TELEMETRY=true KUBEBUILDER_ASSETS="$(shell $(ENVTEST) --arch=amd64 use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
ENVTEST = $(shell pwd)/bin/setup-envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
SWAGGER = $(shell pwd)/bin/swagger
swagger: ## Download swagger locally if necessary.
$(call go-get-tool,$(SWAGGER),github.com/go-swagger/go-swagger/cmd/swagger@latest)
# Prepare release
CERT_MANAGER_VER := $(shell grep -Eo "cert-manager v.*" go.mod|grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")
release: manifests
$(SED) -i "/CERT_MANAGER_VER/s/CERT_MANAGER_VER=\".*/CERT_MANAGER_VER=\"$(CERT_MANAGER_VER)\"/" e2e-tests/functions
$(SED) -i "/Version = \"/s/Version = \".*/Version = \"$(VERSION)\"/" version/version.go
$(SED) -i \
-e "s/crVersion: .*/crVersion: $(VERSION)/" \
-e "/^spec:/,/^ image:/{s#image: .*#image: percona/percona-server-mongodb:@@SET_TAG@@#}" deploy/cr-minimal.yaml
$(SED) -i \
-e "s/crVersion: .*/crVersion: $(VERSION)/" \
-e "/^spec:/,/^ image:/{s#image: .*#image: percona/percona-server-mongodb:@@SET_TAG@@#}" \
-e "/^ backup:/,/^ image:/{s#image: .*#image: percona/percona-backup-mongodb:@@SET_TAG@@#}" \
-e "s#initImage: .*#initImage: percona/percona-server-mongodb-operator:$(VERSION)#g" \
-e "/^ pmm:/,/^ image:/{s#image: .*#image: percona/pmm-client:@@SET_TAG@@#}" deploy/cr.yaml
# Prepare main branch after release
MAJOR_VER := $(shell grep -oE "crVersion: .*" deploy/cr.yaml|grep -oE "[0-9]+\.[0-9]+\.[0-9]+"|cut -d'.' -f1)
MINOR_VER := $(shell grep -oE "crVersion: .*" deploy/cr.yaml|grep -oE "[0-9]+\.[0-9]+\.[0-9]+"|cut -d'.' -f2)
NEXT_VER ?= $(MAJOR_VER).$$(($(MINOR_VER) + 1)).0
after-release: manifests
$(SED) -i "/Version = \"/s/Version = \".*/Version = \"$(NEXT_VER)\"/" version/version.go
$(SED) -i \
-e "s/crVersion: .*/crVersion: $(NEXT_VER)/" \
-e "/^spec:/,/^ image:/{s#image: .*#image: perconalab/percona-server-mongodb-operator:main-mongod7.0#}" deploy/cr-minimal.yaml
$(SED) -i \
-e "s/crVersion: .*/crVersion: $(NEXT_VER)/" \
-e "/^spec:/,/^ image:/{s#image: .*#image: perconalab/percona-server-mongodb-operator:main-mongod7.0#}" \
-e "/^ backup:/,/^ image:/{s#image: .*#image: perconalab/percona-server-mongodb-operator:main-backup#}" \
-e "s#initImage: .*#initImage: perconalab/percona-server-mongodb-operator:main#g" \
-e "/^ pmm:/,/^ image:/{s#image: .*#image: perconalab/pmm-client:dev-latest#}" deploy/cr.yaml
version-service-client: swagger
curl https://raw.githubusercontent.com/Percona-Lab/percona-version-service/$(VS_BRANCH)/api/version.swagger.yaml \
--output ./version.swagger.yaml
rm -rf ./versionserviceclient
swagger generate client \
-f ./version.swagger.yaml \
-c ./versionserviceclient/ \
-m ./versionserviceclient/models
rm ./version.swagger.yaml