-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
368 lines (287 loc) · 11.3 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
PROJECT_NAME ?= kubernetes-operator
PROJECT_VERSION ?= 0.0.9
CONTAINER_REGISTRY ?= docker.io
CONTAINER_REGISTRY_ORG ?= daprio
CONTAINER_IMAGE_VERSION ?= $(PROJECT_VERSION)
CONTAINER_IMAGE ?= $(CONTAINER_REGISTRY)/$(CONTAINER_REGISTRY_ORG)/$(PROJECT_NAME):$(CONTAINER_IMAGE_VERSION)
BUNDLE_NAME ?= dapr-kubernetes-operator
BUNDLE_VERSION ?= $(PROJECT_VERSION)
BUNDLE_CONTAINER_IMAGE ?= $(CONTAINER_REGISTRY)/$(CONTAINER_REGISTRY_ORG)/$(PROJECT_NAME)-bundle:$(BUNDLE_VERSION)
CATALOG_VERSION ?= latest
CATALOG_CONTAINER_IMAGE ?= $(CONTAINER_REGISTRY)/$(CONTAINER_REGISTRY_ORG)/$(PROJECT_NAME)-catalog:$(CATALOG_VERSION)
LINT_GOGC ?= 10
LINT_TIMEOUT ?= 10m
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
LOCALBIN := $(PROJECT_PATH)/bin
HELM_CHART_REPO ?= https://dapr.github.io/helm-charts
HELM_CHART ?= dapr
HELM_CHART_VERSION ?= 1.14.1
HELM_CHART_URL ?= https://raw.githubusercontent.com/dapr/helm-charts/master/dapr-$(HELM_CHART_VERSION).tgz
OPENSHIFT_VERSIONS ?= v4.12
## Tool Versions
KUSTOMIZE_VERSION ?= v5.4.3
KIND_VERSION ?= v0.24.0
KIND_IMAGE_VERSION ?= v1.30.4
LINTER_VERSION ?= v1.61.0
OPERATOR_SDK_VERSION ?= v1.37.0
OPM_VERSION ?= v1.47.0
GOVULNCHECK_VERSION ?= latest
KO_VERSION ?= latest
## Tool Binaries
KUBECTL ?= kubectl
KUSTOMIZE ?= $(LOCALBIN)/kustomize
LINTER ?= $(LOCALBIN)/golangci-lint
GOIMPORT ?= $(LOCALBIN)/goimports
YQ ?= $(LOCALBIN)/yq
KIND ?= $(LOCALBIN)/kind
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
OPM ?= $(LOCALBIN)/opm
GOVULNCHECK ?= $(LOCALBIN)/govulncheck
KO ?= $(LOCALBIN)/ko
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.PHONY: all
all: build
ifndef ignore-not-found
ignore-not-found = false
endif
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
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)
##@ Dapr
.PHONY: update/dapr
update/dapr: ## Update the helm chart.
$(PROJECT_PATH)/hack/scripts/update_helm_chart.sh $(PROJECT_PATH) $(HELM_CHART_URL)
##@ Development
.PHONY: manifests
manifests: ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(PROJECT_PATH)/hack/scripts/gen_manifests.sh $(PROJECT_PATH)
.PHONY: generate
generate: ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(PROJECT_PATH)/hack/scripts/gen_res.sh $(PROJECT_PATH)
$(PROJECT_PATH)/hack/scripts/gen_client.sh $(PROJECT_PATH)
.PHONY: fmt
fmt: goimport ## Run go fmt, gomiport against code.
$(GOIMPORT) -l -w .
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: test
test: manifests generate fmt vet ## Run tests.
DAPR_HELM_CHART_VERSION="$(HELM_CHART_VERSION)" go test -ldflags="$(GOLDFLAGS)" -v ./pkg/... ./internal/...
.PHONY: test/e2e/operator
test/e2e/operator: manifests generate fmt vet ## Run e2e operator tests.
DAPR_HELM_CHART_VERSION="$(HELM_CHART_VERSION)" go test -ldflags="$(GOLDFLAGS)" -p 1 -v ./test/e2e/operator/...
.PHONY: test/e2e/olm
test/e2e/olm: ## Run e2e catalog tests.
DAPR_HELM_CHART_VERSION="$(HELM_CHART_VERSION)" go test -ldflags="$(GOLDFLAGS)" -p 1 -v ./test/e2e/olm/...
.PHONY: test/e2e/app
test/e2e/app: ko ## Deploy test app.
KO_DOCKER_REPO=kind.local $(LOCALBIN)/ko build -B ./test/e2e/support/dapr-test-app
.PHONY: test/e2e/kind
test/e2e/kind: kind ## Deploy test app.
$(LOCALBIN)/kind create cluster \
--image=kindest/node:$(KIND_IMAGE_VERSION) \
--config=$(PROJECT_PATH)/test/e2e/kind.yaml \
--wait=60s
##@ Build
.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -ldflags="$(GOLDFLAGS)" -o bin/dapr-control-plane cmd/main.go
.PHONY: run
run: ## Run a controller from your host.
go run -ldflags="$(GOLDFLAGS)" cmd/main.go run \
--leader-election=false \
--zap-devel \
--health-probe-bind-address ":0" \
--metrics-bind-address ":0"
.PHONY: run/local
run/local: install ## Install and Run a controller from your host.
go run -ldflags="$(GOLDFLAGS)" cmd/main.go run \
--leader-election=false \
--zap-devel \
--health-probe-bind-address ":0" \
--metrics-bind-address ":0"
.PHONY: deps
deps: ## Tidy up deps.
go mod tidy
.PHONY: check
check: check/lint check/vuln
.PHONY: check/lint
check/lint: golangci-lint
@echo "run golangci-lint"
@$(LINTER) run \
--config .golangci.yml \
--out-format tab \
--exclude-dirs etc \
--timeout $(LINT_TIMEOUT) \
--verbose
.PHONY: check/lint/fix
check/lint/fix: golangci-lint
@$(LINTER) run \
--config .golangci.yml \
--out-format tab \
--exclude-dirs etc \
--timeout $(LINT_TIMEOUT) \
--fix
.PHONY: check/vuln
check/vuln: govulncheck
@echo "run govulncheck"
@$(GOVULNCHECK) ./...
.PHONY: docker/build
docker/build: test ## Build docker image with the manager.
$(CONTAINER_TOOL) build -t $(CONTAINER_IMAGE) .
.PHONY: docker/push
docker/push: ## Push docker image with the manager.
$(CONTAINER_TOOL) push $(CONTAINER_IMAGE)
.PHONY: docker/push/kind
docker/push/kind: kind docker/build ## Load docker image in kind.
$(LOCALBIN)/kind load docker-image $(CONTAINER_IMAGE)
.PHONY: docker/image/name
docker/image/name:
@echo $(CONTAINER_IMAGE)
##@ Deployment
.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=$(CONTAINER_IMAGE)
$(KUSTOMIZE) build config/deploy/standalone | kubectl apply -f -
.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/deploy/standalone | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
.PHONY: deploy/kind
deploy/kind: manifests kustomize kind ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=$(CONTAINER_IMAGE)
$(LOCALBIN)/ load docker-image $(CONTAINER_IMAGE)
$(KUSTOMIZE) build config/deploy/standalone | kubectl apply -f -
.PHONY: deploy/e2e/controller
deploy/e2e/controller: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=$(CONTAINER_IMAGE)
$(KUSTOMIZE) build config/deploy/e2e | kubectl apply -f -
kubectl wait \
--namespace=dapr-system \
--for=condition=ready \
pod \
--selector=control-plane=dapr-control-plane \
--timeout=90s
.PHONY: deploy/e2e/ingress
deploy/e2e/ingress:
$(PROJECT_PATH)/hack/scripts/deploy_ingress.sh
.PHONY: deploy/e2e/olm
deploy/e2e/olm:
$(PROJECT_PATH)/hack/scripts/deploy_olm.sh
##@ Bundles
.PHONY: bundle/info
bundle/info: ## Dump bundle info.
@echo $(CONTAINER_IMAGE)
@echo $(BUNDLE_CONTAINER_IMAGE)
.PHONY: bundle/generate_
bundle/generate: generate manifests kustomize operator-sdk yq ## Generate bundle.
cd config/manager && $(KUSTOMIZE) edit set image controller=$(CONTAINER_IMAGE)
$(PROJECT_PATH)/hack/scripts/gen_bundle.sh \
$(PROJECT_PATH) \
$(BUNDLE_NAME) \
$(BUNDLE_VERSION) \
$(OPENSHIFT_VERSIONS)
.PHONY: bundle/build
bundle/build: ## Build bundle image.
$(CONTAINER_TOOL) build \
-t $(BUNDLE_CONTAINER_IMAGE) \
-f $(PROJECT_PATH)/bundle/bundle.Dockerfile \
$(PROJECT_PATH)/bundle
.PHONY: bundle/push
bundle/push: ## Push bundle image.
$(CONTAINER_TOOL) push $(BUNDLE_CONTAINER_IMAGE)
.PHONY: catalog/build
catalog/build: opm ## Build catalog image.
$(OPM) index add \
--container-tool $(CONTAINER_TOOL) \
--mode semver \
--tag $(CATALOG_CONTAINER_IMAGE) \
--bundles $(BUNDLE_CONTAINER_IMAGE)
.PHONY: catalog/push
catalog/push: ## Push catalog image.
$(CONTAINER_TOOL) push $(CATALOG_CONTAINER_IMAGE)
.PHONY: olm/install
olm/install: operator-sdk ## Install olm.
cd bin && $(OPERATOR_SDK) olm install
##@ Build Dependencies
## Location to install dependencies to
$(LOCALBIN):
mkdir -p $(LOCALBIN)
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
$(KUSTOMIZE): $(LOCALBIN)
test -s $(LOCALBIN)/kustomize || \
GOBIN=$(LOCALBIN) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)
.PHONY: golangci-lint
golangci-lint: $(LINTER)
$(LINTER): $(LOCALBIN)
@test -s $(LOCALBIN)/golangci-lint || \
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(LINTER_VERSION)
.PHONY: goimport
goimport: $(GOIMPORT)
$(GOIMPORT): $(LOCALBIN)
@test -s $(LOCALBIN)/goimport || \
GOBIN=$(LOCALBIN) go install golang.org/x/tools/cmd/goimports@latest
.PHONY: yq
yq: $(YQ)
$(YQ): $(LOCALBIN)
@test -s $(LOCALBIN)/yq || \
GOBIN=$(LOCALBIN) go install github.com/mikefarah/yq/v4@latest
.PHONY: kind
kind: $(KIND)
$(KIND): $(LOCALBIN)
@test -s $(LOCALBIN)/kind || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/kind@$(KIND_VERSION)
.PHONY: ko
ko: $(KO)
$(KO): $(LOCALBIN)
@test -s $(LOCALBIN)/ko || \
GOBIN=$(LOCALBIN) go install github.com/google/ko@$(KO_VERSION)
.PHONY: govulncheck
govulncheck: $(GOVULNCHECK)
$(GOVULNCHECK): $(LOCALBIN)
@test -s $(GOVULNCHECK) || \
GOBIN=$(LOCALBIN) go install golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION)
.PHONY: operator-sdk
operator-sdk: $(OPERATOR_SDK)
$(OPERATOR_SDK): $(LOCALBIN)
@echo "Installing operator-sdk"
$(PROJECT_PATH)/hack/scripts/install_operator_sdk.sh $(PROJECT_PATH) $(OPERATOR_SDK_VERSION)
.PHONY: opm
opm: $(OPM)
$(OPM): $(LOCALBIN)
@echo "Installing opm"
$(PROJECT_PATH)/hack/scripts/install_opm.sh $(PROJECT_PATH) $(OPM_VERSION)