This repository is currently being migrated. It's locked while the migration is in progress.
forked from improbable-eng/etcd-cluster-operator
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
316 lines (252 loc) · 11.9 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
MAKEFLAGS += --warn-undefined-variables
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
.SUFFIXES:
.DEFAULT_GOAL := help
# The version which will be reported by the --version argument of each binary
# and which will be used as the Docker image tag
#VERSION ?= $(shell git describe --tags)
VERSION ?= $(shell ./scripts/branch.sh)
# Set ARGS to specify extra go test arguments
ARGS ?=
# BIN is the directory where build tools such controller-gen and kustomize will
# be installed.
# BIN is inherited and exported so that it gets passed down to the make process
# that is launched by verify.sh
# This ensures that test tools get installed in the original directory rather
# than in the temporary copy.
export BIN ?= ${CURDIR}/bin
# Make sure BIN is on the PATH
export PATH := $(BIN):$(PATH)
GO_VERSION ?= 1.18
# Look for a `go1.18` on the path but fall back to `go`.
# Allows me to use `go get golang.org/dl/go1.18` without having to replace my OS
# provided golang package.
GO := $(or $(shell which go${GO_VERSION}),$(shell which go))
# Docker image configuration
# Docker images are published to https://quay.io/repository/storageos/etcd-cluster-operator
DOCKER_TAG ?= ${VERSION}
DOCKER_REPO ?= storageos
DOCKER_IMAGES ?= controller proxy backup-agent restore-agent
DOCKER_IMAGE_NAME_PREFIX ?= etcd-cluster-operator-
# The Docker image for the controller-manager which will be deployed to the cluster in tests
DOCKER_IMAGE_CONTROLLER = ${DOCKER_REPO}/${DOCKER_IMAGE_NAME_PREFIX}controller:${DOCKER_TAG}
DOCKER_IMAGE_PROXY = ${DOCKER_REPO}/${DOCKER_IMAGE_NAME_PREFIX}proxy:${DOCKER_TAG}
DOCKER_IMAGE_RESTORE_AGENT = ${DOCKER_REPO}/${DOCKER_IMAGE_NAME_PREFIX}restore-agent:${DOCKER_TAG}
DOCKER_IMAGE_BACKUP_AGENT = ${DOCKER_REPO}/${DOCKER_IMAGE_NAME_PREFIX}backup-agent:${DOCKER_TAG}
DOCKER_IMAGE_NAME = ${DOCKER_REPO}/${DOCKER_IMAGE_NAME_PREFIX}${COMPONENT}:${DOCKER_TAG}
DOCKER_IMAGE_MANIFESTS = ${DOCKER_REPO}/${DOCKER_IMAGE_NAME_PREFIX}manifests:${DOCKER_TAG}
OS := $(shell ${GO} env GOOS)
ARCH := $(shell ${GO} env GOARCH)
# Generate kuttl e2e tests for the following storageos/kind-node versions
# # TEST_KIND_NODES is not intended to be updated manually.
# # Please run 'LATEST_KIND_NODE=<latest-kind-node> make update-kind-nodes'.
TEST_KIND_NODES ?= 1.22.3,1.23.0,1.24.2,1.25.0,1.26.0
# Kind
KIND_VERSION := 0.15.0
KIND := ${BIN}/kind-${KIND_VERSION}
K8S_CLUSTER_NAME := etcd-e2e
# controller-tools
CONTROLLER_GEN_VERSION := 0.9.0
CONTROLLER_GEN := ${BIN}/controller-gen-${CONTROLLER_GEN_VERSION}
# Kustomize
KUSTOMIZE_VERSION := 3.5.4
KUSTOMIZE_DOWNLOAD_URL := https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_${OS}_${ARCH}.tar.gz
KUSTOMIZE_LOCAL_ARCHIVE := /tmp/kustomize_v${KUSTOMIZE_VERSION}_${OS}_${ARCH}.tar.gz
KUSTOMIZE := ${BIN}/kustomize-3.5.4
KUSTOMIZE_DIRECTORY_TO_EDIT := "config/test/e2e"
KUSTOMIZE_DIRECTORY_TO_DEPLOY := "config/test/e2e"
# Release files
RELEASE_NOTES := docs/release-notes/${VERSION}.md
RELEASE_MANIFEST := "release-${VERSION}.yaml"
# Prevent fancy TTY output from tools like kind
export TERM=dumb
# Stop go build tools from silently modifying go.mod and go.sum
export GOFLAGS := -mod=readonly
# from https://suva.sh/posts/well-documented-makefiles/
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
.PHONY: all
all: verify test manager
.PHONY: verify
verify: ## Run all static checks
verify: verify-gomod verify-manifests verify-generate verify-protobuf verify-fmt vet
.PHONY: test
test: ## Run unit tests
test: kubebuilder
KUBEBUILDER_ASSETS="$(shell pwd)/bin/kubebuilder/bin" ${GO} test ./... -coverprofile cover.out $(ARGS)
.PHONY: e2e
e2e: docker-build kind-cluster kind-load
e2e: ## Run kuttl e2e tests
kubectl-kuttl test --config e2e/kuttl/etcd-cluster-operator-deployment-1.26.yaml
update-kind-nodes:
ifndef LATEST_KIND_NODE
$(error LATEST_KIND_NODE is undefined)
endif
LATEST_KIND_NODE=$(LATEST_KIND_NODE) ./hack/update-kind-nodes.sh
generate-tests: ## Generate kuttl e2e tests
TEST_KIND_NODES=$(TEST_KIND_NODES) REPO=etcd-cluster-operator ./hack/generate-tests.sh
.PHONY: manager
manager: ## Build manager binary
${GO} build -o bin/manager -ldflags="-X 'github.com/improbable-eng/etcd-cluster-operator/version.Version=${VERSION}'" main.go
# Use 'DISABLE_WEBHOOKS=1` to run the controller-manager without the
# webhook server, and to skip the loading of webhook TLS keys, since these are
# difficult to set up locally.
.PHONY: run
run: ## Run against the configured Kubernetes cluster in ~/.kube/config
DISABLE_WEBHOOKS=1 ${GO} run ./main.go
# ===========================================================
# Deploy: Set image tags in manifests and deploy the operator
# ===========================================================
.PHONY: install
install: ## Install CRDs into a cluster
install: ${KUSTOMIZE}
${KUSTOMIZE} build config/bases/crd | kubectl apply -f -
.PHONY: deploy-minio
deploy-minio: ## Deploy MinIO in the cluster for backups and restores
deploy-minio:
kubectl apply -k config/test/e2e/minio
# We can't wait on the `minio` service: https://github.com/kubernetes/kubernetes/issues/80828
# Nor can we wait on a statefulset: https://github.com/kubernetes/kubernetes/issues/79606
count=0; until [[ $$(kubectl get -n minio statefulset minio -o jsonpath="{.status.readyReplicas}") == 1 ]]; do [[ $${count} -le 60 ]] || exit 1; ((count+=1)); sleep 1; done
.PHONY: deploy-cert-manager
deploy-cert-manager: ## Deploy cert-manager in the configured Kubernetes cluster in ~/.kube/config
kubectl apply --validate=false --filename=https://github.com/jetstack/cert-manager/releases/download/v0.11.0/cert-manager.yaml
kubectl wait --for=condition=Available --timeout=300s apiservice v1beta1.webhook.cert-manager.io
.PHONY: deploy-controller
deploy-controller: ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy-controller: kustomize-edit-set-image
${KUSTOMIZE} build ${KUSTOMIZE_DIRECTORY_TO_DEPLOY} | kubectl apply -f -
kubectl --namespace eco-system wait --for=condition=Available --timeout=60s deploy eco-controller-manager
kubectl --namespace eco-system wait --for=condition=Available --timeout=60s deploy eco-proxy
.PHONY: deploy
deploy: ## Deploy the operator, including dependencies
deploy: deploy-controller
.PHONY: deploy-e2e
deploy-e2e: ## Deploy the operator, including all dependencies needed to run E2E tests
deploy-e2e: deploy-cert-manager deploy-minio deploy
kustomize-edit-set-image-%: COMPONENT=$*
kustomize-edit-set-image-%: ${KUSTOMIZE} FORCE
cd ${KUSTOMIZE_DIRECTORY_TO_EDIT} && ${KUSTOMIZE} edit set image ${COMPONENT}=${DOCKER_IMAGE_NAME}
FORCE:
.PHONY: kustomize-edit-set-image
kustomize-edit-set-image: $(addprefix kustomize-edit-set-image-,controller proxy)
.PHONY: protoc-docker
protoc-docker: ## Build a Docker image which can be used for generating protobuf code (below)
docker build --build-arg GO_VERSION=${GO_VERSION} --quiet - -t protoc < hack/grpc-protoc.Dockerfile
.PHONY: protobuf
protobuf: ## Generate a go implementation of the protobuf proxy API
protobuf: protoc-docker
docker run -v `pwd`:/eco -w /eco protoc:latest -I=api/proxy --go_out=plugins=grpc:api/proxy api/proxy/v1/proxy.proto
.PHONY: verify-protobuf-lint
verify-protobuf-lint: ## Run protobuf static checks
docker run --volume ${CURDIR}:/workspace:ro --workdir /workspace bufbuild/buf check lint
.PHONY: manifests
manifests: ## Generate manifests e.g. CRD, RBAC etc.
manifests: ${CONTROLLER_GEN}
$(CONTROLLER_GEN) rbac:roleName=manager-role crd paths=./api/... webhook paths="./..." output:crd:artifacts:config=config/bases/crd/bases
.PHONY: uber
uber: KUSTOMIZE_DIRECTORY_TO_EDIT=config/bases/manager
uber: kustomize-edit-set-image
${KUSTOMIZE} build --output storageos-etcd-cluster-operator.yaml config/default
.PHONY: fmt
fmt: ## Run go fmt against code
${GO} fmt .
.PHONY: vet
vet: ## Run go vet against code
${GO} vet ./...
.PHONY: generate
generate: ## Generate code
generate: ${CONTROLLER_GEN}
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..."
.PHONY: gomod
gomod: ## Update the go.mod and go.sum files
${GO} mod tidy
.PHONY: manifests-image
manifests-image: # Build the manifests docker image.
docker build -t $(DOCKER_IMAGE_MANIFESTS) --build-arg OPERATOR_IMAGE=$(DOCKER_IMAGE_CONTROLLER) --build-arg PROXY_IMAGE=$(DOCKER_IMAGE_PROXY) -f manifests.Dockerfile .
.PHONY: manifests-image-push
manifests-image-push: # Build the manifests docker image.
docker push $(DOCKER_IMAGE_MANIFESTS)
.PHONY: docker-build
docker-build: ## Build the all the docker images
docker-build: $(addprefix docker-build-,$(DOCKER_IMAGES))
docker-build-%: FORCE
docker build --target $* \
--build-arg GO_VERSION=${GO_VERSION} \
--build-arg VERSION=$(VERSION) \
--build-arg BACKUP_AGENT_IMAGE=${DOCKER_IMAGE_BACKUP_AGENT} \
--build-arg RESTORE_AGENT_IMAGE=${DOCKER_IMAGE_RESTORE_AGENT} \
--tag ${DOCKER_REPO}/${DOCKER_IMAGE_NAME_PREFIX}$*:${DOCKER_TAG} \
--tag quay.io/${DOCKER_REPO}/${DOCKER_IMAGE_NAME_PREFIX}$*:${DOCKER_TAG} \
--file Dockerfile \
${CURDIR}
FORCE:
.PHONY: docker-push
docker-push: ## Push all the docker images
docker-push: $(addprefix docker-push-,$(DOCKER_IMAGES))
docker-push-%: FORCE
docker push ${DOCKER_REPO}/${DOCKER_IMAGE_NAME_PREFIX}$*:${DOCKER_TAG}
docker push quay.io/${DOCKER_REPO}/${DOCKER_IMAGE_NAME_PREFIX}$*:${DOCKER_TAG}
FORCE:
# Run the supplied make target argument in a temporary workspace and diff the results.
verify-%: FORCE
./hack/verify.sh ${MAKE} -s $*
FORCE:
.PHONY: kind-cluster
kind-cluster: ## Use Kind to create a Kubernetes cluster for E2E tests
kind-cluster: ${KIND}
${KIND} get clusters | grep ${K8S_CLUSTER_NAME} || ${KIND} create cluster --name ${K8S_CLUSTER_NAME}
.PHONY: kind-cluster
kind-load: ## Load all the Docker images into Kind
kind-load: $(addprefix kind-load-,$(DOCKER_IMAGES))
kind-load-%: FORCE ${KIND}
${KIND} load docker-image --name ${K8S_CLUSTER_NAME} ${DOCKER_REPO}/${DOCKER_IMAGE_NAME_PREFIX}$*:${DOCKER_TAG}
FORCE:
.PHONY: kind-export-logs
kind-export-logs:
${KIND} export logs --name ${K8S_CLUSTER_NAME} ${E2E_ARTIFACTS_DIRECTORY}
# ===================================
# Release: Tag and Push Docker Images
# ===================================
.PHONY: .create-release-tag
.create-release-tag: KUSTOMIZE_DIRECTORY_TO_EDIT=config/bases/manager
.create-release-tag: kustomize-edit-set-image
git add ${KUSTOMIZE_DIRECTORY_TO_EDIT}
git commit --message "Release ${VERSION}"
git tag --annotate --message "Release ${VERSION}" ${VERSION}
${RELEASE_NOTES}:
$(error "Release notes not found: ${RELEASE_NOTES}")
${RELEASE_MANIFEST}: KUSTOMIZE_DIRECTORY_TO_EDIT=config/bases/manager
${RELEASE_MANIFEST}: kustomize-edit-set-image
${KUSTOMIZE} build --output ${RELEASE_MANIFEST} ${KUSTOMIZE_DIRECTORY_TO_EDIT}
.PHONY: release
release: ## Create a tagged release
release: KUSTOMIZE_DIRECTORY_TO_EDIT=config/bases/manager
release: version ${RELEASE_NOTES} docker-build docker-push ${RELEASE_MANIFEST} .create-release-tag
.PHONY: version
version:
@echo $(or $(filter v%, $(firstword ${VERSION})), $(error Version must begin with v. Got: ${VERSION}))
# ==================================
# Download: tools in ${BIN}
# ==================================
${BIN}:
mkdir -p ${BIN}
${CONTROLLER_GEN}: | ${BIN}
# Prevents go get from modifying our go.mod file.
# See https://github.com/kubernetes-sigs/kubebuilder/issues/909
cd /tmp; GOBIN=${BIN} GO111MODULE=on ${GO} install sigs.k8s.io/controller-tools/cmd/controller-gen@v${CONTROLLER_GEN_VERSION}
mv ${BIN}/controller-gen ${CONTROLLER_GEN}
${KUSTOMIZE}: | ${BIN}
curl -sSL -o ${KUSTOMIZE_LOCAL_ARCHIVE} ${KUSTOMIZE_DOWNLOAD_URL}
tar -C ${BIN} -x -f ${KUSTOMIZE_LOCAL_ARCHIVE}
mv ${BIN}/kustomize ${KUSTOMIZE}
.PHONY: kind
kind:
curl -sSL -o ${KIND} https://github.com/kubernetes-sigs/kind/releases/download/v${KIND_VERSION}/kind-${OS}-${ARCH}
chmod +x ${KIND}
.PHONY: kubebuilder
kubebuilder:
hack/download-kubebuilder-local.sh