-
Notifications
You must be signed in to change notification settings - Fork 28
/
Makefile
553 lines (457 loc) · 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
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
.PHONY: *
.SILENT: release
NOW_ISO8601 = $(shell date -u +"%Y-%m-%dT%H:%M:%S")
GOOS = $(shell go env GOOS)
GOARCH = $(shell go env GOARCH)
# change also circleci go build version "cimb/go:" if you change the version below
# https://github.com/DataDog/chaos-controller/blob/main/.circleci/config.yml#L85
BUILDGOVERSION = 1.23.1
# GOBIN can be provided (gitlab), defined (custom user setup), or empty/guessed (default go setup)
GOBIN ?= $(shell go env GOBIN)
ifeq (,$(GOBIN))
GOBIN = $(shell go env GOPATH)/bin
endif
INSTALL_DATADOG_AGENT = false
LIMA_INSTALL_SINK = noop
ifdef STAGING_DATADOG_API_KEY
ifdef STAGING_DATADOG_APP_KEY
INSTALL_DATADOG_AGENT = true
LIMA_INSTALL_SINK = datadog
endif
endif
# Lima requires to have images built on a specific namespace to be shared to the Kubernetes cluster when using containerd runtime
# https://github.com/abiosoft/colima#interacting-with-image-registry
CONTAINER_REGISTRY ?= k8s.io
CONTAINER_TAG ?= latest
CONTAINER_VERSION ?= $(shell git rev-parse HEAD)$(shell git diff --quiet || echo '-dirty')
CONTAINER_BUILD_EXTRA_ARGS ?=
SIGN_IMAGE ?= false
# Image URL to use all building/pushing image targets
MANAGER_IMAGE ?= ${CONTAINER_REGISTRY}/chaos-controller
INJECTOR_IMAGE ?= ${CONTAINER_REGISTRY}/chaos-injector
HANDLER_IMAGE ?= ${CONTAINER_REGISTRY}/chaos-handler
LIMA_PROFILE ?= lima
LIMA_CONFIG ?= lima
# default instance name will be connected user name
LIMA_INSTANCE ?= $(shell whoami | tr "." "-")
# cluster name is used by e2e-test to target the node with a disruption
# CI need to be able to override this value
E2E_TEST_CLUSTER_NAME ?= lima-$(LIMA_INSTANCE)
E2E_TEST_KUBECTL_CONTEXT ?= lima
KUBECTL ?= limactl shell $(LIMA_INSTANCE) sudo kubectl
PROTOC_VERSION = 3.17.3
PROTOC_OS ?= osx
PROTOC_ZIP = protoc-${PROTOC_VERSION}-${PROTOC_OS}-x86_64.zip
# you might also want to change ~/lima.yaml k3s version
KUBERNETES_MAJOR_VERSION ?= 1.26
KUBERNETES_VERSION ?= v$(KUBERNETES_MAJOR_VERSION).0
KUBEBUILDER_VERSION ?= 3.1.0
USE_VOLUMES ?= false
HELM_VALUES ?= dev.yaml
HELM_VERSION = v3.11.3
HELM_INSTALLED_VERSION = $(shell (helm version --template="{{ .Version }}" || echo "") | awk '{ print $$1 }')
# TODO: reenable depguard in .golangci.yml after upgrading golangci-lint again
GOLANGCI_LINT_VERSION = 1.61.0
GOLANGCI_LINT_INSTALLED_VERSION = $(shell (golangci-lint --version || echo "") | sed -E 's/.*version ([^ ]+).*/\1/')
CONTROLLER_GEN_VERSION = v0.14.0
CONTROLLER_GEN_INSTALLED_VERSION = $(shell (controller-gen --version || echo "") | awk '{ print $$2 }')
MOCKERY_VERSION = 2.43.2
MOCKERY_ARCH = $(GOARCH)
ifeq (amd64,$(GOARCH))
MOCKERY_ARCH = x86_64
endif
MOCKERY_INSTALLED_VERSION = $(shell mockery --version --quiet --config="" 2>/dev/null || echo "")
# Additional args to provide to test runner (ginkgo)
# examples:
# `make test TEST_ARGS=--until-it-fails` to run tests randomly and repeatedly until a failure might occur (help to detect flaky tests or wrong tests setup)
# `make test TEST_ARGS=injector` will focus on package injector to run tests
TEST_ARGS ?=
DD_ENV = local
# https://circleci.com/docs/variables/
# we rely on standard CI env var to adapt test upload configuration automatically
ifeq (true,$(CI))
DD_ENV = ci
endif
LIMA_CGROUPS=v1
ifeq (v2,$(CGROUPS))
LIMA_CGROUPS=v2
endif
# we define target specific variables values https://www.gnu.org/software/make/manual/html_node/Target_002dspecific.html
injector handler: BINARY_PATH=./cli/$(BINARY_NAME)
manager: BINARY_PATH=.
docker-build-injector docker-build-only-injector: CONTAINER_NAME=$(INJECTOR_IMAGE)
docker-build-handler docker-build-only-handler: CONTAINER_NAME=$(HANDLER_IMAGE)
docker-build-manager docker-build-only-manager: CONTAINER_NAME=$(MANAGER_IMAGE)
docker-build-ebpf:
docker buildx build --platform linux/$(GOARCH) --build-arg BUILDGOVERSION=$(BUILDGOVERSION) -t ebpf-builder-$(GOARCH) -f bin/ebpf-builder/Dockerfile .
-rm -r bin/injector/ebpf/
ifeq (true,$(USE_VOLUMES))
# create a dummy container with volume to store files
# circleci remote docker does not allow to use volumes, locally we fallbakc to standard volume but can call this target with USE_VOLUMES=true to debug if necessary
# https://circleci.com/docs/building-docker-images/#mounting-folders
-docker rm ebpf-volume
-docker create --platform linux/$(GOARCH) -v /app --name ebpf-volume ebpf-builder-$(GOARCH) /bin/true
-docker cp . ebpf-volume:/app
-docker rm ebpf-builder
docker run --platform linux/$(GOARCH) --volumes-from ebpf-volume --name=ebpf-builder ebpf-builder-$(GOARCH)
docker cp ebpf-builder:/app/bin/injector/ebpf bin/injector/ebpf
docker rm ebpf-builder
else
docker run --rm --platform linux/$(GOARCH) -v $(shell pwd):/app ebpf-builder-$(GOARCH)
endif
lima-push-injector lima-push-handler lima-push-manager: FAKE_FOR=COMPLETION
_injector:;
_handler:;
_manager: generate
_docker-build-injector:
ifneq (true,$(SKIP_EBPF))
$(MAKE) docker-build-ebpf
endif
_docker-build-handler:;
_docker-build-manager:;
# we define the template we expect for each target
# $(1) is the target name: injector|handler|manager
define TARGET_template
$(1): BINARY_NAME=$(1)
_$(1)_arm:
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o ./bin/$(1)/$(1)_arm64 $$(BINARY_PATH)
_$(1)_amd:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o ./bin/$(1)/$(1)_amd64 $$(BINARY_PATH)
$(1): _$(1) _$(1)_arm _$(1)_amd
docker-build-$(1): _docker-build-$(1) $(1) docker-build-only-$(1)
docker save $$(CONTAINER_NAME):$(CONTAINER_TAG) -o ./bin/$(1)/$(1).tar.gz
docker-build-only-$(1):
docker buildx build \
--build-arg BUILDGOVERSION=$(BUILDGOVERSION) \
--build-arg BUILDSTAMP=$(NOW_ISO8601) \
-t $$(CONTAINER_NAME):$(CONTAINER_TAG) \
--metadata-file ./bin/$(1)/docker-metadata.json \
$(CONTAINER_BUILD_EXTRA_ARGS) \
-f bin/$(1)/Dockerfile ./bin/$(1)/
if [ "$${SIGN_IMAGE}" = "true" ]; then \
ddsign sign $$(CONTAINER_NAME):$(CONTAINER_VERSION) --docker-metadata-file ./bin/$(1)/docker-metadata.json; \
fi
lima-push-$(1): docker-build-$(1)
limactl copy ./bin/$(1)/$(1).tar.gz $(LIMA_INSTANCE):/tmp/
limactl shell $(LIMA_INSTANCE) -- sudo k3s ctr i import /tmp/$(1).tar.gz
minikube-load-$(1):
# let's fail if the file does not exists so we know, mk load is not failing
ls -la ./bin/$(1)/$(1).tar.gz
minikube image load --daemon=false --overwrite=true ./bin/$(1)/$(1).tar.gz
endef
# we define the targers we want to generate make target for
TARGETS = injector handler manager
# we generate the exact same rules as for target specific variables, hence completion works and no duplication 😎
$(foreach tgt,$(TARGETS),$(eval $(call TARGET_template,$(tgt))))
# Build actions
all: $(TARGETS)
docker-build-all: $(addprefix docker-build-,$(TARGETS))
docker-build-only-all: $(addprefix docker-build-only-,$(TARGETS))
lima-push-all: $(addprefix lima-push-,$(TARGETS))
minikube-load-all: $(addprefix minikube-load-,$(TARGETS))
# Build chaosli
chaosli:
GOOS=darwin GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags="-X github.com/DataDog/chaos-controller/cli/chaosli/cmd.Version=$(VERSION)" -o bin/chaosli/chaosli_darwin_$(GOARCH) ./cli/chaosli/
# https://onsi.github.io/ginkgo/#recommended-continuous-integration-configuration
_ginkgo_test:
# Run the test and write a file if succeed
# Do not stop on any error
-go run github.com/onsi/ginkgo/v2/ginkgo --fail-on-pending --keep-going --vv \
--cover --coverprofile=cover.profile --randomize-all \
--race --trace --json-report=report-$(GO_TEST_REPORT_NAME).json --junit-report=report-$(GO_TEST_REPORT_NAME).xml \
--compilers=4 --procs=4 \
--poll-progress-after=10s --poll-progress-interval=10s \
$(GINKGO_TEST_ARGS) \
&& touch report-$(GO_TEST_REPORT_NAME)-succeed
# Try upload test reports if allowed and necessary prerequisites exists
ifneq (true,$(GO_TEST_SKIP_UPLOAD)) # you can bypass test upload
ifdef DATADOG_API_KEY # if no API key bypass is guaranteed
ifneq (,$(shell which datadog-ci)) # same if no test binary
-DD_ENV=$(DD_ENV) datadog-ci junit upload --service chaos-controller --tags="team:chaos-engineering,type:$(GO_TEST_REPORT_NAME)" report-$(GO_TEST_REPORT_NAME).xml
else
@echo "datadog-ci binary is not installed, run 'make install-datadog-ci' to upload tests results to datadog"
endif
else
@echo "DATADOG_API_KEY env var is not defined, create a local API key https://app.datadoghq.com/personal-settings/application-keys if you want to upload your local tests results to datadog"
endif
else
@echo "datadog-ci junit upload SKIPPED"
endif
# Fail if succeed file does not exists
[ -f report-$(GO_TEST_REPORT_NAME)-succeed ] && rm -f report-$(GO_TEST_REPORT_NAME)-succeed || exit 1
# Tests & CI
## Run unit tests
test: generate manifests
$(if $(GOPATH),,$(error GOPATH is not set. Please set GOPATH before running make test))
$(MAKE) _ginkgo_test GO_TEST_REPORT_NAME=$@ \
GINKGO_TEST_ARGS="-r --skip-package=controllers --randomize-suites --timeout=10m $(TEST_ARGS)"
spellcheck-deps:
ifeq (, $(shell which npm))
@{\
echo "please install npm or run 'make spellcheck-docker' for a slow but platform-agnistic run" ;\
exit 1 ;\
}
endif
ifeq (, $(shell which mdspell))
@{\
echo "installing mdspell through npm -g... (might require sudo run)" ;\
npm -g i markdown-spellcheck ;\
}
endif
spellcheck: spellcheck-deps
mdspell --en-us --ignore-acronyms --ignore-numbers \
$(shell find . -name vendor -prune -o -name '*.md' -print);
spellcheck-report: spellcheck-deps
mdspell --en-us --ignore-acronyms --ignore-numbers --report \
$(shell find . -name vendor -prune -o -name '*.md' -print);
spellcheck-docker:
docker run --rm -ti -v $(shell pwd):/workdir tmaier/markdown-spellcheck:latest --ignore-numbers --ignore-acronyms --en-us \
$(shell find . -name vendor -prune -o -name '*.md' -print);
spellcheck-format-spelling:
sort < .spelling | sort | uniq | grep -v '^-' | tee .spelling.tmp > /dev/null && mv .spelling.tmp .spelling
## This target is dedicated for CI and aims to reuse the Kubernetes version defined here as the source of truth
ci-install-minikube:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
sudo dpkg -i minikube_latest_amd64.deb
# adapt here according to circleCI VM resource_class https://circleci.com/docs/configuration-reference/#linuxvm-execution-environment
minikube start --cpus='6' --memory='28672' --vm-driver=docker --container-runtime=containerd --kubernetes-version=${KUBERNETES_VERSION}
minikube status
SKIP_DEPLOY ?=
## Run e2e tests (against a real cluster)
## to run them locally you first need to run `make install-kubebuilder`
e2e-test: generate manifests
ifneq (true,$(SKIP_DEPLOY)) # we can only wait for a controller if it exists, local.yaml does not deploy the controller
$(MAKE) lima-install HELM_VALUES=ci.yaml
endif
E2E_TEST_CLUSTER_NAME=$(E2E_TEST_CLUSTER_NAME) E2E_TEST_KUBECTL_CONTEXT=$(E2E_TEST_KUBECTL_CONTEXT) $(MAKE) _ginkgo_test GO_TEST_REPORT_NAME=$@ \
GINKGO_TEST_ARGS="--flake-attempts=3 --timeout=25m controllers"
# Test chaosli API portability
chaosli-test:
docker buildx build -f ./cli/chaosli/chaosli.DOCKERFILE -t test-chaosli-image .
# Go actions
## Generate manifests e.g. CRD, RBAC etc.
manifests: install-controller-gen install-yamlfmt
controller-gen rbac:roleName=chaos-controller crd:crdVersions=v1 paths="./..." output:crd:dir=./chart/templates/generated/ output:rbac:dir=./chart/templates/generated/
# ensure generated files stays formatted as expected
yamlfmt chart/templates/generated
## Run go fmt against code
fmt:
go fmt ./...
## Run go vet against code
vet:
go vet ./...
## Run golangci-lint against code
lint: install-golangci-lint
# By using GOOS=linux we aim to validate files as if we were on linux
# you can use a similar trick with gopls to have vs-code linting your linux platform files instead of darwin
GOOS=linux golangci-lint run --no-config -E ginkgolinter ./...
GOOS=linux golangci-lint run
## Generate code
generate: install-controller-gen
controller-gen object:headerFile=./hack/boilerplate.go.txt paths="./..."
# Lima actions
## Create a new lima cluster and deploy the chaos-controller into it
lima-all: lima-start lima-install-datadog-agent lima-install-cert-manager lima-push-all lima-install
kubens chaos-engineering
## Rebuild the chaos-controller images, re-install the chart and restart the chaos-controller pods
lima-redeploy: lima-push-all lima-install lima-restart
## Install cert-manager chart
lima-install-cert-manager:
$(KUBECTL) apply -f https://github.com/jetstack/cert-manager/releases/download/v1.9.1/cert-manager.yaml
$(KUBECTL) -n cert-manager rollout status deployment/cert-manager-webhook --timeout=180s
lima-install-demo:
$(KUBECTL) apply -f - < ./examples/namespace.yaml
$(KUBECTL) apply -f - < ./examples/demo.yaml
$(KUBECTL) -n chaos-demo rollout status deployment/demo-curl --timeout=60s
$(KUBECTL) -n chaos-demo rollout status deployment/demo-nginx --timeout=60s
## Install CRDs and controller into a lima k3s cluster
## In order to use already built images inside the containerd runtime
## we override images for all of our components to the expected namespace
lima-install: manifests
helm template \
--set=controller.version=$(CONTAINER_VERSION) \
--set=controller.metricsSink=$(LIMA_INSTALL_SINK) \
--set=controller.profilerSink=$(LIMA_INSTALL_SINK) \
--set=controller.tracerSink=$(LIMA_INSTALL_SINK) \
--values ./chart/values/$(HELM_VALUES) \
./chart | $(KUBECTL) apply -f -
ifneq (local.yaml,$(HELM_VALUES)) # we can only wait for a controller if it exists, local.yaml does not deploy the controller
$(KUBECTL) -n chaos-engineering rollout status deployment/chaos-controller --timeout=60s
endif
## Uninstall CRDs and controller from a lima k3s cluster
lima-uninstall:
helm template --set=skipNamespace=true --values ./chart/values/$(HELM_VALUES) ./chart | $(KUBECTL) delete -f -
## Restart the chaos-controller pod
lima-restart:
ifneq (local.yaml,$(HELM_VALUES)) # we can only wait for a controller if it exists, local.yaml does not deploy the controller
$(KUBECTL) -n chaos-engineering rollout restart deployment/chaos-controller
$(KUBECTL) -n chaos-engineering rollout status deployment/chaos-controller --timeout=60s
endif
## Remove lima references from kubectl config
lima-kubectx-clean:
-kubectl config delete-cluster ${LIMA_PROFILE}
-kubectl config delete-context ${LIMA_PROFILE}
-kubectl config delete-user ${LIMA_PROFILE}
kubectl config unset current-context
lima-kubectx:
limactl shell $(LIMA_INSTANCE) sudo sed 's/default/lima/g' /etc/rancher/k3s/k3s.yaml > ~/.kube/config_lima
KUBECONFIG=${KUBECONFIG}:~/.kube/config:~/.kube/config_lima kubectl config view --flatten > /tmp/config
rm ~/.kube/config_lima
mv /tmp/config ~/.kube/config
chmod 600 ~/.kube/config
kubectx ${LIMA_PROFILE}
## Stop and delete the lima cluster
lima-stop:
limactl stop -f $(LIMA_INSTANCE)
limactl delete $(LIMA_INSTANCE)
$(MAKE) lima-kubectx-clean
## Start the lima cluster, pre-cleaning kubectl config
lima-start: lima-kubectx-clean
LIMA_CGROUPS=${LIMA_CGROUPS} LIMA_CONFIG=${LIMA_CONFIG} LIMA_INSTANCE=${LIMA_INSTANCE} ./scripts/lima_start.sh
$(MAKE) lima-kubectx
# Longhorn is used as an alternative StorageClass in order to enable "reliable" disk throttling accross various local setup
# It aims to bypass some issues encountered with default StorageClass (local-path --> tmpfs) that led to virtual unnamed devices
# unnamed devices are linked to 0 as a major device identifier, that blkio does not support
# https://super-unix.com/unixlinux/can-you-throttle-the-bandwidth-to-a-tmpfs-based-ramdisk/
lima-install-longhorn:
$(KUBECTL) apply -f https://raw.githubusercontent.com/longhorn/longhorn/v1.4.0/deploy/longhorn.yaml
# CI-specific actions
venv:
test -d .venv || python3 -m venv .venv
. .venv/bin/activate; pip install -qr tasks/requirements.txt
header: venv
. .venv/bin/activate; inv header-check
header-fix:
# First re-generate header, it should complain as just (re)generated mocks does not contains them
-$(MAKE) header
# Then, re-generate header, it should succeed as now all files contains headers as expected, and command return with an happy exit code
$(MAKE) header
license: venv
. .venv/bin/activate; inv license-check
godeps:
go mod tidy; go mod vendor
deps: godeps license
generate-disruptionlistener-protobuf:
cd grpc/disruptionlistener && \
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1 && \
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0 && \
protoc --proto_path=. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative disruptionlistener.proto
generate-chaosdogfood-protobuf:
cd dogfood/chaosdogfood && \
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1 && \
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0 && \
protoc --proto_path=. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative chaosdogfood.proto
clean-mocks:
find . -type f -name "*mock*.go" -not -path "./vendor/*" -exec rm {} \;
rm -rf mocks/
generate-mocks: clean-mocks install-mockery
go generate ./...
$(MAKE) header-fix
release:
VERSION=$(VERSION) ./tasks/release.sh
_pre_local: generate manifests
@$(shell $(KUBECTL) get deploy chaos-controller 2> /dev/null)
ifeq (0,$(.SHELLSTATUS))
# uninstall using a non local value to ensure deployment is deleted
-$(MAKE) lima-uninstall HELM_VALUES=dev.yaml
$(MAKE) lima-install HELM_VALUES=local.yaml
$(KUBECTL) -n chaos-engineering get cm chaos-controller -oyaml | yq '.data["config.yaml"]' > .local.yaml
yq -i '.controller.webhook.certDir = "chart/certs"' .local.yaml
else
@echo "Chaos controller is not installed, skipped!"
endif
debug: _pre_local
@echo "now you can launch through vs-code or your favorite IDE a controller in debug with appropriate configuration (--config=chart/values/local.yaml + CONTROLLER_NODE_NAME=local)"
run:
CONTROLLER_NODE_NAME=local go run . --config=.local.yaml
watch: _pre_local install-watchexec
watchexec make SKIP_EBPF=true lima-push-injector run
install-protobuf:
curl -sSLo /tmp/${PROTOC_ZIP} https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/${PROTOC_ZIP}
unzip -o /tmp/${PROTOC_ZIP} -d ${GOPATH} bin/protoc
unzip -o /tmp/${PROTOC_ZIP} -d ${GOPATH} 'include/*'
rm -f /tmp/${PROTOC_ZIP}
install-golangci-lint:
ifneq ($(GOLANGCI_LINT_VERSION),$(GOLANGCI_LINT_INSTALLED_VERSION))
$(info golangci-lint version $(GOLANGCI_LINT_VERSION) is not installed or version differ ($(GOLANGCI_LINT_VERSION) != $(GOLANGCI_LINT_INSTALLED_VERSION)))
$(info installing golangci-lint v$(GOLANGCI_LINT_VERSION)...)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v$(GOLANGCI_LINT_VERSION)
endif
install-kubebuilder:
# download kubebuilder and install locally.
curl -sSLo $(GOBIN)/kubebuilder https://go.kubebuilder.io/dl/latest/$(GOOS)/$(GOARCH)
chmod u+x $(GOBIN)/kubebuilder
# download setup-envtest and install related binaries locally
go install -v sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
# setup-envtest use -p path $(KUBERNETES_MAJOR_VERSION).x
install-helm:
ifneq ($(HELM_INSTALLED_VERSION),$(HELM_VERSION))
$(info helm version $(HELM_VERSION) is not installed or version differ ($(HELM_VERSION) != $(HELM_INSTALLED_VERSION)))
$(info installing helm $(HELM_VERSION)...)
curl -sSLo /tmp/helm.tar.gz "https://get.helm.sh/helm-$(HELM_VERSION)-$(GOOS)-$(GOARCH).tar.gz"
tar -xvzf /tmp/helm.tar.gz --directory=$(GOBIN) --strip-components=1 $(GOOS)-$(GOARCH)/helm
rm /tmp/helm.tar.gz
endif
# install controller-gen expected version
install-controller-gen:
ifneq ($(CONTROLLER_GEN_INSTALLED_VERSION),$(CONTROLLER_GEN_VERSION))
$(info controller-gen version $(CONTROLLER_GEN_VERSION) is not installed or version differ ($(CONTROLLER_GEN_VERSION) != $(CONTROLLER_GEN_INSTALLED_VERSION)))
$(info installing controller-gen $(CONTROLLER_GEN_VERSION)...)
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
CGO_ENABLED=0 go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
endif
install-datadog-ci:
curl -L --fail "https://github.com/DataDog/datadog-ci/releases/latest/download/datadog-ci_$(GOOS)-x64" --output "$(GOBIN)/datadog-ci" && chmod u+x $(GOBIN)/datadog-ci
install-mockery:
# recommended way to install mockery is through their released binaries, NOT go install...
# https://vektra.github.io/mockery/installation/#github-release
ifneq ($(MOCKERY_INSTALLED_VERSION),v$(MOCKERY_VERSION))
$(info mockery version $(MOCKERY_VERSION) is not installed or version differ (v$(MOCKERY_VERSION) != $(MOCKERY_INSTALLED_VERSION)))
$(info installing mockery v$(MOCKERY_VERSION)...)
curl -sSLo /tmp/mockery.tar.gz https://github.com/vektra/mockery/releases/download/v$(MOCKERY_VERSION)/mockery_$(MOCKERY_VERSION)_$(GOOS)_$(MOCKERY_ARCH).tar.gz
tar -xvzf /tmp/mockery.tar.gz --directory=$(GOBIN) mockery
rm /tmp/mockery.tar.gz
endif
YAMLFMT_ARCH = $(GOARCH)
ifeq (amd64,$(GOARCH))
YAMLFMT_ARCH = x86_64
endif
install-yamlfmt:
ifeq (,$(wildcard $(GOBIN)/yamlfmt))
$(info installing yamlfmt...)
curl -sSLo /tmp/yamlfmt.tar.gz https://github.com/google/yamlfmt/releases/download/v0.9.0/yamlfmt_0.9.0_$(GOOS)_$(YAMLFMT_ARCH).tar.gz
tar -xvzf /tmp/yamlfmt.tar.gz --directory=$(GOBIN) yamlfmt
rm /tmp/yamlfmt.tar.gz
endif
install-watchexec:
ifeq (,$(wildcard $(GOBIN)/watchexec))
$(info installing watchexec...)
brew install watchexec
endif
install-go:
BUILDGOVERSION=$(BUILDGOVERSION) ./scripts/install-go
EXISTING_NAMESPACE = $(shell $(KUBECTL) get ns datadog-agent -oname || echo "")
lima-install-datadog-agent:
ifeq (true,$(INSTALL_DATADOG_AGENT))
ifeq (,$(EXISTING_NAMESPACE))
$(KUBECTL) create ns datadog-agent
helm repo add --force-update datadoghq https://helm.datadoghq.com
helm install -n datadog-agent my-datadog-operator datadoghq/datadog-operator
$(KUBECTL) create secret -n datadog-agent generic datadog-secret --from-literal api-key=${STAGING_DATADOG_API_KEY} --from-literal app-key=${STAGING_DATADOG_APP_KEY}
endif
$(KUBECTL) apply -f - < examples/datadog-agent.yaml
endif
open-dd:
ifeq (true,$(INSTALL_DATADOG_AGENT))
ifdef STAGING_DD_SITE
open "${STAGING_DD_SITE}/infrastructure?host=lima-$(LIMA_INSTANCE)&tab=details"
else
@echo "You need to define STAGING_DD_SITE in your .zshrc or similar to use this feature"
endif
endif