-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathMakefile
More file actions
274 lines (232 loc) · 9.49 KB
/
Makefile
File metadata and controls
274 lines (232 loc) · 9.49 KB
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
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0
SHELL := bash
REPO_ROOT := $(shell dirname "$(realpath $(lastword $(MAKEFILE_LIST)))")
HACK_DIR := $(REPO_ROOT)/hack
API_HACK_DIR := $(REPO_ROOT)/api/hack
VERSION := $(shell $(HACK_DIR)/get-version.sh)
REGISTRY_ROOT := europe-docker.pkg.dev/gardener-project
REGISTRY := $(REGISTRY_ROOT)/snapshots
IMAGE_NAME := gardener/etcd-druid
IMAGE_REPOSITORY := $(REGISTRY)/$(IMAGE_NAME)
IMAGE_BUILD_TAG := $(VERSION)
PLATFORM ?= $(shell docker info --format '{{.OSType}}/{{.Architecture}}')
PROVIDERS ?= "none,local"
BUCKET_NAME := "e2e-test"
IMG ?= ${IMAGE_REPOSITORY}:${IMAGE_BUILD_TAG}
TEST_COVER := "true"
KUBECONFIG_PATH := $(HACK_DIR)/kind/kubeconfig
CI_K8S_VERSION ?= 1.34
# Tools
# -------------------------------------------------------------------------
TOOLS_DIR := $(HACK_DIR)/tools
include $(HACK_DIR)/tools.mk
ifndef CERT_EXPIRY_DAYS
override CERT_EXPIRY_DAYS = 365
endif
# Rules for verification, formatting, linting and cleaning
# -------------------------------------------------------------------------
.PHONY: tidy
tidy:
@env GO111MODULE=on go mod tidy
# Clean go mod cache
.PHONY: clean-mod-cache
clean-mod-cache:
@go clean -modcache
.PHONY: update-dependencies
update-dependencies:
@env GO111MODULE=on go get -u ./...
@make tidy
.PHONY: add-license-headers
add-license-headers: $(GO_ADD_LICENSE)
@$(HACK_DIR)/addlicenseheaders.sh
# Format code and arrange imports.
.PHONY: format
format: $(GOIMPORTS_REVISER)
@$(HACK_DIR)/format.sh ./cmd/ ./internal/ ./test/ ./examples/
# Check packages
.PHONY: check
check: $(GOLANGCI_LINT) $(GOIMPORTS) format
@$(HACK_DIR)/check.sh --golangci-lint-config=./.golangci.yaml ./internal/...
# Check license headers
.PHONY: check-license-headers
check-license-headers: $(GO_ADD_LICENSE)
@$(HACK_DIR)/check-license-headers.sh
# Check git status is clean (only tracked files, ignores untracked files)
.PHONY: check-git-status
check-git-status:
@if [[ -n $$(git status --porcelain -uno) ]]; then \
echo ""; \
echo "⚠️ WARNING: Repository has uncommitted changes to tracked files."; \
echo "Please fix/commit these changes before pushing to a PR/upstream."; \
echo ""; \
git status -uno; \
git --no-pager diff; \
exit 1; \
else \
echo ""; \
echo "✅ Repository is clean (tracked files)."; \
fi
# Run all CI checks and verify git tree is clean
.PHONY: ci-checks
ci-checks:
@echo "Running CI checks..."
@$(MAKE) tidy
@$(MAKE) check
@$(MAKE) check-license-headers
@$(MAKE) --directory=api tidy
@$(MAKE) --directory=api check
@$(MAKE) --directory=api check-generate
@$(MAKE) --directory=druidctl tidy
@$(MAKE) --directory=druidctl check
@$(MAKE) ci-prepare-helm-charts
@$(MAKE) check-git-status
.PHONY: sast
sast: $(GOSEC)
@./hack/sast.sh
.PHONY: sast-report
sast-report: $(GOSEC)
@./hack/sast.sh --gosec-report true
# Rules for testing (unit, integration and end-2-end)
# -------------------------------------------------------------------------
# Run tests
.PHONY: test-unit
test-unit: $(GINKGO)
# run ginkgo unit tests. These will be ported to golang native tests over a period of time.
@TEST_COVER=$(TEST_COVER) "$(HACK_DIR)/test.sh" ./internal/controller/etcdcopybackupstask/... \
./internal/controller/utils/... \
./internal/mapper/... \
./internal/metrics/... \
./internal/health/... \
./internal/utils/imagevector/...
# run the golang native unit tests.
@TEST_COVER=$(TEST_COVER) "$(HACK_DIR)/test-go.sh" \
./internal/controller/etcd/... \
./internal/controller/etcdopstask/... \
./internal/controller/secret/... \
./internal/controller/compaction/... \
./internal/component/... \
./internal/errors/... \
./internal/store/... \
./internal/utils/... \
./internal/webhook/...
.PHONY: test-integration
test-integration: $(GINKGO) $(SETUP_ENVTEST)
@SETUP_ENVTEST="true" "$(HACK_DIR)/test.sh" ./test/integration/...
@SETUP_ENVTEST="true" "$(HACK_DIR)/test-go.sh" ./test/it/...
# Starts a stand alone envtest which you can leverage to test an individual integration-test.
.PHONE: start-envtest
start-envtest: $(SETUP_ENVTEST)
@$(HACK_DIR)/start-envtest.sh
.PHONY: test-cov-clean
test-cov-clean:
@$(HACK_DIR)/test-cover-clean.sh
# Set env var PROVIDERS to specify which providers to test. Current options are:
# - none: tests without any cloud provider integration.
# - local: tests with local storage provider.
# - none,local: tests with both none and local providers.
# - Default: none,local.
# Set env var RETAIN_TEST_ARTIFACTS=[all|failed] to retain the test artifacts for all test cases or only the failed ones.
# Set env var GO_TEST_ARGS to pass additional args to go test command, like "-run <TestName> -count=1 -v":
# - Set -run <TestName> to run specific tests.
# - Set -count=1 to not use cached results.
# - Set -v for verbose logs.
.PHONY: test-e2e
test-e2e: $(KUBECTL) $(HELM) $(SKAFFOLD)
@SETUP_ENVTEST="false" PROVIDERS=$(PROVIDERS) "$(HACK_DIR)/test-go.sh" ./test/e2e/... -parallel 10 -timeout 1h $(GO_TEST_ARGS)
# Set env var PROVIDERS to specify which providers to test. Current options are "none", "local" and "none,local".
# Default: none,local.
# Set env var RETAIN_TEST_ARTIFACTS=[all|failed] to retain the test artifacts for all test cases or only the failed ones.
# Set env var RETAIN_KIND_CLUSTER=true to retain the kind cluster.
# Set env var GO_TEST_ARGS to pass additional args to go test command, like `-run <TestName> -count=1 -v`.
.PHONY: ci-e2e-kind
ci-e2e-kind: $(GINKGO) $(YQ) $(KIND)
@BUCKET_NAME=$(BUCKET_NAME) PROVIDERS=$(PROVIDERS) $(HACK_DIR)/ci-e2e-kind.sh
.PHONY: clean-e2e-test-resources
clean-e2e-test-resources: $(KUBECTL)
@rm -rf $(REPO_ROOT)/test/e2e/controller/pki-resources/*
@kubectl get ns -o custom-columns=":metadata.name" --no-headers | grep '^etcd-e2e-' | xargs --no-run-if-empty kubectl delete ns
# Rules related to binary build, Docker image build and release
# -------------------------------------------------------------------------
# Build manager binary
.PHONY: build
build:
@GO111MODULE=on CGO_ENABLED=0 go build \
-v \
-o bin/etcd-druid \
-ldflags "$$(bash -c 'source $(HACK_DIR)/ld-flags.sh && build_ld_flags')" \
cmd/main.go
# Clean go build cache
.PHONY: clean-build-cache
clean-build-cache:
@go clean -cache
# Build the docker image
.PHONY: docker-build
docker-build:
docker buildx build --platform=$(PLATFORM) --tag $(IMG) --rm .
# Push the docker image
.PHONY: docker-push
docker-push:
docker push ${IMG}
# Clean up all docker images for etcd-druid
.PHONY: docker-clean
docker-clean:
docker images | grep -e "$(REGISTRY_ROOT)/.*/$(IMAGE_NAME)" | awk '{print $$3}' | xargs docker rmi -f
# Rules for locale/remote environment
# -------------------------------------------------------------------------
kind-up kind-down ci-e2e-kind ci-e2e-kind-azure ci-e2e-kind-gcs deploy-localstack deploy-fakegcs deploy-azurite test-e2e deploy deploy-dev deploy-debug undeploy: export KUBECONFIG = $(KUBECONFIG_PATH)
ifndef CLUSTER_NAME
override CLUSTER_NAME = etcd-druid-e2e
endif
.PHONY: kind-up
kind-up: $(KIND)
@$(HACK_DIR)/kind-up.sh --cluster-name $(CLUSTER_NAME)
@printf "\n\033[0;33m📌 NOTE: To target the newly created KinD cluster, please run the following command:\n\n export KUBECONFIG=$(KUBECONFIG_PATH)\n\033[0m\n"
.PHONY: kind-down
kind-down: $(KIND)
@$(HACK_DIR)/kind-down.sh --cluster-name $(CLUSTER_NAME)
# Make targets to deploy etcd-druid operator using skaffold
# --------------------------------------------------------------------------------------------------------
# Deploy controller to the Kubernetes cluster specified in the environment variable KUBECONFIG
# Modify the Helm template located at charts/druid/templates if any changes are required
ifndef NAMESPACE
override NAMESPACE = default
endif
# While preparing helm charts, it will by default attempt to get the k8s version by invoking kubectl command assuming that you are already connected to a k8s cluster.
# If you wish to specify a specific k8s version, then set K8S_VERSION environment variable to a value of your choice.
.PHONY: prepare-helm-charts
prepare-helm-charts:
ifeq ($(strip $(K8S_VERSION)),)
@$(HACK_DIR)/prepare-chart-resources.sh --namespace $(NAMESPACE) --cert-expiry $(CERT_EXPIRY_DAYS)
else
@$(HACK_DIR)/prepare-chart-resources.sh --namespace $(NAMESPACE) --cert-expiry $(CERT_EXPIRY_DAYS) --k8s-version $(K8S_VERSION)
endif
.PHONY: ci-prepare-helm-charts
ci-prepare-helm-charts: $(KUBECTL)
@K8S_VERSION=$(CI_K8S_VERSION) $(MAKE) prepare-helm-charts
.PHONY: deploy
deploy: $(SKAFFOLD) $(HELM) prepare-helm-charts
@$(HACK_DIR)/deploy-local.sh run -m etcd-druid -n $(NAMESPACE)
.PHONY: deploy-dev
deploy-dev: $(SKAFFOLD) $(HELM) prepare-helm-charts
@$(HACK_DIR)/deploy-local.sh dev --cleanup=false -m etcd-druid --trigger='manual' -n $(NAMESPACE)
.PHONY: deploy-debug
deploy-debug: $(SKAFFOLD) $(HELM) prepare-helm-charts
@$(HACK_DIR)/deploy-local.sh debug --cleanup=false -m etcd-druid -p debug -n $(NAMESPACE)
.PHONY: undeploy
undeploy: $(SKAFFOLD) $(HELM)
$(SKAFFOLD) delete -m etcd-druid -n $(NAMESPACE)
.PHONY: deploy-localstack
deploy-localstack: $(KUBECTL)
@$(HACK_DIR)/deploy-localstack.sh
.PHONY: deploy-azurite
deploy-azurite: $(KUBECTL)
@$(HACK_DIR)/deploy-azurite.sh
.PHONY: deploy-fakegcs
deploy-fakegcs: $(KUBECTL)
@$(HACK_DIR)/deploy-fakegcs.sh
.PHONY: clean-chart-resources
clean-chart-resources:
@rm -f $(REPO_ROOT)/charts/crds/*.yaml
@rm -rf $(REPO_ROOT)/charts/pki-resources/*