forked from deckhouse/deckhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
846 lines (723 loc) · 37 KB
/
Copy pathMakefile
File metadata and controls
846 lines (723 loc) · 37 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
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
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
export PATH := $(abspath bin/):${PATH}
FORMATTING_BEGIN_YELLOW = \033[0;33m
FORMATTING_BEGIN_BLUE = \033[36m
FORMATTING_END = \033[0m
FOCUS =
MDLINTER_IMAGE = ghcr.io/igorshubovych/markdownlint-cli@sha256:2e22b4979347f70e0768e3fef1a459578b75d7966e4b1a6500712b05c5139476
SPELLCHECKER_IMAGE = registry.deckhouse.ru/base_images/hunspell:1.7.0-r1-alpine@sha256:f419f1dc5b55cd9c0038ece60612549e64333bb0a0e7d4764d45ed94336dec9c
# Explicitly set architecture on arm, since werf currently does not support building of images for any other platform
# besides linux/amd64 (e.g. relevant for mac m1).
PLATFORM_NAME := $(shell uname -m)
OS_NAME := $(shell uname)
ifneq ($(filter arm%,$(PLATFORM_NAME)),)
export WERF_PLATFORM=linux/amd64
endif
# Set platform for deps
ifeq ($(OS_NAME), Linux)
JQ_PLATFORM = linux64
YQ_PLATFORM = linux
TRDL_PLATFORM = linux
GH_PLATFORM = linux
else ifeq ($(OS_NAME), Darwin)
JQ_PLATFORM = osx-amd64
YQ_PLATFORM = darwin
TRDL_PLATFORM = darwin
GH_PLATFORM = macOS
endif
JQ_VERSION = 1.6
# Set arch for deps
ifeq ($(PLATFORM_NAME), x86_64)
YQ_ARCH = amd64
CRANE_ARCH = x86_64
TRDL_ARCH = amd64
CRANE_ARCH = x86_64
GH_ARCH = amd64
else ifeq ($(PLATFORM_NAME), aarch64)
YQ_ARCH = amd64
CRANE_ARCH = x86_64
TRDL_ARCH = amd64
CRANE_ARCH = x86_64
GH_ARCH = amd64
else ifeq ($(PLATFORM_NAME), arm64)
YQ_ARCH = arm64
CRANE_ARCH = arm64
TRDL_ARCH = arm64
CRANE_ARCH = arm64
GH_ARCH = arm64
endif
# Set proxy for github
ifeq ($(DISTRO_PACKAGES_PROXY),)
GITHUB_URL = https://github.com
else
GITHUB_URL = http://$(DISTRO_PACKAGES_PROXY)/repository/github-com
endif
# Set testing path for tests-modules
ifeq ($(FOCUS),)
TESTS_PATH = ./modules/... ./global-hooks/... ./ee/modules/... ./ee/fe/modules/... ./ee/be/modules/... ./ee/se/modules/... ./ee/se-plus/modules/...
else
CE_MODULES = $(shell find ./modules -maxdepth 1 -regex ".*[0-9]-${FOCUS}")
ifneq ($(CE_MODULES),)
CE_MODULES_RECURSE = ${CE_MODULES}/...
endif
EE_MODULES = $(shell find ./ee/modules -maxdepth 1 -regex ".*[0-9]-${FOCUS}")
ifneq ($(EE_MODULES),)
EE_MODULES_RECURSE = ${EE_MODULES}/...
endif
FE_MODULES = $(shell find ./ee/fe/modules -maxdepth 1 -regex ".*[0-9]-${FOCUS}")
ifneq ($(FE_MODULES),)
FE_MODULES_RECURSE = ${FE_MODULES}/...
endif
BE_MODULES = $(shell find ./ee/be/modules -maxdepth 1 -regex ".*[0-9]-${FOCUS}")
ifneq ($(FE_MODULES),)
BE_MODULES_RECURSE = ${BE_MODULES}/...
endif
SE_MODULES = $(shell find ./ee/se/modules -maxdepth 1 -regex ".*[0-9]-${FOCUS}")
ifneq ($(FE_MODULES),)
SE_MODULES_RECURSE = ${SE_MODULES}/...
endif
SE_PLUS_MODULES = $(shell find ./ee/se-plus/modules -maxdepth 1 -regex ".*[0-9]-${FOCUS}")
ifneq ($(FE_MODULES),)
SE_PLUS_MODULES_RECURSE = ${SE_PLUS_MODULES}/...
endif
TESTS_PATH = ${CE_MODULES_RECURSE} ${EE_MODULES_RECURSE} ${FE_MODULES_RECURSE} ${BE_MODULES_RECURSE} ${SE_MODULES_RECURSE}
endif
# Set host arch & OS for golang-based programs, e.g. Prometheus
ifneq (, $(shell which go))
GOHOSTARCH := $(shell go env GOHOSTARCH)
GOHOSTOS := $(shell go env GOHOSTOS)
endif
help:
@printf -- "${FORMATTING_BEGIN_BLUE}%s${FORMATTING_END}\n" \
"" \
" ██████╗░███████╗░█████╗░██╗░░██╗██╗░░██╗░█████╗░██╗░░░██╗░██████╗███████╗" \
" ██╔══██╗██╔════╝██╔══██╗██║░██╔╝██║░░██║██╔══██╗██║░░░██║██╔════╝██╔════╝" \
" ██║░░██║█████╗░░██║░░╚═╝█████═╝░███████║██║░░██║██║░░░██║╚█████╗░█████╗░░" \
" ██║░░██║██╔══╝░░██║░░██╗██╔═██╗░██╔══██║██║░░██║██║░░░██║░╚═══██╗██╔══╝░░" \
" ██████╔╝███████╗╚█████╔╝██║░╚██╗██║░░██║╚█████╔╝╚██████╔╝██████╔╝███████╗" \
" ╚═════╝░╚══════╝░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝░╚════╝░░╚═════╝░╚═════╝░╚══════╝" \
"" \
"-----------------------------------------------------------------------------------" \
""
@awk 'BEGIN {\
FS = ":.*##"; \
printf "Usage: ${FORMATTING_BEGIN_BLUE}OPTION${FORMATTING_END}=<value> make ${FORMATTING_BEGIN_YELLOW}<target>${FORMATTING_END}\n"\
} \
/^[a-zA-Z0-9_-]+:.*?##/ { printf " ${FORMATTING_BEGIN_BLUE}%-46s${FORMATTING_END} %s\n", $$1, $$2 } \
/^.?.?##~/ { printf " %-46s${FORMATTING_BEGIN_YELLOW}%-46s${FORMATTING_END}\n", "", substr($$1, 6) } \
/^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
TRIVY_VERSION= 0.67.2
PROMTOOL_VERSION = 2.37.0
GATOR_VERSION = 3.22.0
OPA_VERSION = 1.15.1
GH_VERSION = 2.83.2
TESTS_TIMEOUT="15m"
##@ General
deps: bin/golangci-lint bin/trivy bin/regcopy bin/jq bin/yq bin/crane bin/promtool bin/gator bin/opa bin/werf bin/gh ## Install dev dependencies.
##@ Security
bin:
mkdir -p bin
##@ Tests
bin/promtool-${PROMTOOL_VERSION}/promtool:
mkdir -p bin/promtool-${PROMTOOL_VERSION}
curl -sSfL $(GITHUB_URL)/prometheus/prometheus/releases/download/v${PROMTOOL_VERSION}/prometheus-${PROMTOOL_VERSION}.${GOHOSTOS}-${GOHOSTARCH}.tar.gz -o - | tar zxf - -C bin/promtool-${PROMTOOL_VERSION} --strip=1 prometheus-${PROMTOOL_VERSION}.${GOHOSTOS}-${GOHOSTARCH}/promtool
.PHONY: bin/promtool
bin/promtool: bin/promtool-${PROMTOOL_VERSION}/promtool
rm -f bin/promtool
ln -s promtool-${PROMTOOL_VERSION}/promtool bin/promtool
bin/gator-${GATOR_VERSION}/gator:
mkdir -p bin/gator-${GATOR_VERSION}
curl -sSfL $(GITHUB_URL)/open-policy-agent/gatekeeper/releases/download/v${GATOR_VERSION}/gator-v${GATOR_VERSION}-${GOHOSTOS}-${GOHOSTARCH}.tar.gz -o - | tar zxf - -C bin/gator-${GATOR_VERSION} gator
.PHONY: bin/gator
bin/gator: bin/gator-${GATOR_VERSION}/gator
rm -f bin/gator
ln -s /deckhouse/bin/gator-${GATOR_VERSION}/gator bin/gator
bin/opa-${OPA_VERSION}/opa:
mkdir -p bin/opa-${OPA_VERSION}
curl -sSfL https://openpolicyagent.org/downloads/v${OPA_VERSION}/opa_${GOHOSTOS}_${GOHOSTARCH}_static -o bin/opa-${OPA_VERSION}/opa
chmod +x bin/opa-${OPA_VERSION}/opa
.PHONY: bin/opa
bin/opa: bin/opa-${OPA_VERSION}/opa
rm -f bin/opa
ln -s /deckhouse/bin/opa-${OPA_VERSION}/opa bin/opa
.PHONY: bin/yq
bin/yq: bin ## Install yq deps for update-patchversion script.
curl -sSfL $(GITHUB_URL)/mikefarah/yq/releases/download/v4.25.3/yq_$(YQ_PLATFORM)_$(YQ_ARCH) -o bin/yq && chmod +x bin/yq
.PHONY: tests-modules dmt-lint tests-openapi tests-controller tests-webhooks
tests-modules: bin/gator bin/opa gotestsum ## Run unit tests for modules hooks and templates.
##~ Options: FOCUS=module-name
$(GOTESTSUM) -- -cover -race -timeout=${TESTS_TIMEOUT} -vet=off ${TESTS_PATH}
dmt-lint:
export DMT_METRICS_URL="${DMT_METRICS_URL}"
export DMT_METRICS_TOKEN="${DMT_METRICS_TOKEN}"
docker run --rm -v ${PWD}:/deckhouse-src -e DMT_METRICS_URL="${DMT_METRICS_URL}" -e DMT_METRICS_TOKEN="${DMT_METRICS_TOKEN}" --user $(id -u):$(id -g) ubuntu /deckhouse-src/tools/dmt-lint.sh
tests-openapi: ## Run tests against modules openapi values schemas.
go test -timeout=${TESTS_TIMEOUT} -vet=off ./testing/openapi_cases/
tests-controller: gotestsum ## Run deckhouse-controller unit tests.
$(GOTESTSUM) -- -cover -race -timeout=${TESTS_TIMEOUT} ./deckhouse-controller/... -v
tests-webhooks: bin/yq ## Run python webhooks unit tests.
./testing/webhooks/run.sh
.PHONY: test-all
test-all: go-check gotestsum
$(call iterateAllGoModules,Running go test with race and cover in,$(GOTESTSUM) -- -cover -race -timeout=${TESTS_TIMEOUT} ./...)
.PHONY: test-draft-all
test-draft-all: go-check gotestsum
$(call iterateAllGoModules,Running go test in,$(GOTESTSUM) -- ./...)
.PHONY: validate
validate: ## Check common patterns through all modules.
go test -tags=validation -run Validation -timeout=${TESTS_TIMEOUT} ./testing/...
bin/golangci-lint:
mkdir -p bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | BINARY=golangci-lint bash -s -- ${GOLANGCI_LINT_VERSION}
.PHONY: lint lint-fix
lint: golangci-lint ## Run linter.
golangci-lint run
lint-fix: golangci-lint ## Fix lint violations.
golangci-lint run --fix
# Generic function to iterate over all directories with go.mod
# Usage: $(call iterateAllGoModules,message,command)
define iterateAllGoModules
@FAILED=0; \
for dir in $$(find . -name "go.mod" -type f -exec dirname {} \; ); do \
echo ""; \
echo "============================================================"; \
echo "$(1) in $$dir"; \
echo "============================================================"; \
echo ""; \
(cd $$dir && $(2)) || FAILED=1; \
done; \
exit $$FAILED
endef
.PHONY: lint-all
lint-all: golangci-lint check-dhctl-cmd-drift ## Run golangci-lint run in all directories with go.mod
$(call iterateAllGoModules,Running golangci-lint in,GOFLAGS="-buildvcs=false" golangci-lint run --max-issues-per-linter 100 --max-same-issues 100)
.PHONY: lint-changed
lint-changed: check-dhctl-cmd-drift ## Lint only Go modules touched by diff against DIFF_BASE (default: HEAD~1).
##~ Uses the golangci-lint already on PATH (the CI tests image ships one);
##~ run `make golangci-lint` first if you don't have it locally.
@bash tools/lint-changed.sh
.PHONY: lint-fix-all
lint-fix-all: golangci-lint ## Run golangci-lint run --fix in all directories with go.mod
$(call iterateAllGoModules,Running golangci-lint --fix in,GOFLAGS="-buildvcs=false" golangci-lint run --fix --max-issues-per-linter 100 --max-same-issues 100)
.PHONY: check-dhctl-cmd-drift
check-dhctl-cmd-drift: ## Verify dhctl ↔ deckhouse-controller CLI command-builder duplicates are in sync.
@bash tools/check-dhctl-cmd-drift.sh
.PHONY: --lint-markdown-header lint-markdown lint-markdown-fix
--lint-markdown-header:
@docker pull -q ${MDLINTER_IMAGE}
@echo "\n######################################################################################################################"
@echo '###'
@echo "### Markdown linter report (powered by https://github.com/DavidAnson/markdownlint/)\n"
lint-markdown: --lint-markdown-header ## Run markdown linter.
@bash -c \
"if docker run --rm -v ${PWD}:/workdir ${MDLINTER_IMAGE} --config testing/markdownlint.yaml -p testing/.markdownlintignore '**/*.md' ; then \
echo; echo 'All checks passed.'; \
else \
echo; \
echo 'To run linter locally and fix common problems run: make lint-markdown-fix'; \
echo; \
exit 1; \
fi"
lint-markdown-fix: ## Run markdown linter and fix problems automatically.
@docker run --rm -v ${PWD}:/workdir ${MDLINTER_IMAGE} \
--config testing/markdownlint.yaml -p testing/.markdownlintignore "**/*.md" --fix && (echo 'Fixed successfully.')
lint-src-artifact: set-build-envs ## Run src-artifact stapel linter
@bin/werf config render | awk 'NR!=1 {print}' | go run ./tools/lint-src-artifact/lint-src-artifact.go
##@ Generate
## Run all generate-* jobs in bulk.
.PHONY: generate render-workflow
generate: generate-kubernetes generate-tools generate-docs dmt-gen generate-werf
.PHONY: generate-tools
generate-tools: yq
cd tools && go generate -v && cd ..
render-workflow: ## Generate CI workflow instructions.
./.github/render-workflows.sh
bin/regcopy: bin ## App to copy docker images to the Deckhouse registry
cd tools/regcopy; go build -o bin/regcopy
bin/trivy-${TRIVY_VERSION}/trivy:
mkdir -p bin/trivy-${TRIVY_VERSION}
curl ${DECKHOUSE_PRIVATE_REPO}/api/v4/projects/${TRIVY_PROJECT_ID}/packages/generic/trivy-v${TRIVY_VERSION}/v${TRIVY_VERSION}/trivy -o bin/trivy-${TRIVY_VERSION}/trivy
.PHONY: trivy
bin/trivy: bin bin/trivy-${TRIVY_VERSION}/trivy
rm -rf bin/trivy
chmod u+x bin/trivy-${TRIVY_VERSION}/trivy
ln -s ${PWD}/bin/trivy-${TRIVY_VERSION}/trivy bin/trivy
.PHONY: cve-report
cve-report: bin/trivy bin/jq ## Generate CVE report for a Deckhouse release.
##~ Options: SEVERITY=CRITICAL,HIGH REPO=registry.deckhouse.io TAG=v1.30.0
./tools/cve/d8_images_cve_scan.sh
cve-base-images-check-default-user: bin/jq ## Check CVE in our base images.
##~ Options: SEVERITY=CRITICAL,HIGH
./tools/cve/check-non-root.sh
##@ Documentation
MODULE_PATH ?=
CHANNEL ?= alpha
MODULE_VERSION ?= v0.1.0
DOC_VERSION ?=
.PHONY: docs
docs: bin/werf ## Run containers with the documentation.
@echo "Building documentation containers..."
@echo -n "werf: "; bin/werf version
@$(MAKE) -C docs/site free-port-80
@cd docs/site/; ../../bin/werf compose up --docker-compose-command-options='-d' --env local --repo ":local" --skip-image-spec-stage=true
echo "Open http://localhost/products/kubernetes-platform/documentation/v1/ to access DKP documentation..."
.PHONY: docs-generate-pdf
docs-generate-pdf: ## Generate PDF documentation.
##~ Options: DOC_VERSION=X.XX - DKP version (used just in PDF headers and footers). If not set, the version is determined from the git branch name.
##~ Options: BUILD_LANG=ru|en - build a single language only. If not set, both languages are built.
##~ Outputs: pdf/deckhouse-admin-guide_{ru,en}.pdf and pdf/deckhouse-user-guide_{ru,en}.pdf
DOC_VERSION="$(strip $(DOC_VERSION))" \
BUILD_LANG="$(strip $(BUILD_LANG))" \
bash tools/docs/pdf/generate-pdf.sh
.PHONY: docs-external-module
docs-external-module: yq bin/werf ## Build an external module docs and run the local portal.
##~ Options: MODULE_PATH=/path/to/module [CHANNEL=alpha] [MODULE_VERSION=v0.1.0]
MODULE_PATH="$(MODULE_PATH)" CHANNEL="$(CHANNEL)" MODULE_VERSION="$(MODULE_VERSION)" ./tools/docs/external-module-docs.sh
@echo "Building documentation containers..."
@echo -n "werf: "; bin/werf version
@$(MAKE) -C docs/site free-port-80
@cd docs/site/; ../../bin/werf compose up --docker-compose-command-options='-d' --env local --repo ":local" --skip-image-spec-stage=true
echo "Open http://localhost/products/kubernetes-platform/documentation/v1/ to access DKP documentation..."
.PHONY: docs-external-module-clean
docs-external-module-clean: ## Remove generated external module documentation output.
rm -rf docs/site/backends/docs-builder-template/public
@echo "Removed docs/site/backends/docs-builder-template/public"
.PHONY: docs-dev
docs-dev: bin/werf ## Run containers with the documentation in the dev mode (allow uncommited files).
@echo "Building documentation containers (dev mode)..."
@echo -n "werf: "; bin/werf version;
@$(MAKE) -C docs/site free-port-80
@cd docs/site/; ../../bin/werf compose up --docker-compose-command-options='-d' --dev --env development --repo ":local" --skip-image-spec-stage=true
echo "Open http://localhost/products/kubernetes-platform/documentation/v1/ to access DKP documentation..."
.PHONY: docs-down
docs-down: ## Stop all the documentation containers (e.g. site_site_1 - for Linux, and site-site-1 for MacOs)
echo "Removing documentation related containers..."
@docker rm -f site-site-1 site_site_1 site-router-1 site_router_1 site-front-1 site_front_1 site-frontend-1 site_frontend_1 2>/dev/null || true ; docker network rm deckhouse 2>/dev/null || true
.PHONY: tests-doc-links
docs-linkscheck: ## Build documentation and run checker of html links.
@bash tools/docs/link-checker/run.sh
.PHONY: docs-spellcheck
docs-spellcheck: ## Check the spelling in the documentation.
##~ Options: file="path/to/file" (Specify a path to a specific file)
@docker run --rm -v ${PWD}:/spelling -v ${PWD}/tools/docs/spelling:/app ${SPELLCHECKER_IMAGE} /app/spell_check.sh -f $(file)
lint-doc-spellcheck-pr:
@docker run --rm -v ${PWD}:/spelling -v ${PWD}/tools/docs/spelling:/app ${SPELLCHECKER_IMAGE} /app/check_diff.sh
.PHONY: docs-spellcheck-generate-dictionary
docs-spellcheck-generate-dictionary: ## Generate a dictionary (run it after adding new words to the tools/docs/spelling/wordlist file).
@echo "Sorting wordlist..."
@sort ./tools/docs/spelling/wordlist -o ./tools/docs/spelling/wordlist
@echo "Validating wordlist..."
@./tools/docs/spelling/validate_wordlist.sh
@echo "Generating dictionary..."
@test -f ./tools/docs/spelling/dictionaries/dev_OPS.dic && rm ./tools/docs/spelling/dictionaries/dev_OPS.dic
@touch ./tools/docs/spelling/dictionaries/dev_OPS.dic
@cat ./tools/docs/spelling/wordlist | wc -l | sed 's/^[ \t]*//g' > ./tools/docs/spelling/dictionaries/dev_OPS.dic
@sort ./tools/docs/spelling/wordlist >> ./tools/docs/spelling/dictionaries/dev_OPS.dic
@echo "Don't forget to commit changes and push it!"
@git diff --stat
.PHONY: docs-spellcheck-get-typos-list
docs-spellcheck-get-typos-list: ## Print out a list of all the terms in all pages that were considered as a typo.
@echo "Please wait a bit. It may take about 20 minutes and there may be no output in the terminal..." && \
docker run --rm -v ${PWD}:/spelling --entrypoint /bin/bash -v ${PWD}/tools/docs/spelling:/app ${SPELLCHECKER_IMAGE} -c "/app/spell_check.sh 2>/dev/null | sed '/Spell-checking the documentation/ d; /^Possible typos/d' | sort -u"
##@ Update kubernetes control-plane patchversions
bin/jq-$(JQ_VERSION)/jq:
mkdir -p bin/jq-$(JQ_VERSION)
curl -sSfL $(GITHUB_URL)/stedolan/jq/releases/download/jq-$(JQ_VERSION)/jq-$(JQ_PLATFORM) -o $(PWD)/bin/jq-$(JQ_VERSION)/jq && chmod +x $(PWD)/bin/jq-$(JQ_VERSION)/jq
.PHONY: bin/jq
bin/jq: bin bin/jq-$(JQ_VERSION)/jq ## Install jq deps for update-patchversion script.
rm -f bin/jq
ln -s jq-$(JQ_VERSION)/jq bin/jq
bin/crane: bin ## Install crane deps for update-patchversion script.
curl -sSfL $(GITHUB_URL)/google/go-containerregistry/releases/download/v0.10.0/go-containerregistry_$(OS_NAME)_$(CRANE_ARCH).tar.gz | tar -xzf - crane && mv crane bin/crane && chmod +x bin/crane
bin/trdl: bin
@if ! command -v bin/trdl >/dev/null 2>&1; then \
curl -sSfL https://tuf.trdl.dev/targets/releases/0.7.0/$(TRDL_PLATFORM)-$(TRDL_ARCH)/bin/trdl -o bin/trdl; \
chmod +x bin/trdl; \
fi
bin/werf: bin bin/trdl ## Install werf for images-digests generator.
@bash -c 'bin/trdl --home-dir bin/.trdl add werf https://tuf.werf.io 1 b7ff6bcbe598e072a86d595a3621924c8612c7e6dc6a82e919abe89707d7e3f468e616b5635630680dd1e98fc362ae5051728406700e6274c5ed1ad92bea52a2';
@if command -v bin/werf >/dev/null 2>&1; then \
bin/trdl --home-dir bin/.trdl --no-self-update=true update --in-background werf 2 alpha; \
else \
bin/trdl --home-dir bin/.trdl --no-self-update=true update werf 2 alpha; \
ln -sf $$(bin/trdl --home-dir bin/.trdl bin-path werf 2 alpha | sed 's|^.*/bin/\(.trdl.*\)|\1/werf|') bin/werf; \
fi;
bin/gh: bin ## Install gh cli.
ifeq ($(OS_NAME), Darwin)
curl -sSfL $(GITHUB_URL)/cli/cli/releases/download/v$(GH_VERSION)/gh_$(GH_VERSION)_$(GH_PLATFORM)_$(GH_ARCH).zip -o bin/gh.zip
unzip -d bin -oj bin/gh.zip gh_$(GH_VERSION)_$(GH_PLATFORM)_$(GH_ARCH)/bin/gh
rm bin/gh.zip
else
curl -sSfL $(GITHUB_URL)/cli/cli/releases/download/v$(GH_VERSION)/gh_$(GH_VERSION)_$(GH_PLATFORM)_$(GH_ARCH).tar.gz -o bin/gh.tar.gz
tar zxf bin/gh.tar.gz -C bin/ && ln -s bin/gh_$(GH_VERSION)_$(GH_PLATFORM)_$(GH_ARCH)/bin/gh bin/gh
rm bin/gh.tar.gz
endif
.PHONY: update-k8s-patch-versions
update-k8s-patch-versions: ## Run update-patchversion script to generate new version_map.yml.
cd candi/tools; bash update_kubernetes_patchversions.sh
##@ Lib helm
.PHONY: update-lib-helm
update-lib-helm: yq ## Update lib-helm.
##~ Options: version=MAJOR.MINOR.PATCH
cd helm_lib/ && yq -i '.dependencies[0].version = "$(version)"' Chart.yaml && helm dependency update && tar -xf charts/deckhouse_lib_helm-*.tgz -C charts/ && rm charts/deckhouse_lib_helm-*.tgz && git add Chart.yaml Chart.lock charts/*
.PHONY: update-base-images-versions
update-base-images-versions:
##~ Options: version=vMAJOR.MINOR.PATCH
cd candi && curl --fail -sSLO https://fox.flant.com/api/v4/projects/deckhouse%2Fbase-images/packages/generic/base_images/$(version)/base_images.yml
$(MAKE) render-workflow
BASE_LIMIT_KEYS := REGISTRY_PATH \
base/distroless \
builder/distroless \
builder/golang-1.25 \
builder/golang-1.26 \
builder/golang \
minget-0.1 \
minget
.PHONY: update-container-factory
update-container-factory: ## Download container-factory digests and update candi/alt_base_images.yml
@set -e; \
test -n "$(version)" || (echo 'Err: version is required. Example: make update-container-factory version=v1.0.37' >&2; exit 1); \
ver="$(version)"; \
case "$$ver" in \
v[0-9]*.[0-9]*.[0-9]*) ;; \
[0-9]*.[0-9]*.[0-9]*) ver="v$$ver" ;; \
esac; \
cd candi; \
URL="https://fox.flant.com/api/v4/projects/deckhouse%2Fcontainer-base%2Fbase-images/packages/generic/base_images/$$ver/base_images.yml"; \
curl --fail -sSL "$$URL" -o .alt_base_images.full.yml; \
{ \
echo "# version=$$ver"; \
for key in $(BASE_LIMIT_KEYS); do \
line=$$(grep -F "$${key}:" .alt_base_images.full.yml | head -n1); \
case "$$key" in \
base/distroless) line=$$(printf '%s\n' "$$line" | sed 's#^base/distroless:#base/distroless-fin:#');; \
esac; \
echo "$$line"; \
done; \
} > alt_base_images.yml; \
rm -f .alt_base_images.full.yml; \
echo "Updated candi/alt_base_images.yml to version $$ver"
##@ Build
.PHONY: build
set-build-envs:
ifeq ($(WERF_ENV),)
export WERF_ENV=FE
endif
ifeq ($(WERF_CHANNEL),)
export WERF_CHANNEL=ea
endif
ifeq ($(DEV_REGISTRY_PATH),)
export DEV_REGISTRY_PATH=dev-registry.deckhouse.io/sys/deckhouse-oss
endif
ifeq ($(SOURCE_REPO),)
export SOURCE_REPO=https://github.com
endif
ifeq ($(CLOUD_PROVIDERS_SOURCE_REPO),)
export CLOUD_PROVIDERS_SOURCE_REPO=https://github.com
endif
ifeq ($(GOPROXY),)
export GOPROXY=https://proxy.golang.org/
endif
# NB: := (simple expansion), not = (recursive). These vars are `export`ed,
# so a recursive definition makes `make` re-run the `$(shell git ...)` while
# building the environment for *every* $(shell) call in the Makefile —
# thousands of `git` invocations per `make` run, ~9 min on a full-history
# repo. Simple expansion runs each git command exactly once at parse time.
ifeq ($(CI_COMMIT_TAG),)
export CI_COMMIT_TAG := $(shell git describe --abbrev=0 2>/dev/null)
endif
ifeq ($(CI_COMMIT_BRANCH),)
export CI_COMMIT_BRANCH := $(shell git branch --show-current)
endif
ifeq ($(CI_COMMIT_REF_NAME),)
export CI_COMMIT_REF_NAME := $(shell git rev-parse --abbrev-ref HEAD)
else
ifeq ($(CI_COMMIT_TAG),)
export CI_COMMIT_REF_NAME := $(CI_COMMIT_BRANCH)
else
export CI_COMMIT_REF_NAME := $(CI_COMMIT_TAG)
endif
endif
ifeq ($(CI_COMMIT_REF_SLUG),)
export CI_COMMIT_REF_SLUG := $(shell bin/gh pr view $$CI_COMMIT_BRANCH --json number -q .number 2>/dev/null)
endif
ifeq ($(DECKHOUSE_REGISTRY_HOST),)
export DECKHOUSE_REGISTRY_HOST=registry.deckhouse.io
endif
ifeq ($(DECKHOUSE_PRIVATE_REPO),)
export DECKHOUSE_PRIVATE_REPO=https://github.com
endif
export WERF_REPO := $(DEV_REGISTRY_PATH)
export REGISTRY_SUFFIX := $(shell echo $(WERF_ENV) | tr '[:upper:]' '[:lower:]')
export SECONDARY_REPO := --secondary-repo $(DECKHOUSE_REGISTRY_HOST)/deckhouse/$(REGISTRY_SUFFIX)
build: bin/werf set-build-envs ## Build Deckhouse images.
##~ Options: FOCUS=image-name
bin/werf build --parallel=true --parallel-tasks-limit=5 --platform linux/amd64 --save-build-report=true --build-report-path images_tags_werf.json $(SECONDARY_REPO) $(FOCUS)
ifeq ($(FOCUS),)
ifneq ($(CI_COMMIT_REF_SLUG),)
@# By default in the Github CI_COMMIT_REF_SLUG is a 'prNUM' for dev branches.
SRC=$(shell jq -r '.Images."dev".DockerImageName' images_tags_werf.json) && \
DST=$(DEV_REGISTRY_PATH):pr$(CI_COMMIT_REF_SLUG) && \
echo "⚓️ 💫 [$(date -u)] Publish images to dev-registry for branch '$(CI_COMMIT_BRANCH)' and edition '$(WERF_ENV)' using tag '$(CI_COMMIT_REF_SLUG)' ..." && \
echo "⚓️ 💫 [$(date -u)] Publish 'dev' image to dev-registry using tag 'pr$(CI_COMMIT_REF_SLUG)'" && \
docker pull $$SRC && \
docker image tag $$SRC $$DST && \
docker image push $$DST && \
docker image rmi $$DST || true
SRC=$(shell jq -r '.Images."dev/install".DockerImageName' images_tags_werf.json) && \
DST=$(DEV_REGISTRY_PATH)/install:pr$(CI_COMMIT_REF_SLUG) && \
echo "⚓️ 💫 [$(date -u)] Publish 'dev/install' image to dev-registry using tag 'pr$(CI_COMMIT_REF_SLUG)'" && \
docker pull $$SRC && \
docker image tag $$SRC $$DST && \
docker image push $$DST && \
docker image rmi $$DST || true
SRC=$(shell jq -r '.Images."dev/install-standalone".DockerImageName' images_tags_werf.json) && \
DST=$(DEV_REGISTRY_PATH)/install-standalone:pr$(CI_COMMIT_REF_SLUG) && \
echo "⚓️ 💫 [$(date -u)] Publish 'dev/install-standalone' image to dev-registry using tag 'pr$(CI_COMMIT_REF_SLUG)'" && \
docker pull $$SRC && \
docker image tag $$SRC $$DST && \
docker image push $$DST && \
docker image rmi $$DST || true
SRC="$(shell jq -r '.Images."e2e-opentofu-eks".DockerImageName' images_tags_werf.json)" && \
DST="$(DEV_REGISTRY_PATH)/e2e-opentofu-eks:pr$(CI_COMMIT_REF_SLUG)" && \
echo "⚓️ 💫 [$(date -u)] Publish 'e2e-opentofu-eks' image to dev-registry using tag 'pr$(CI_COMMIT_REF_SLUG)'" && \
docker pull $$SRC && \
docker image tag $$SRC $$DST && \
docker image push $$DST && \
docker image rmi $$DST || true
endif
endif
build-render: bin/werf set-build-envs ## render werf.yaml for build Deckhouse images.
echo "Cur dir $$(pwd)"
bin/werf config render --dev
GO=$(shell which go)
GIT=$(shell which git)
.PHONY: go-check
go-check:
$(call error-if-empty,$(GO),go)
.PHONY: go-module-version
go-module-version: go-check
@echo "go get $(shell go list ./deckhouse-controller/cmd/deckhouse-controller)@$(shell git rev-parse HEAD)"
.PHONY: tidy-all
tidy-all: go-check
$(call iterateAllGoModules,Running go mod tidy in,go mod tidy)
##@ Dependencies
WHOAMI ?= $(shell whoami)
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
DECKHOUSE_CLI ?= $(LOCALBIN)/d8
CRD_ENRICHER ?= $(LOCALBIN)/crd-enricher
CRD_ENRICHER_LOCAL ?= $(LOCALBIN)/crd-enricher-local
CRD_ENRICHER_SRC ?= $(CURDIR)/pkg/crd-enricher
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
CLIENT_GEN ?= $(LOCALBIN)/client-gen
INFORMER_GEN ?= $(LOCALBIN)/informer-gen
LISTER_GEN ?= $(LOCALBIN)/lister-gen
YQ = $(LOCALBIN)/yq
GOTESTSUM = $(LOCALBIN)/gotestsum
## TODO: remap in yaml file (version.yaml or smthng)
## Tool Versions
GOLANGCI_LINT_VERSION = v2.8.0
DECKHOUSE_CLI_VERSION ?= v0.33.1
CRD_ENRICHER_VERSION ?= v0.0.1
DMT_VERSION ?= 0.1.95
CONTROLLER_TOOLS_VERSION ?= v0.19.0
CODE_GENERATOR_VERSION ?= v0.34.8
YQ_VERSION ?= v4.47.2
GOTESTSUM_VERSION ?= v1.13.0
## Generate werf
.PHONY: generate-werf
generate-werf: yq ## Generate changes in werf files.
##~ Options: GOLANGCI_LINT_VERSION=vX.Y.Z
@if [ -n "$(GOLANGCI_LINT_VERSION)" ]; then \
sed -i 's/export GOLANGCI_LINT_VERSION=v[0-9.]\+/export GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION)/' .werf/werf-golang-ci-lint.yaml; \
echo "Updated golangci-lint version to $(GOLANGCI_LINT_VERSION) in .werf/werf-golang-ci-lint.yaml"; \
else \
echo "No GOLANGCI_LINT_VERSION specified. Skipping update."; \
fi
## Generate dmt version in dmt-lint.sh
.PHONY: dmt-gen
dmt-gen: ## Update DMT_VERSION in tools/dmt-lint.sh.
##~ Options: DMT_VERSION=X.Y.Z
@sed -i.bak -E 's/DMT_VERSION=[0-9.]+/DMT_VERSION=$(DMT_VERSION)/' tools/dmt-lint.sh && rm -f tools/dmt-lint.sh.bak
@echo "Updated DMT_VERSION to $(DMT_VERSION) in tools/dmt-lint.sh"
## Generate tools documentation
.PHONY: generate-docs
generate-docs: yq deckhouse-cli ## Generate documentation for deckhouse-cli.
@$(DECKHOUSE_CLI) --version
@$(YQ) eval '.d8.d8CliVersion = "$(DECKHOUSE_CLI_VERSION)"' -i ./candi/version_map.yml
@DECKHOUSE_PLUGINS_ENABLED=false HELM_PLUGINS="" $(DECKHOUSE_CLI) help-json --username-replace=$(WHOAMI) > ./docs/documentation/_data/reference/d8-cli.json && echo "d8 help-json content is updated"
## Generate codebase for deckhouse-controllers kubernetes entities
.PHONY: generate-kubernetes
generate-kubernetes: controller-gen-generate client-gen-generate lister-gen-generate informer-gen-generate manifests
## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
.PHONY: controller-gen-generate
controller-gen-generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="./deckhouse-controller/hack/boilerplate.go.txt" paths="./deckhouse-controller/pkg/apis/..."
.PHONY: manifests
## Enriches with the crd-enricher built from THIS repo's source (pkg/crd-enricher)
## rather than a released binary, since the tool and the API structs it reads are
## versioned together here. Pass CRD_ENRICHER_FLAGS to toggle enricher options,
## e.g. CRD_ENRICHER_FLAGS=auto-examples or CRD_ENRICHER_FLAGS=reindent.
manifests: controller-gen enrich-crds-local ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
@$(MAKE) copy-crds
## Copy the enriched CRDs from bin/crd/bases into deckhouse-controller/crds.
## Kept as a standalone target so the enrich and copy steps stay separable and
## the copied file list lives in one place.
.PHONY: copy-crds
copy-crds:
@echo "Copying CRDs to deckhouse-controller/crds..."
@cp bin/crd/bases/deckhouse.io_applications.yaml deckhouse-controller/crds/application.yaml
@cp bin/crd/bases/deckhouse.io_packagerepositoryoperations.yaml deckhouse-controller/crds/packagerepositoryoperation.yaml
@cp bin/crd/bases/deckhouse.io_packagerepositories.yaml deckhouse-controller/crds/packagerepository.yaml
@cp bin/crd/bases/deckhouse.io_applicationpackageversions.yaml deckhouse-controller/crds/applicationpackageversion.yaml
@cp bin/crd/bases/deckhouse.io_applicationpackages.yaml deckhouse-controller/crds/applicationpackage.yaml
.PHONY: generate-crds
generate-crds: controller-gen
@echo "Removing old CRDs..."
@rm -rf ./bin/crd
@echo "Generating CRDs..."
@-$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./deckhouse-controller/pkg/apis/deckhouse.io/..." output:crd:artifacts:config=bin/crd/bases 2>&1
## Enrich the controller-gen CRDs in bin/crd/bases with custom x-doc-* fields
## defined via markers next to the Go API structs.
.PHONY: enrich-crds
enrich-crds: generate-crds crd-enricher ## Add custom x-doc-* fields to the generated CRDs in bin/crd/bases.
@echo "Enriching CRDs with custom x-doc-* fields..."
@$(CRD_ENRICHER) \
paths="./deckhouse-controller/pkg/apis/deckhouse.io/..." \
crds=$(CURDIR)/bin/crd/bases \
dir=$(CURDIR)
## Generate and enrich CRDs with the crd-enricher built from THIS branch's source
## (pkg/crd-enricher) instead of the released $(CRD_ENRICHER_VERSION), so local
## changes are exercised. Pass CRD_ENRICHER_FLAGS=auto-examples to turn on
## automatic example generation.
##
## make enrich-crds-local
## make enrich-crds-local CRD_ENRICHER_FLAGS=auto-examples
.PHONY: enrich-crds-local
enrich-crds-local: generate-crds crd-enricher-local ## Enrich CRDs with the local (branch) crd-enricher build.
@echo "Enriching CRDs with the local crd-enricher$(if $(CRD_ENRICHER_FLAGS), (flags: $(CRD_ENRICHER_FLAGS)),)..."
@$(CRD_ENRICHER_LOCAL) \
paths="./deckhouse-controller/pkg/apis/deckhouse.io/..." \
crds=$(CURDIR)/bin/crd/bases \
dir=$(CURDIR) \
$(CRD_ENRICHER_FLAGS)
## Run the crd-enricher module's unit and golden tests. Pass
## CRD_ENRICHER_TEST_FLAGS=-golden to regenerate the golden snapshots.
##
## make test-crd-enricher
## make test-crd-enricher CRD_ENRICHER_TEST_FLAGS=-golden
.PHONY: test-crd-enricher
test-crd-enricher: ## Run crd-enricher unit/golden tests (CRD_ENRICHER_TEST_FLAGS=-golden regenerates goldens).
@echo "Running crd-enricher tests..."
@cd $(CRD_ENRICHER_SRC) && go test ./... $(CRD_ENRICHER_TEST_FLAGS)
## Generate clientset
.PHONY: client-gen-generate
client-gen-generate: client-gen
$(CLIENT_GEN) \
--clientset-name "versioned" \
--input-base "" \
--input "github.com/deckhouse/deckhouse/deckhouse-controller/pkg/apis/deckhouse.io/v1alpha1,github.com/deckhouse/deckhouse/deckhouse-controller/pkg/apis/deckhouse.io/v1alpha2" \
--output-pkg "github.com/deckhouse/deckhouse/deckhouse-controller/pkg/client/clientset" \
--output-dir "./deckhouse-controller/pkg/client/clientset" \
--go-header-file "./deckhouse-controller/hack/boilerplate.go.txt"
## Generate listers (required for informers)
.PHONY: lister-gen-generate
lister-gen-generate: lister-gen
$(LISTER_GEN) \
--output-pkg "github.com/deckhouse/deckhouse/deckhouse-controller/pkg/client/listers" \
--output-dir "./deckhouse-controller/pkg/client/listers" \
--go-header-file "./deckhouse-controller/hack/boilerplate.go.txt" \
github.com/deckhouse/deckhouse/deckhouse-controller/pkg/apis/deckhouse.io/v1alpha1 \
github.com/deckhouse/deckhouse/deckhouse-controller/pkg/apis/deckhouse.io/v1alpha2
## Generate informers
.PHONY: informer-gen-generate
informer-gen-generate: informer-gen lister-gen-generate client-gen-generate
$(INFORMER_GEN) \
--versioned-clientset-package "github.com/deckhouse/deckhouse/deckhouse-controller/pkg/client/clientset/versioned" \
--listers-package "github.com/deckhouse/deckhouse/deckhouse-controller/pkg/client/listers" \
--output-pkg "github.com/deckhouse/deckhouse/deckhouse-controller/pkg/client/informers" \
--output-dir "./deckhouse-controller/pkg/client/informers" \
--go-header-file "./deckhouse-controller/hack/boilerplate.go.txt" \
github.com/deckhouse/deckhouse/deckhouse-controller/pkg/apis/deckhouse.io/v1alpha1 \
github.com/deckhouse/deckhouse/deckhouse-controller/pkg/apis/deckhouse.io/v1alpha2
## Tool installations
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
## Download deckhouse-cli locally if necessary.
.PHONY: deckhouse-cli
deckhouse-cli:
@if [ -f "$(DECKHOUSE_CLI)" ]; then \
CURRENT_VERSION=$$($(DECKHOUSE_CLI) --version 2>/dev/null | head -n1 | awk '{print $$3}' || echo "unknown"); \
if [ "$$CURRENT_VERSION" != "$(DECKHOUSE_CLI_VERSION)" ]; then \
echo "Current d8 version ($$CURRENT_VERSION) does not match required version ($(DECKHOUSE_CLI_VERSION)), downloading new binary..."; \
else \
echo "d8 version $(DECKHOUSE_CLI_VERSION) is already installed."; \
exit 0; \
fi; \
else \
echo "d8 not found, downloading..."; \
fi; \
curl -sSfL "$(GITHUB_URL)/deckhouse/deckhouse-cli/releases/download/$(DECKHOUSE_CLI_VERSION)/d8-$(DECKHOUSE_CLI_VERSION)-$(YQ_PLATFORM)-$(YQ_ARCH).tar.gz" | tar -xz -C $(LOCALBIN) --strip-components=2 $(YQ_PLATFORM)-$(YQ_ARCH)/bin/d8
.PHONY: crd-enricher
crd-enricher: $(CRD_ENRICHER) ## Download crd-enricher locally if necessary.
$(CRD_ENRICHER): $(LOCALBIN)
$(call go-install-tool,$(CRD_ENRICHER),github.com/deckhouse/deckhouse/pkg/crd-enricher/cmd/crd-enricher,$(CRD_ENRICHER_VERSION))
## Build crd-enricher from the local source in this branch (pkg/crd-enricher) so
## that unreleased changes are used. Rebuilt on every invocation. crd-enricher is
## a separate Go module, so the build runs from within its directory.
.PHONY: crd-enricher-local
crd-enricher-local: $(LOCALBIN) ## Build crd-enricher from local branch source into $(LOCALBIN)/crd-enricher-local.
@echo "Building crd-enricher from local source ($(CRD_ENRICHER_SRC))..."
@cd $(CRD_ENRICHER_SRC) && go build -o $(CRD_ENRICHER_LOCAL) ./cmd/crd-enricher
## Download client-gen locally if necessary.
.PHONY: client-gen
client-gen: $(CLIENT_GEN)
$(CLIENT_GEN): $(LOCALBIN)
$(call go-install-tool,$(CLIENT_GEN),k8s.io/code-generator/cmd/client-gen,$(CODE_GENERATOR_VERSION))
## Download lister-gen locally if necessary.
.PHONY: lister-gen
lister-gen: $(LISTER_GEN)
$(LISTER_GEN): $(LOCALBIN)
$(call go-install-tool,$(LISTER_GEN),k8s.io/code-generator/cmd/lister-gen,$(CODE_GENERATOR_VERSION))
## Download informer-gen locally if necessary.
.PHONY: informer-gen
informer-gen: $(INFORMER_GEN)
$(INFORMER_GEN): $(LOCALBIN)
$(call go-install-tool,$(INFORMER_GEN),k8s.io/code-generator/cmd/informer-gen,$(CODE_GENERATOR_VERSION))
## Download controller-gen locally if necessary.
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN)
$(CONTROLLER_GEN): $(LOCALBIN)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
.PHONY: yq
yq: $(YQ) ## Download yq locally if necessary.
$(YQ): $(LOCALBIN)
$(call go-install-tool,$(YQ),github.com/mikefarah/yq/v4,$(YQ_VERSION))
.PHONY: gotestsum
gotestsum: $(GOTESTSUM) ## Download gotestsum locally if necessary.
$(GOTESTSUM): $(LOCALBIN)
$(call go-install-tool,$(GOTESTSUM),gotest.tools/gotestsum,$(GOTESTSUM_VERSION))
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef
define error-if-empty
@if [[ -z $(1) ]]; then echo "$(2) not installed"; false; fi
endef