forked from rabbitmq/cluster-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
209 lines (165 loc) · 9.15 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
SHELL := bash
platform := $(shell uname | tr A-Z a-z)
.DEFAULT_GOAL = help
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
ENVTEST_K8S_VERSION = 1.20.2
ARCHITECTURE = amd64
LOCAL_TESTBIN = $(CURDIR)/testbin
# "Control plane binaries (etcd and kube-apiserver) are loaded by default from /usr/local/kubebuilder/bin.
# This can be overridden by setting the KUBEBUILDER_ASSETS environment variable"
# https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/envtest
export KUBEBUILDER_ASSETS = $(LOCAL_TESTBIN)/k8s/$(ENVTEST_K8S_VERSION)-$(platform)-$(ARCHITECTURE)
$(KUBEBUILDER_ASSETS):
setup-envtest --os $(platform) --arch $(ARCHITECTURE) --bin-dir $(LOCAL_TESTBIN) use $(ENVTEST_K8S_VERSION)
.PHONY: unit-tests
unit-tests: install-tools $(KUBEBUILDER_ASSETS) generate fmt vet manifests ## Run unit tests
ginkgo -r --randomizeAllSpecs api/ internal/
.PHONY: integration-tests
integration-tests: install-tools $(KUBEBUILDER_ASSETS) generate fmt vet manifests ## Run integration tests
ginkgo -r controllers/
CRD_OPTIONS ?= "crd:trivialVersions=true, preserveUnknownFields=false"
manifests: install-tools ## Generate manifests e.g. CRD, RBAC etc.
controller-gen $(CRD_OPTIONS) rbac:roleName=operator-role paths="./api/...;./controllers/..." output:crd:artifacts:config=config/crd/bases
./hack/remove-override-descriptions.sh
./hack/add-notice-to-yaml.sh config/rbac/role.yaml
./hack/add-notice-to-yaml.sh config/crd/bases/rabbitmq.com_rabbitmqclusters.yaml
api-reference: install-tools ## Generate API reference documentation
crd-ref-docs \
--source-path ./api/v1beta1 \
--config ./docs/api/autogen/config.yaml \
--templates-dir ./docs/api/autogen/templates \
--output-path ./docs/api/rabbitmq.com.ref.asciidoc \
--max-depth 30
# Run go fmt against code
fmt:
go fmt ./...
# Run go vet against code
vet:
go vet ./...
# Generate code & docs
generate: install-tools api-reference
controller-gen object:headerFile=./hack/NOTICE.go.txt paths=./api/...
controller-gen object:headerFile=./hack/NOTICE.go.txt paths=./internal/status/...
# Build manager binary
manager: generate fmt vet
go mod tidy
go build -o bin/manager main.go
deploy-manager: ## Deploy manager
kustomize build config/crd | kubectl apply -f -
kustomize build config/default/base | kubectl apply -f -
deploy-manager-dev:
kustomize build config/crd | kubectl apply -f -
kustomize build config/default/overlays/dev | sed 's@((operator_docker_image))@"$(DOCKER_REGISTRY_SERVER)/$(OPERATOR_IMAGE):$(GIT_COMMIT)"@' | kubectl apply -f -
deploy-sample: ## Deploy RabbitmqCluster defined in config/sample/base
kustomize build config/samples/base | kubectl apply -f -
destroy: ## Cleanup all controller artefacts
kustomize build config/crd/ | kubectl delete --ignore-not-found=true -f -
kustomize build config/default/base/ | kubectl delete --ignore-not-found=true -f -
kustomize build config/rbac/ | kubectl delete --ignore-not-found=true -f -
kustomize build config/namespace/base/ | kubectl delete --ignore-not-found=true -f -
run: generate manifests fmt vet install deploy-namespace-rbac just-run ## Run operator binary locally against the configured Kubernetes cluster in ~/.kube/config
just-run: ## Just runs 'go run main.go' without regenerating any manifests or deploying RBACs
KUBE_CONFIG=${HOME}/.kube/config OPERATOR_NAMESPACE=rabbitmq-system go run ./main.go
delve: generate install deploy-namespace-rbac just-delve ## Deploys CRD, Namespace, RBACs and starts Delve debugger
just-delve: install-tools ## Just starts Delve debugger
KUBE_CONFIG=${HOME}/.kube/config OPERATOR_NAMESPACE=rabbitmq-system dlv debug
# Install CRDs into a cluster
install: manifests
kubectl apply -f config/crd/bases
deploy-namespace-rbac:
kustomize build config/namespace/base | kubectl apply -f -
kustomize build config/rbac | kubectl apply -f -
deploy: manifests deploy-namespace-rbac deploy-manager ## Deploy operator in the configured Kubernetes cluster in ~/.kube/config
deploy-dev: check-env-docker-credentials docker-build-dev manifests deploy-namespace-rbac docker-registry-secret deploy-manager-dev ## Deploy operator in the configured Kubernetes cluster in ~/.kube/config, with local changes
deploy-kind: check-env-docker-repo git-commit-sha manifests deploy-namespace-rbac ## Load operator image and deploy operator into current KinD cluster
docker build --build-arg=GIT_COMMIT=$(GIT_COMMIT) -t $(DOCKER_REGISTRY_SERVER)/$(OPERATOR_IMAGE):$(GIT_COMMIT) .
kind load docker-image $(DOCKER_REGISTRY_SERVER)/$(OPERATOR_IMAGE):$(GIT_COMMIT)
kustomize build config/crd | kubectl apply -f -
kustomize build config/default/overlays/kind | sed 's@((operator_docker_image))@"$(DOCKER_REGISTRY_SERVER)/$(OPERATOR_IMAGE):$(GIT_COMMIT)"@' | kubectl apply -f -
# Builds a single-file installation manifest to deploy the Operator
generate-installation-manifest:
mkdir -p releases
kustomize build config/installation/ > releases/rabbitmq-cluster-operator.yaml
# Build the docker image
docker-build: check-env-docker-repo git-commit-sha
docker build --build-arg=GIT_COMMIT=$(GIT_COMMIT) -t $(DOCKER_REGISTRY_SERVER)/$(OPERATOR_IMAGE):latest .
# Push the docker image
docker-push: check-env-docker-repo
docker push $(DOCKER_REGISTRY_SERVER)/$(OPERATOR_IMAGE):latest
git-commit-sha:
ifeq ("", git diff --stat)
GIT_COMMIT=$(shell git rev-parse --short HEAD)
else
GIT_COMMIT=$(shell git rev-parse --short HEAD)-
endif
docker-build-dev: check-env-docker-repo git-commit-sha
docker build --build-arg=GIT_COMMIT=$(GIT_COMMIT) -t $(DOCKER_REGISTRY_SERVER)/$(OPERATOR_IMAGE):$(GIT_COMMIT) .
docker push $(DOCKER_REGISTRY_SERVER)/$(OPERATOR_IMAGE):$(GIT_COMMIT)
CERT_MANAGER_VERSION ?= 1.2.0
CERT_MANAGER_HELM_RELEASE := cert-manager
CERT_MANAGER_NAMESPACE := cert-manager
cert-manager:
@echo "Installing Cert Manager"
helm repo add jetstack https://charts.jetstack.io
helm upgrade $(CERT_MANAGER_HELM_RELEASE) jetstack/$(@) \
--install \
--namespace $(CERT_MANAGER_NAMESPACE) --create-namespace \
--version $(CERT_MANAGER_VERSION) \
--set installCRDs=true \
--wait
cert-manager-rm:
@echo "Deleting Cert Manager"
helm uninstall $(CERT_MANAGER_HELM_RELEASE) \
--namespace $(CERT_MANAGER_NAMESPACE)
kubectl delete namespace $(CERT_MANAGER_NAMESPACE)
helm repo remove jetstack
kind-prepare: ## Prepare KIND to support LoadBalancer services
# Note that created LoadBalancer services will have an unreachable external IP
@kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/namespace.yaml
@kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/metallb.yaml
@kubectl apply -f config/metallb/config.yaml
@kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(shell openssl rand -base64 128)"
kind-unprepare: ## Remove KIND support for LoadBalancer services
# remove MetalLB
@kubectl delete -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/metallb.yaml
@kubectl delete -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/namespace.yaml
system-tests: install-tools ## Run end-to-end tests against Kubernetes cluster defined in ~/.kube/config
NAMESPACE="rabbitmq-system" ginkgo -nodes=3 -randomizeAllSpecs -r system_tests/
chart-tests: ## Run Helm chart tests
echo "running charts tests"
cd charts/rabbitmq && ./test.sh
kubectl-plugin-tests: ## Run kubectl-rabbitmq tests
echo "running kubectl plugin tests"
./bin/kubectl-rabbitmq.bats
tests: unit-tests integration-tests system-tests chart-tests kubectl-plugin-tests
docker-registry-secret: check-env-docker-credentials operator-namespace
echo "creating registry secret and patching default service account"
@kubectl -n $(K8S_OPERATOR_NAMESPACE) create secret docker-registry $(DOCKER_REGISTRY_SECRET) --docker-server='$(DOCKER_REGISTRY_SERVER)' --docker-username="$$DOCKER_REGISTRY_USERNAME" --docker-password="$$DOCKER_REGISTRY_PASSWORD" || true
@kubectl -n $(K8S_OPERATOR_NAMESPACE) patch serviceaccount rabbitmq-cluster-operator -p '{"imagePullSecrets": [{"name": "$(DOCKER_REGISTRY_SECRET)"}]}'
install-tools:
go mod download
grep _ tools/tools.go | awk -F '"' '{print $$2}' | xargs -t go install
operator-namespace:
ifeq (, $(K8S_OPERATOR_NAMESPACE))
K8S_OPERATOR_NAMESPACE=rabbitmq-system
endif
check-env-docker-repo: check-env-registry-server
ifndef OPERATOR_IMAGE
$(error OPERATOR_IMAGE is undefined: path to the Operator image within the registry specified in DOCKER_REGISTRY_SERVER (e.g. rabbitmq/cluster-operator - without leading slash))
endif
check-env-docker-credentials: check-env-registry-server
ifndef DOCKER_REGISTRY_USERNAME
$(error DOCKER_REGISTRY_USERNAME is undefined: Username for accessing the docker registry)
endif
ifndef DOCKER_REGISTRY_PASSWORD
$(error DOCKER_REGISTRY_PASSWORD is undefined: Password for accessing the docker registry)
endif
ifndef DOCKER_REGISTRY_SECRET
$(error DOCKER_REGISTRY_SECRET is undefined: Name of Kubernetes secret in which to store the Docker registry username and password)
endif
check-env-registry-server:
ifndef DOCKER_REGISTRY_SERVER
$(error DOCKER_REGISTRY_SERVER is undefined: URL of docker registry containing the Operator image (e.g. registry.my-company.com))
endif