forked from gardener/etcd-druid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
214 lines (176 loc) · 7.22 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
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0
REPO_ROOT := $(shell dirname "$(realpath $(lastword $(MAKEFILE_LIST)))")
HACK_DIR := $(REPO_ROOT)/hack
VERSION := $(shell $(HACK_DIR)/get-version.sh)
GIT_SHA := $(shell git rev-parse --short HEAD || echo "GitNotFound")
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}}')
BUILD_DIR := build
PROVIDERS := ""
BUCKET_NAME := "e2e-test"
IMG ?= ${IMAGE_REPOSITORY}:${IMAGE_BUILD_TAG}
TEST_COVER := "true"
KUBECONFIG_PATH := $(HACK_DIR)/kind/kubeconfig
# Tools
# -------------------------------------------------------------------------
TOOLS_DIR := $(HACK_DIR)/tools
include $(HACK_DIR)/tools.mk
# Rules for generation (code and manifests)
# -------------------------------------------------------------------------
.PHONY: check-generate
check-generate:
@$(HACK_DIR)/check-generate.sh "$(REPO_ROOT)"
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests: $(VGOPATH) $(CONTROLLER_GEN)
@HACK_DIR=$(HACK_DIR) VGOPATH=$(VGOPATH) go generate ./config/crd/bases
@find "$(REPO_ROOT)/config/crd/bases" -name "*.yaml" -exec cp '{}' "$(REPO_ROOT)/charts/druid/charts/crds/templates/" \;
@controller-gen rbac:roleName=manager-role paths="./internal/controller/..."
.PHONY: generate-api-docs
generate-api-docs: $(CRD_REF_DOCS)
@crd-ref-docs --source-path "$(REPO_ROOT)/api" --config "$(HACK_DIR)/api-reference/config.yaml" --output-path "$(REPO_ROOT)/docs/api-reference/etcd-druid-api.md" --renderer markdown
# Generate code
.PHONY: generate
generate: manifests generate-api-docs $(CONTROLLER_GEN) $(GOIMPORTS) $(MOCKGEN)
@go generate "$(REPO_ROOT)/internal/..."
@"$(HACK_DIR)/update-codegen.sh"
# Rules for verification, formatting, linting and cleaning
# -------------------------------------------------------------------------
.PHONY: tidy
tidy:
@env GO111MODULE=on go mod tidy
.PHONY: clean
clean:
@$(HACK_DIR)/clean.sh ./api/... ./internal/...
# 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 ${YEAR}
# Format code and arrange imports.
.PHONY: format
format: $(GOIMPORTS_REVISER)
@$(HACK_DIR)/format.sh ./api/ ./internal/ ./test/
# Check packages
.PHONY: check
check: $(GOLANGCI_LINT) $(GOIMPORTS) format manifests
@$(HACK_DIR)/check.sh --golangci-lint-config=./.golangci.yaml ./api/... ./internal/...
.PHONY: check-apidiff
check-apidiff: $(GO_APIDIFF)
@$(HACK_DIR)/check-apidiff.sh
# Rules for testing (unit, integration and end-2-end)
# -------------------------------------------------------------------------
# Run tests
.PHONY: test-unit
test-unit: $(GINKGO) $(GOTESTFMT)
# 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/secret/... \
./internal/controller/utils/... \
./internal/mapper/... \
./internal/metrics/... \
./internal/health/...
# run the golang native unit tests.
@TEST_COVER=$(TEST_COVER) "$(HACK_DIR)/test-go.sh" ./api/... \
./internal/controller/etcd/... \
./internal/controller/compaction/... \
./internal/component/... \
./internal/errors/... \
./internal/store/... \
./internal/utils/... \
./internal/webhook/...
.PHONY: test-integration
test-integration: $(GINKGO) $(SETUP_ENVTEST) $(GOTESTFMT)
@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
.PHONY: test-e2e
test-e2e: $(KUBECTL) $(HELM) $(SKAFFOLD) $(KUSTOMIZE) $(GINKGO)
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(HACK_DIR)/e2e-test/run-e2e-test.sh $(PROVIDERS)
.PHONY: ci-e2e-kind
ci-e2e-kind: $(GINKGO) $(YQ) $(KIND)
@BUCKET_NAME=$(BUCKET_NAME) $(HACK_DIR)/ci-e2e-kind.sh
.PHONY: ci-e2e-kind-azure
ci-e2e-kind-azure: $(GINKGO)
@BUCKET_NAME=$(BUCKET_NAME) $(HACK_DIR)/ci-e2e-kind-azure.sh
# Rules related to binary build, Docker image build and release
# -------------------------------------------------------------------------
# Build manager binary
.PHONY: druid
druid: check
@env GO111MODULE=on go build -o bin/druid 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 .
@echo "updating kustomize image patch file for manager resource"
sed -i'' -e 's@image: .*@image: '"${IMG}"'@' ./config/default/manager_image_patch.yaml
# 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 deploy-localstack deploy-azurite test-e2e deploy deploy-dev deploy-debug undeploy: export KUBECONFIG = $(KUBECONFIG_PATH)
.PHONY: kind-up
kind-up: $(KIND)
@$(HACK_DIR)/kind-up.sh
@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
# Install CRDs into a cluster
.PHONY: install
install: manifests
kubectl apply -f config/crd/bases
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: deploy-via-kustomize
deploy-via-kustomize: manifests $(KUSTOMIZE)
kubectl apply -f config/crd/bases
kustomize build config/default | kubectl apply -f -
# 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
.PHONY: deploy
deploy: $(SKAFFOLD) $(HELM)
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(SKAFFOLD) run -m etcd-druid
.PHONY: deploy-dev
deploy-dev: $(SKAFFOLD) $(HELM)
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(SKAFFOLD) dev --cleanup=false -m etcd-druid --trigger='manual'
.PHONY: deploy-debug
deploy-debug: $(SKAFFOLD) $(HELM)
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(SKAFFOLD) debug --cleanup=false -m etcd-druid -p debug
.PHONY: undeploy
undeploy: $(SKAFFOLD) $(HELM)
$(SKAFFOLD) delete -m etcd-druid
.PHONY: deploy-localstack
deploy-localstack: $(KUBECTL)
@$(HACK_DIR)/deploy-localstack.sh
.PHONY: deploy-azurite
deploy-azurite: $(KUBECTL)
./hack/deploy-azurite.sh