forked from kgateway-dev/kgateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
1304 lines (1084 loc) · 56.5 KB
/
Copy pathMakefile
File metadata and controls
1304 lines (1084 loc) · 56.5 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
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# imports should be after the set up flags so are lower
# https://www.gnu.org/software/make/manual/html_node/Special-Variables.html#Special-Variables
.DEFAULT_GOAL := help
SHELL := bash
#----------------------------------------------------------------------------------
# Help
#----------------------------------------------------------------------------------
# Our Makefile is quite large, and hard to reason through
# `make help` can be used to self-document targets
# To update a target to be self-documenting (and appear with the `help` command),
# place a comment after the target that is prefixed by `##`. For example:
# custom-target: ## comment that will appear in the documentation when running `make help`
#
# **NOTE TO DEVELOPERS**
# As you encounter make targets that are frequently used, please make them self-documenting
.PHONY: help
help: NAME_COLUMN_WIDTH=35
help: LINE_COLUMN_WIDTH=5
help: ## Output the self-documenting make targets
@grep -hnE '^[%a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = "[:]|(## )"}; {printf "\033[36mL%-$(LINE_COLUMN_WIDTH)s%-$(NAME_COLUMN_WIDTH)s\033[0m %s\n", $$1, $$2, $$4}'
#----------------------------------------------------------------------------------
# Base
#----------------------------------------------------------------------------------
ROOTDIR := $(shell pwd)
OUTPUT_DIR ?= $(ROOTDIR)/_output
export IMAGE_REGISTRY ?= ghcr.io/kgateway-dev
# Kind of a hack to make sure _output exists
z := $(shell mkdir -p $(OUTPUT_DIR))
BUILDX_BUILD ?= docker buildx build
#----------------------------------------------------------------------------------
# Devcontainer build-tools image
#----------------------------------------------------------------------------------
BUILD_TOOLS_DIR ?= tools/build-tools
BUILD_TOOLS_IMAGE ?= kgateway-build-tools:dev
BUILD_TOOLS_VERSION ?= $(shell git rev-parse --short=12 HEAD 2>/dev/null || echo dev)
OSV_SCANNER_IMAGE ?= ghcr.io/google/osv-scanner-action:v2.3.5
OSV_SCAN_IMAGES ?=
OSV_SCAN_IMAGE_PLATFORM ?= linux/$(GOARCH)
# Set to any value to read images from the local Docker daemon (docker save) instead of pulling from a registry.
# Used by osv-scan-local-images; not set by default so osv-scan always pulls fresh remote images.
OSV_SCAN_LOCAL ?=
.PHONY: build-tools-image
build-tools-image: ## Build the devcontainer build-tools image locally (override BUILD_TOOLS_IMAGE=... to change tag)
$(BUILDX_BUILD) \
--load \
-t $(BUILD_TOOLS_IMAGE) \
--build-arg VERSION=$(BUILD_TOOLS_VERSION) \
-f $(BUILD_TOOLS_DIR)/Dockerfile \
.
# Helper variable for escaping commas in Make functions
comma := ,
# A 'v'-prefixed semver used only locally. Most calling GHA jobs customize
# this. Exported for use in goreleaser.yaml. Because our docker images are
# tagged with a 'v' prefix, we use the prefix here and strip the 'v' prefix
# where actual semver is desired.
VERSION ?= v1.0.1-dev
export VERSION
ROLLING_MAIN_VERSION ?= v2.5.0-main
SOURCES := $(shell find . -name "*.go" | grep -v test.go)
export LDFLAGS := -X 'github.com/kgateway-dev/kgateway/v2/pkg/version.Version=$(VERSION)' -s -w
export GCFLAGS ?=
UNAME_M := $(shell uname -m)
# if `GOARCH` is set, then it will keep its value. Else, it will be changed based off the machine's host architecture.
# if the machines architecture is set to arm64 then we want to set the appropriate values, else we only support amd64
IS_ARM_MACHINE := $(or $(filter $(UNAME_M), arm64), $(filter $(UNAME_M), aarch64))
ifneq ($(IS_ARM_MACHINE), )
ifneq ($(GOARCH), amd64)
GOARCH := arm64
endif
else
# currently we only support arm64 and amd64 as a GOARCH option.
ifneq ($(GOARCH), arm64)
GOARCH := amd64
endif
endif
ifeq ($(IS_ARM_MACHINE), )
OSV_SCANNER_PLATFORM :=
else
OSV_SCANNER_PLATFORM := --platform=linux/amd64
endif
export ENVOY_IMAGE ?= envoyproxy/envoy:v1.38.3
# ENVOY_IMAGE is used by some of the *-docker targets which are used by CI e2e tests, so figure out the correct image
# to use base on GOARCH. This doesn't affect goreleaser
ifeq ($(GOARCH), arm64)
RUST_BUILD_ARCH := aarch64
else
RUST_BUILD_ARCH := x86_64
endif
PLATFORM := --platform=linux/$(GOARCH)
GOOS ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
GO_BUILD_FLAGS := GO111MODULE=on CGO_ENABLED=0 GOARCH=$(GOARCH)
TEST_ASSET_DIR ?= $(ROOTDIR)/_test
# This is the location where assets are placed after a test failure
# This is used by our e2e tests to emit information about the running instance of kgateway
BUG_REPORT_DIR := $(TEST_ASSET_DIR)/bug_report
$(BUG_REPORT_DIR):
mkdir -p $(BUG_REPORT_DIR)
# Base Alpine image used for the dummy-idp container. Exported for use in goreleaser.yaml.
export ALPINE_BASE_IMAGE ?= alpine:3.23.4@sha256:5b10f432ef3da1b8d4c7eb6c487f2f5a8f096bc91145e68878dd4a5019afde11
# Distroless glibc base used for the kgateway controller, SDS, and envoy-wrapper containers. Exported for use in goreleaser.yaml.
# Tracked as :latest (unpinned) on purpose: this distroless image has no package manager, so the only way
# to receive Chainguard's CVE fixes is to pull a newer build. A pinned digest would freeze CVEs in place and
# may be garbage-collected on the free tier. Release builds set DOCKER_NO_CACHE=1, which adds --pull so each
# release picks up the freshly patched image.
export DISTROLESS_BASE_IMAGE ?= cgr.dev/chainguard/glibc-dynamic:latest
GO_VERSION := $(shell cat go.mod | grep -E '^go' | awk '{print $$2}')
GOTOOLCHAIN ?= go$(GO_VERSION)
DEPSGOBIN ?= $(OUTPUT_DIR)
GOLANGCI_LINT ?= go tool golangci-lint
ANALYZE_ARGS ?= --fix --verbose --max-issues-per-linter 0 --max-same-issues 0
CUSTOM_GOLANGCI_LINT_BIN ?= $(DEPSGOBIN)/golangci-lint-custom
CUSTOM_GOLANGCI_LINT_RUN ?= $(CUSTOM_GOLANGCI_LINT_BIN) run --build-tags e2e
CUSTOM_GOLANGCI_LINT_FMT ?= $(GOLANGCI_LINT) fmt
#----------------------------------------------------------------------------------
# Macros
#----------------------------------------------------------------------------------
# This macro takes a relative path as its only argument and returns all the files
# in the tree rooted at that directory that match the given criteria.
get_sources = $(shell find $(1) -name "*.go" | grep -v test | grep -v generated.go | grep -v mock_)
#----------------------------------------------------------------------------------
# Repo setup
#----------------------------------------------------------------------------------
.PHONY: init-git-hooks
init-git-hooks: ## Use the tracked version of Git hooks from this repo
git config core.hooksPath .githooks
.PHONY: fmt-go
fmt-go:
$(CUSTOM_GOLANGCI_LINT_FMT) ./...
.PHONY: fmt-go-changed
fmt-go-changed:
git status -s -uno | awk '{print $$2}' | grep '.*.go$$' | xargs -r -I{} bash -lc '[ -f "{}" ] && $(CUSTOM_GOLANGCI_LINT_FMT) "{}" || true'
YAMLFMT ?= go tool -modfile tools/go.mod yamlfmt
YAML_PATHSPEC = '*.[Yy][Mm][Ll]' '*.[Yy][Aa][Mm][Ll]'
.PHONY: fmt-yaml
fmt-yaml: ## Format tracked YAML files with yamlfmt
git ls-files -z -- $(YAML_PATHSPEC) | xargs -0 sh -c 'if [ "$$#" -gt 0 ]; then exec $(YAMLFMT) "$$@"; fi' sh
.PHONY: fmt-yaml-changed
fmt-yaml-changed:
git diff --name-only -z --diff-filter=d HEAD -- $(YAML_PATHSPEC) | xargs -0 sh -c 'if [ "$$#" -gt 0 ]; then exec $(YAMLFMT) "$$@"; fi' sh
.PHONY: fmt
fmt: fmt-go fmt-yaml ## Format Go and YAML files
.PHONY: fmt-changed
fmt-changed: fmt-go-changed fmt-yaml-changed ## Format changed Go and YAML files (skip deleted files)
.PHONY: mod-download
mod-download: ## Download transitive dependencies
go mod download
cd tools && go mod download
cd test/e2e/defaults/extproc && go mod download
.PHONY: mod-tidy
mod-tidy: ## Tidy the go mod file
@echo "Tidying tools..." && cd tools && go mod tidy
@echo "Tidying test/e2e/defaults/extproc..." && cd test/e2e/defaults/extproc && go mod tidy
@echo "Tidying top level" && go mod tidy
#----------------------------------------------------------------------------
# Analyze
#----------------------------------------------------------------------------
.PHONY: analyze
analyze: $(CUSTOM_GOLANGCI_LINT_BIN) ## Run repository lint checks. Override golangci-lint options with ANALYZE_ARGS.
$(MAKE) --no-print-directory fmt-yaml
$(CUSTOM_GOLANGCI_LINT_RUN) $(ANALYZE_ARGS) ./...
$(CUSTOM_GOLANGCI_LINT_BIN): go.mod go.sum .custom-gcl.yml
GOTOOLCHAIN=$(GOTOOLCHAIN) $(GOLANGCI_LINT) custom
ACTION_LINT ?= go tool github.com/rhysd/actionlint/cmd/actionlint
.PHONY: lint-actions
lint-actions: ## Lint the GitHub Actions workflows
$(ACTION_LINT)
.PHONY: osv-scan
osv-scan: ## Run OSV-Scanner locally; set OSV_SCAN_IMAGES="image-ref ..." to also scan Docker images
@set -euo pipefail; \
branch="$$(git rev-parse --abbrev-ref HEAD)"; \
if [[ "$$branch" == "HEAD" ]]; then \
branch="detached-$$(git rev-parse --short=12 HEAD)"; \
fi; \
safe_branch="$$(printf '%s' "$$branch" | tr '/.' '--')"; \
out_dir="$(OUTPUT_DIR)/osv/$$safe_branch"; \
mkdir -p "$$out_dir"; \
echo "Running OSV-Scanner for branch: $$branch"; \
echo "Writing results to: $$out_dir"; \
scanner_status=0; \
if docker run --rm \
$(OSV_SCANNER_PLATFORM) \
--entrypoint /root/osv-scanner \
-v "$(ROOTDIR):/workspace" \
-v "$(OUTPUT_DIR):/output" \
-w /workspace \
"$(OSV_SCANNER_IMAGE)" \
scan source \
--output-file=/output/osv/$$safe_branch/results.json \
--format=json \
--no-call-analysis=go \
--no-call-analysis=rust \
--verbosity=warn \
-r \
./; then \
:; \
else \
scanner_status=$$?; \
fi; \
if [[ ! -f "$$out_dir/results.json" ]]; then \
echo "osv-scanner did not produce $$out_dir/results.json" >&2; \
exit 1; \
fi; \
reporter_status=0; \
if docker run --rm \
$(OSV_SCANNER_PLATFORM) \
--entrypoint /root/osv-reporter \
-v "$(ROOTDIR):/workspace" \
-v "$(OUTPUT_DIR):/output" \
-w /workspace \
"$(OSV_SCANNER_IMAGE)" \
--output-files=sarif:/output/osv/$$safe_branch/results.sarif \
--new=/output/osv/$$safe_branch/results.json \
--fail-on-vuln=false; then \
:; \
else \
reporter_status=$$?; \
fi; \
if [[ ! -f "$$out_dir/results.sarif" ]]; then \
echo "osv-reporter did not produce $$out_dir/results.sarif" >&2; \
exit 1; \
fi; \
image_scanner_status=0; \
image_reporter_status=0; \
if [[ -n "$(strip $(OSV_SCAN_IMAGES))" ]]; then \
image_dir="$$out_dir/images"; \
mkdir -p "$$image_dir"; \
echo "Scanning Docker images: $(OSV_SCAN_IMAGES)"; \
for image in $(OSV_SCAN_IMAGES); do \
safe_image_base="$$(printf '%s' "$$image" | sed 's/[^A-Za-z0-9_.-]/-/g')"; \
image_hash="$$(printf '%s' "$$image" | sha256sum | cut -d' ' -f1)"; \
safe_image="$$safe_image_base-$$image_hash"; \
image_json="/output/osv/$$safe_branch/images/$$safe_image.json"; \
image_sarif="/output/osv/$$safe_branch/images/$$safe_image.sarif"; \
image_archive="/output/osv/$$safe_branch/images/$$safe_image.tar"; \
host_image_json="$$image_dir/$$safe_image.json"; \
host_image_sarif="$$image_dir/$$safe_image.sarif"; \
host_image_archive="$$image_dir/$$safe_image.tar"; \
image_platform="$(OSV_SCAN_IMAGE_PLATFORM)"; \
image_os="$${image_platform%%/*}"; \
image_arch="$${image_platform#*/}"; \
image_arch="$${image_arch%%/*}"; \
rm -f "$$host_image_archive"; \
if [[ -n "$(OSV_SCAN_LOCAL)" ]]; then \
echo "Saving local image $$image via docker save"; \
docker save "$$image" -o "$$host_image_archive"; \
elif command -v skopeo > /dev/null 2>&1; then \
if skopeo copy \
--override-os "$$image_os" \
--override-arch "$$image_arch" \
"docker://$$image" \
"docker-archive:$$host_image_archive:$$image"; then \
:; \
else \
echo "skopeo archive export failed for $$image; falling back to docker save"; \
rm -f "$$host_image_archive"; \
echo "Pulling Docker image $$image for platform $$image_platform"; \
docker pull --platform "$$image_platform" "$$image"; \
docker save "$$image" -o "$$host_image_archive"; \
fi; \
else \
echo "Pulling Docker image $$image for platform $$image_platform"; \
docker pull --platform "$$image_platform" "$$image"; \
docker save "$$image" -o "$$host_image_archive"; \
fi; \
echo "Running OSV-Scanner for Docker image: $$image"; \
if docker run --rm \
$(OSV_SCANNER_PLATFORM) \
--entrypoint /root/osv-scanner \
-v "$(ROOTDIR):/workspace" \
-v "$(OUTPUT_DIR):/output" \
-w /workspace \
"$(OSV_SCANNER_IMAGE)" \
scan image \
--archive \
--config=/workspace/osv-scanner.toml \
--output-file="$$image_json" \
--format=json \
--verbosity=warn \
"$$image_archive"; then \
:; \
else \
image_scanner_status=$$?; \
fi; \
if [[ ! -f "$$host_image_json" ]]; then \
echo "osv-scanner did not produce $$host_image_json" >&2; \
exit 1; \
fi; \
rm -f "$$host_image_archive"; \
if docker run --rm \
$(OSV_SCANNER_PLATFORM) \
--entrypoint /root/osv-reporter \
-v "$(ROOTDIR):/workspace" \
-v "$(OUTPUT_DIR):/output" \
-w /workspace \
"$(OSV_SCANNER_IMAGE)" \
--output-files="sarif:$$image_sarif" \
--new="$$image_json" \
--fail-on-vuln=false; then \
:; \
else \
image_reporter_status=$$?; \
fi; \
if [[ ! -f "$$host_image_sarif" ]]; then \
echo "osv-reporter did not produce $$host_image_sarif" >&2; \
exit 1; \
fi; \
echo "Image JSON: $$host_image_json"; \
echo "Image SARIF: $$host_image_sarif"; \
done; \
fi; \
docker run --rm \
$(OSV_SCANNER_PLATFORM) \
--entrypoint /bin/chown \
-v "$(OUTPUT_DIR):/output" \
"$(OSV_SCANNER_IMAGE)" \
-R "$$(id -u):$$(id -g)" "/output/osv/$$safe_branch" > /dev/null; \
if [[ "$$scanner_status" -ne 0 || "$$reporter_status" -ne 0 || "$$image_scanner_status" -ne 0 || "$$image_reporter_status" -ne 0 ]]; then \
echo "OSV scan completed and wrote results despite non-zero scanner/reporter exit status."; \
fi; \
echo "JSON: $$out_dir/results.json"; \
echo "SARIF: $$out_dir/results.sarif"
.PHONY: osv-scan-latest-main-images
osv-scan-latest-main-images:
$(MAKE) osv-scan OSV_SCAN_IMAGES="ghcr.io/kgateway-dev/kgateway:$(ROLLING_MAIN_VERSION) ghcr.io/kgateway-dev/sds:$(ROLLING_MAIN_VERSION) ghcr.io/kgateway-dev/envoy-wrapper:$(ROLLING_MAIN_VERSION)"
.PHONY: osv-scan-local-images
osv-scan-local-images: ## Build images from the current branch and run OSV-Scanner against them
$(MAKE) -B kgateway-docker sds-docker envoy-wrapper-docker
$(MAKE) osv-scan \
OSV_SCAN_LOCAL=1 \
OSV_SCAN_IMAGES="$(IMAGE_REGISTRY)/$(CONTROLLER_IMAGE_REPO):$(VERSION) $(IMAGE_REGISTRY)/$(SDS_IMAGE_REPO):$(VERSION) $(IMAGE_REGISTRY)/$(ENVOYINIT_IMAGE_REPO):$(VERSION)"
#----------------------------------------------------------------------------------
# Ginkgo Tests
#----------------------------------------------------------------------------------
FLAKE_ATTEMPTS ?= 3
GINKGO_VERSION ?= $(shell echo $(shell go list -m github.com/onsi/ginkgo/v2) | cut -d' ' -f2)
GINKGO_ENV ?= ACK_GINKGO_RC=true ACK_GINKGO_DEPRECATIONS=$(GINKGO_VERSION)
GINKGO_FLAGS ?= -tags=purego --trace -progress -race --fail-fast -fail-on-pending --randomize-all --compilers=5 --flake-attempts=$(FLAKE_ATTEMPTS)
GINKGO_REPORT_FLAGS ?= --json-report=test-report.json --junit-report=junit.xml -output-dir=$(OUTPUT_DIR)
GINKGO_COVERAGE_FLAGS ?= --cover --covermode=atomic --coverprofile=coverage.cov
TEST_PKG ?= ./... # Default to run all tests except e2e tests
# This is a way for a user executing `make test` to be able to provide flags which we do not include by default
# For example, you may want to run tests multiple times, or with various timeouts
GINKGO_USER_FLAGS ?=
GINKGO ?= go tool ginkgo
.PHONY: test
test: ## Run all tests with ginkgo, or only run the test package at {TEST_PKG} if it is specified
$(GO_TEST_ENV) $(GINKGO_ENV) $(GINKGO) -ldflags='$(LDFLAGS)' \
$(GINKGO_FLAGS) $(GINKGO_REPORT_FLAGS) $(GINKGO_USER_FLAGS) \
$(TEST_PKG)
# To run only e2e tests, we restrict to ./test/e2e/tests. We say
# '-tags=e2e' because untagged files contain unit tests cases, not e2e test
# cases, so we have to allow `go` to see our e2e tests. Someone might forget to
# label a new e2e test case with `//go:build e2e`, in which case `make unit`
# will error because there is no kind cluster.
#
# This build-tag approach makes unit tests run faster since e2e tests are not
# compiled, but it might be better to set an environment variable `E2E=true`
# and have end-to-end test cases report that they were skipped if it's not
# truthy. As it stands, a developer who runs `make unit` or `go test ./...`
# will still have e2e tests run by Github Actions once they publish a pull
# request.
# CLUSTER_TYPE controls whether images are loaded via kind or k3d (default: kind)
#
# k3d note: under k3d, LB IPs are not host-reachable, so e2e tests use
# GATEWAY_ADDRESS_OVERRIDE (e.g. "localhost") to direct curls to a port-forwarded
# address. This override is honored only for the base gateway resolved by
# common.SetupBaseGateway; multi-gateway suites that construct their own
# common.Gateway values cannot disambiguate multiple gateways with a single env
# var and are therefore out of scope under k3d.
CLUSTER_TYPE ?= kind
SKIP_EXTPROC_SERVER_SETUP ?= false
E2E_SHARED_IMAGE_ARCHIVE ?= $(OUTPUT_DIR)/e2e-images/shared-images.tar
E2E_SHARED_IMAGE_TAGS = \
$(IMAGE_REGISTRY)/$(CONTROLLER_IMAGE_REPO):$(VERSION) \
$(IMAGE_REGISTRY)/$(ENVOYINIT_IMAGE_REPO):$(VERSION) \
$(IMAGE_REGISTRY)/$(SDS_IMAGE_REPO):$(VERSION) \
$(IMAGE_REGISTRY)/$(DUMMY_IDP_IMAGE_REPO):$(DUMMY_IDP_VERSION) \
$(IMAGE_REGISTRY)/$(EXTPROC_SERVER_IMAGE_REPO):$(EXTPROC_SERVER_VERSION)
.PHONY: cluster-load-extproc-server
ifeq ($(CLUSTER_TYPE),k3d)
cluster-load-extproc-server: k3d-load-extproc-server
else
cluster-load-extproc-server: kind-load-extproc-server
endif
.PHONY: e2e-test
e2e-test: maybe-setup-extproc-server
e2e-test: go-test
e2e-test: TEST_TAG = e2e
e2e-test: GO_TEST_ARGS = $(E2E_GO_TEST_ARGS)
.PHONY: e2e-shared-images-docker
e2e-shared-images-docker: kgateway-docker envoy-wrapper-docker sds-docker dummy-idp-docker extproc-server-docker ## Build shared docker images for e2e shards
.PHONY: save-e2e-shared-images
save-e2e-shared-images: e2e-shared-images-docker ## Save shared e2e shard images to a docker archive
@mkdir -p $(dir $(E2E_SHARED_IMAGE_ARCHIVE))
docker save -o $(E2E_SHARED_IMAGE_ARCHIVE) $(E2E_SHARED_IMAGE_TAGS)
.PHONY: maybe-setup-extproc-server
ifeq ($(SKIP_EXTPROC_SERVER_SETUP),true)
maybe-setup-extproc-server:
@echo "Skipping extproc-server build and load"
else
maybe-setup-extproc-server: extproc-server-docker cluster-load-extproc-server
endif
# https://go.dev/blog/cover#heat-maps
.PHONY: test-with-coverage
test-with-coverage: GINKGO_FLAGS += $(GINKGO_COVERAGE_FLAGS)
test-with-coverage: test
go tool cover -html $(OUTPUT_DIR)/coverage.cov
.PHONY: golden-deployer
golden-deployer: ## Refreshes golden files for ./test/deployer snapshot testing
HELM="$(HELM)" REFRESH_GOLDEN=true go test ./test/deployer/... > /dev/null || true
@echo ""
@echo "This must pass after refreshing:"
HELM="$(HELM)" go test ./test/deployer/...
.PHONY: golden-helm
golden-helm: ## Refreshes golden files for ./test/helm snapshot testing
HELM="$(HELM)" REFRESH_GOLDEN=true go test ./test/helm/... > /dev/null || true
@echo ""
@echo "This must pass after refreshing:"
HELM="$(HELM)" go test ./test/helm/...
## Refreshes golden files for translation testing
golden-translator-%:
REFRESH_GOLDEN=true \
GINKGO_USER_FLAGS="--fail-on-pending=false" \
TEST_PKG=./pkg/kgateway/translator/$* \
$(MAKE) test
#----------------------------------------------------------------------------------
# Env test
#----------------------------------------------------------------------------------
# Gateway API v1.6 experimental CRDs (xbackends) use the CEL format library,
# which requires a kube-apiserver newer than 1.31.
# Defaults to a version compatible with the Gateway API experimental CRDs. CI
# matrix lanes may override this to match their Kubernetes version.
ENVTEST_K8S_VERSION ?= 1.33
ENVTEST ?= go -C tools tool setup-envtest
.PHONY: envtest-path
envtest-path: ## Set the envtest path
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path --arch=amd64
#----------------------------------------------------------------------------------
# Go Tests
#----------------------------------------------------------------------------------
# Fix for macOS linker warning with race detector on arm64 (which still warns
# you that -ld_classic is deprecated, but that's better than broken race
# condition detection)
# See: https://github.com/golang/go/issues/61229
GO_TEST_ENV ?=
ifeq ($(GOOS), darwin)
ifeq ($(GOARCH), arm64)
override GO_TEST_ENV := CGO_LDFLAGS="-Wl,-ld_classic"
endif
endif
# Skip -race on e2e. This requires building the codebase twice, and provides no value as the only code executed is test code.
# Skip -vet; we already run it on the linter step and its very slow.
E2E_GO_TEST_ARGS ?= -vet=off -timeout=35m -outputdir=$(OUTPUT_DIR)
# Testing flags: https://pkg.go.dev/cmd/go#hdr-Testing_flags
# The default timeout for a suite is 10 minutes, but this can be overridden by
# setting the -timeout flag. Currently set to 35 minutes based on the time it
# takes to run the longest test step (unittests. TODO(chandler): why is the
# upgraded setup-envtest so much slower?)
GO_TEST_ARGS ?= -timeout=35m -outputdir=$(OUTPUT_DIR) -race
GO_TEST_COVERAGE_ARGS ?= --cover --covermode=atomic --coverprofile=cover.out
GO_TEST_COVERAGE ?= go tool github.com/vladopajic/go-test-coverage/v2
# This is a way for a user executing `make go-test` to be able to provide args which we do not include by default
# For example, you may want to run tests multiple times, or with various timeouts
GO_TEST_USER_ARGS ?=
GO_TEST_RETRIES ?= 0
GOTESTSUM ?= go tool gotestsum
GOTESTSUM_ARGS ?= --format=standard-verbose
.PHONY: go-test
go-test: ## Run all tests, or only run the test package at {TEST_PKG} if it is specified
go-test: reset-bug-report
$(GO_TEST_ENV) $(GOTESTSUM) $(GOTESTSUM_ARGS) --rerun-fails-abort-on-data-race --rerun-fails=$(GO_TEST_RETRIES) --packages="$(TEST_PKG)" -- -ldflags='$(LDFLAGS)' $(if $(TEST_TAG),-tags=$(TEST_TAG)) $(GO_TEST_ARGS) $(GO_TEST_USER_ARGS)
# https://go.dev/blog/cover#heat-maps
.PHONY: go-test-with-coverage
go-test-with-coverage: GO_TEST_ARGS += $(GO_TEST_COVERAGE_ARGS)
go-test-with-coverage: go-test
# https://go.dev/blog/cover#heat-maps
.PHONY: unit-with-coverage
unit-with-coverage:
@$(MAKE) --no-print-directory unit GO_TEST_ARGS="$(GO_TEST_ARGS) $(GO_TEST_COVERAGE_ARGS)"
.PHONY: unit
unit: ## Run all unit tests (excludes e2e tests)
@echo "Running unit tests (excluding e2e)..."
@$(MAKE) --no-print-directory go-test TEST_TAG=""
.PHONY: validate-test-coverage
validate-test-coverage: ## Validate the test coverage
$(GO_TEST_COVERAGE) --config=./test_coverage.yml
# https://go.dev/blog/cover#heat-maps
.PHONY: view-test-coverage
view-test-coverage:
go tool cover -html $(OUTPUT_DIR)/cover.out
#----------------------------------------------------------------------------------
# Container Structure Tests
#----------------------------------------------------------------------------------
# Tests Docker images using container-structure-test from GoogleContainerTools
# https://github.com/GoogleContainerTools/container-structure-test
CONTAINER_STRUCTURE_TEST ?= container-structure-test
CONTAINER_STRUCTURE_TEST_DIR := test/container-structure
# Architecture suffix used by goreleaser image tags (e.g. -amd64, -arm64)
CONTAINER_STRUCTURE_TEST_ARCH ?= $(GOARCH)
# Platform flag for cross-arch testing via QEMU (only needed when testing non-native arch)
CONTAINER_STRUCTURE_TEST_PLATFORM_FLAG := $(if $(filter $(GOARCH),$(CONTAINER_STRUCTURE_TEST_ARCH)),,--platform linux/$(CONTAINER_STRUCTURE_TEST_ARCH))
.PHONY: container-structure-test
container-structure-test: ## Run container structure tests for all production images (uses goreleaser image tags)
container-structure-test: container-structure-test-kgateway container-structure-test-sds container-structure-test-envoy-wrapper
.PHONY: container-structure-test-kgateway
container-structure-test-kgateway: ## Run container structure tests for kgateway image
$(CONTAINER_STRUCTURE_TEST) test \
--image $(IMAGE_REGISTRY)/$(CONTROLLER_IMAGE_REPO):$(VERSION)-$(CONTAINER_STRUCTURE_TEST_ARCH) \
$(CONTAINER_STRUCTURE_TEST_PLATFORM_FLAG) \
--config $(CONTAINER_STRUCTURE_TEST_DIR)/kgateway.yaml
.PHONY: container-structure-test-sds
container-structure-test-sds: ## Run container structure tests for sds image
$(CONTAINER_STRUCTURE_TEST) test \
--image $(IMAGE_REGISTRY)/$(SDS_IMAGE_REPO):$(VERSION)-$(CONTAINER_STRUCTURE_TEST_ARCH) \
$(CONTAINER_STRUCTURE_TEST_PLATFORM_FLAG) \
--config $(CONTAINER_STRUCTURE_TEST_DIR)/sds.yaml
.PHONY: container-structure-test-envoy-wrapper
container-structure-test-envoy-wrapper: ## Run container structure tests for envoy-wrapper image
$(CONTAINER_STRUCTURE_TEST) test \
--image $(IMAGE_REGISTRY)/$(ENVOYINIT_IMAGE_REPO):$(VERSION)-$(CONTAINER_STRUCTURE_TEST_ARCH) \
$(CONTAINER_STRUCTURE_TEST_PLATFORM_FLAG) \
--config $(CONTAINER_STRUCTURE_TEST_DIR)/envoy-wrapper.yaml
#----------------------------------------------------------------------------------
# MARK: Clean
#----------------------------------------------------------------------------------
# Important to clean before pushing new releases. Dockerfiles and binaries may not update properly
.PHONY: clean
clean:
rm -rf _output
rm -rf _test
git clean -f -X install
@# Note: _output removal also cleans stamps since STAMP_DIR is in _output
.PHONY: clean-tests
clean-tests:
find * -type f -name '*.test' -exec rm {} \;
find * -type f -name '*.cov' -exec rm {} \;
find * -type f -name 'junit*.xml' -exec rm {} \;
# NB: 'reset-bug-report: clean-bug-report $(BUG_REPORT_DIR)' would be a subtle
# bug since we would never run 'mkdir' if the directory already existed.
.PHONY: reset-bug-report
reset-bug-report: clean-bug-report
@$(MAKE) --no-print-directory $(BUG_REPORT_DIR)
.PHONY: clean-bug-report
clean-bug-report:
rm -rf $(BUG_REPORT_DIR)
#----------------------------------------------------------------------------------
# MARK: Generated Code
#----------------------------------------------------------------------------------
# This section uses stamp files to optimize 'make generate-all' by tracking dependencies.
#
# For local development:
# - 'make generate-all' only regenerates code when source files change (fast!)
# - Use 'make clean-stamps' to force full regeneration
#
# For CI (always regenerates to catch dependency tracking bugs):
# - 'make verify' cleans stamps and always regenerates everything
# - This ensures CI catches any mistakes in our dependency tracking
#
# How it works:
# - Each generation step creates a stamp file in _output/stamps/
# - Make compares stamp file timestamps with source file timestamps
# - Only re-runs steps when source files are newer than stamps
#----------------------------------------------------------------------------------
# Stamp directory for tracking generation steps
STAMP_DIR := $(OUTPUT_DIR)/stamps
$(STAMP_DIR):
mkdir -p $(STAMP_DIR)
# Source files that trigger API codegen
API_SOURCE_FILES := $(shell find api/v1alpha1 -name "*.go" ! -name "zz_generated*")
API_SOURCE_FILES += hack/generate.sh hack/generate.go
# Source files that trigger mockgen
MOCK_SOURCE_FILES := pkg/kgateway/query/query_test.go
# Files that track dependency changes
MOD_FILES := go.mod go.sum \
tools/go.mod tools/go.sum \
test/e2e/defaults/extproc/go.mod test/e2e/defaults/extproc/go.sum
# Clean generated code
.PHONY: clean-gen
clean-gen:
rm -rf api/applyconfiguration
rm -rf pkg/generated/openapi
rm -rf pkg/client
rm -f install/helm/kgateway-crds/templates/gateway.kgateway.dev_*.yaml
# Clean all stamp files to force regeneration
.PHONY: clean-stamps
clean-stamps:
rm -rf $(STAMP_DIR)
# API code generation with dependency tracking
$(STAMP_DIR)/go-generate-apis: $(API_SOURCE_FILES) | $(STAMP_DIR)
@echo "Running API code generation..."
GO111MODULE=on go generate ./hack/...
$(MAKE) fmt-changed
@touch $@
# Mock generation with dependency tracking
$(STAMP_DIR)/go-generate-mocks: $(MOCK_SOURCE_FILES) | $(STAMP_DIR)
@echo "Running mock generation..."
GO111MODULE=on go generate -run="mockgen" ./...
$(MAKE) fmt-changed
@touch $@
# Combine both generation steps
$(STAMP_DIR)/go-generate-all: $(STAMP_DIR)/go-generate-apis $(STAMP_DIR)/go-generate-mocks
@touch $@
# Module tidy with dependency tracking
$(STAMP_DIR)/mod-tidy: $(MOD_FILES) | $(STAMP_DIR)
@$(MAKE) --no-print-directory mod-tidy
@touch $@
# License generation with dependency tracking
$(STAMP_DIR)/generate-licenses: $(MOD_FILES) | $(STAMP_DIR)
@echo "Generating licenses..."
GO111MODULE=on go run hack/utils/oss_compliance/oss_compliance.go osagen -c "GNU General Public License v2.0,GNU General Public License v3.0,GNU Lesser General Public License v2.1,GNU Lesser General Public License v3.0,GNU Affero General Public License v3.0"
GO111MODULE=on go run hack/utils/oss_compliance/oss_compliance.go osagen -s "Mozilla Public License 2.0,GNU General Public License v2.0,GNU General Public License v3.0,GNU Lesser General Public License v2.1,GNU Lesser General Public License v3.0,GNU Affero General Public License v3.0"> hack/utils/oss_compliance/osa_provided.md
GO111MODULE=on go run hack/utils/oss_compliance/oss_compliance.go osagen -i "Mozilla Public License 2.0"> hack/utils/oss_compliance/osa_included.md
@touch $@
# Formatting - only runs if generation steps changed
$(STAMP_DIR)/fmt: $(STAMP_DIR)/go-generate-all $(CUSTOM_GOLANGCI_LINT_BIN)
@echo "Formatting code..."
$(MAKE) --no-print-directory fmt-go
@touch $@
# Fast generation using stamp files (for local development)
$(STAMP_DIR)/generated-code: $(STAMP_DIR)/go-generate-all $(STAMP_DIR)/mod-tidy $(STAMP_DIR)/generate-licenses $(STAMP_DIR)/fmt
@touch $@
.PHONY: verify
verify: generated-code ## Verify that generated code is up to date (always regenerates for CI safety)
git diff -U3 --exit-code
ENVOYINIT_DOCKERFILE = cmd/envoyinit/Dockerfile
ENVOY_MODULE_DIR = internal/envoy_modules
ENVOY_MODULE_DOCKERFILE = $(ENVOY_MODULE_DIR)/Dockerfile
ENVOY_MODULE_DOCKERFILE_TEMPLATE = $(ENVOY_MODULE_DIR)/Dockerfile.tmpl
ENVOY_MODULE_OUTPUT_DIR = $(OUTPUT_DIR)/$(ENVOY_MODULE_DIR)
.PHONY: generate-all
generate-all: $(STAMP_DIR)/generated-code $(ENVOY_MODULE_DOCKERFILE) ## Generate all code with optimized dependencies (uses stamp files for speed)
.PHONY: generate
generate: generate-all ## Alias for generate
# Force full regeneration by cleaning stamps and generated files
.PHONY: generated-code
generated-code: clean-gen clean-stamps ## Force regenerate all code (always runs, ignoring stamps)
@$(MAKE) --no-print-directory generate-all
# Convenience PHONY targets that trigger stamp-based generation
.PHONY: go-generate-all
go-generate-all: $(STAMP_DIR)/go-generate-all ## Run all go generate directives (with dependency tracking)
.PHONY: go-generate-apis
go-generate-apis: $(STAMP_DIR)/go-generate-apis ## Run all go generate directives in the repo, including codegen for protos, mockgen, and more
.PHONY: go-generate-mocks
go-generate-mocks: $(STAMP_DIR)/go-generate-mocks ## Runs all generate directives for mockgen in the repo
.PHONY: generate-licenses
generate-licenses: $(STAMP_DIR)/generate-licenses ## Generate the licenses for the project
#----------------------------------------------------------------------------------
# Controller
#----------------------------------------------------------------------------------
K8S_GATEWAY_SOURCES=$(call get_sources,cmd/kgateway pkg/ api/)
CONTROLLER_OUTPUT_DIR=$(OUTPUT_DIR)/pkg/kgateway
export CONTROLLER_IMAGE_REPO ?= kgateway
# Registry cache repo for controller Docker build (set to enable, e.g., ghcr.io/kgateway-dev/kgateway-cache).
# The arch tag is appended automatically as :$(GOARCH) to match what goreleaser publishes.
CONTROLLER_CACHE_REF ?=
CONTROLLER_CACHE_FROM := $(if $(CONTROLLER_CACHE_REF),--cache-from type=registry$(comma)ref=$(CONTROLLER_CACHE_REF):$(GOARCH),)
# We include the files in K8S_GATEWAY_SOURCES as dependencies to the kgateway build
# so changes in those directories cause the make target to rebuild
$(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH): $(K8S_GATEWAY_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ ./cmd/kgateway/...
# TODO: is this target obsolete?
.PHONY: kgateway
kgateway: $(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH)
$(CONTROLLER_OUTPUT_DIR)/Dockerfile: cmd/kgateway/Dockerfile
cp $< $@
$(CONTROLLER_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH): $(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH) $(CONTROLLER_OUTPUT_DIR)/Dockerfile $(ENVOY_MODULE_OUTPUT_DIR)/librust_module.so
cp $(ENVOY_MODULE_OUTPUT_DIR)/librust_module.so $(CONTROLLER_OUTPUT_DIR)/librust_module.so
$(BUILDX_BUILD) --load $(PLATFORM) $(CONTROLLER_OUTPUT_DIR) -f $(CONTROLLER_OUTPUT_DIR)/Dockerfile \
--build-arg GOARCH=$(GOARCH) \
--build-arg ENVOY_IMAGE=$(ENVOY_IMAGE) \
--build-arg BASE_IMAGE=$(DISTROLESS_BASE_IMAGE) \
$(CONTROLLER_CACHE_FROM) \
-t $(IMAGE_REGISTRY)/$(CONTROLLER_IMAGE_REPO):$(VERSION)
@touch $@
.PHONY: kgateway-docker
kgateway-docker: $(CONTROLLER_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH)
#----------------------------------------------------------------------------------
# SDS Server - gRPC server for serving Secret Discovery Service config
#----------------------------------------------------------------------------------
SDS_DIR=pkg/sds
SDS_SOURCES=$(call get_sources,$(SDS_DIR))
SDS_OUTPUT_DIR=$(OUTPUT_DIR)/$(SDS_DIR)
export SDS_IMAGE_REPO ?= sds
# Registry cache repo for sds Docker build (set to enable, e.g., ghcr.io/kgateway-dev/sds-cache).
# The arch tag is appended automatically as :$(GOARCH) to match what goreleaser publishes.
SDS_CACHE_REF ?=
SDS_CACHE_FROM := $(if $(SDS_CACHE_REF),--cache-from type=registry$(comma)ref=$(SDS_CACHE_REF):$(GOARCH),)
$(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH): $(SDS_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ ./cmd/sds/...
.PHONY: sds
sds: $(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH)
$(SDS_OUTPUT_DIR)/Dockerfile.sds: cmd/sds/Dockerfile
cp $< $@
$(SDS_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH): $(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH) $(SDS_OUTPUT_DIR)/Dockerfile.sds
$(BUILDX_BUILD) --load $(PLATFORM) $(SDS_OUTPUT_DIR) -f $(SDS_OUTPUT_DIR)/Dockerfile.sds \
--build-arg GOARCH=$(GOARCH) \
--build-arg BASE_IMAGE=$(DISTROLESS_BASE_IMAGE) \
$(SDS_CACHE_FROM) \
-t $(IMAGE_REGISTRY)/$(SDS_IMAGE_REPO):$(VERSION)
@touch $@
.PHONY: sds-docker
sds-docker: $(SDS_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH)
#----------------------------------------------------------------------------------
# Envoy init (BASE/SIDECAR)
#----------------------------------------------------------------------------------
ENVOYINIT_DIR=cmd/envoyinit
INTERNAL_ENVOYINIT_DIR=internal/envoyinit
ENVOYINIT_SOURCES=$(call get_sources,$(ENVOYINIT_DIR) $(INTERNAL_ENVOYINIT_DIR))
ENVOYINIT_OUTPUT_DIR=$(OUTPUT_DIR)/$(ENVOYINIT_DIR)
export ENVOYINIT_IMAGE_REPO ?= envoy-wrapper
# Registry cache for envoyinit Docker build (set to enable, e.g., ghcr.io/kgateway-dev/envoy-wrapper-cache)
# Registry cache-from targets the image goreleaser publishes on main/release.
# The arch tag is appended automatically as :$(GOARCH) to match what goreleaser publishes.
ENVOYINIT_CACHE_REF ?=
ENVOYINIT_CACHE_FROM := $(if $(ENVOYINIT_CACHE_REF),--cache-from type=registry$(comma)ref=$(ENVOYINIT_CACHE_REF):$(GOARCH),)
# Optional local BuildKit cache paths, typically wired to actions/cache in CI
# so PR runs can read AND write layer cache without needing registry push auth.
# Requires the docker-container buildx driver (docker/setup-buildx-action).
# mode=max exports intermediate stages, which is what lets rust_build_deps and
# rust_builder stay cached across runs even when the registry cache has gaps.
ENVOYINIT_LOCAL_CACHE_FROM ?=
ENVOYINIT_LOCAL_CACHE_TO ?=
ENVOYINIT_LOCAL_CACHE_FROM_ARG := $(if $(ENVOYINIT_LOCAL_CACHE_FROM),--cache-from type=local$(comma)src=$(ENVOYINIT_LOCAL_CACHE_FROM),)
ENVOYINIT_LOCAL_CACHE_TO_ARG := $(if $(ENVOYINIT_LOCAL_CACHE_TO),--cache-to type=local$(comma)dest=$(ENVOYINIT_LOCAL_CACHE_TO)$(comma)mode=max,)
ENVOY_MODULES_DIR := internal/envoy_modules/
# find all the files under the envoy modules directory but exclude the target, vendor and pkg directory
ENVOY_MODULES_SRC_FILES := $(shell find $(ENVOY_MODULES_DIR) \( -type d -name target -o -type d -name pkg -o -type d -name vendor \) -prune -o -type f -print)
$(ENVOYINIT_OUTPUT_DIR)/envoyinit-linux-$(GOARCH): $(ENVOYINIT_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ ./cmd/envoyinit/...
.PHONY: envoyinit
envoyinit: $(ENVOYINIT_OUTPUT_DIR)/envoyinit-linux-$(GOARCH)
$(ENVOY_MODULE_DOCKERFILE): $(ENVOY_MODULE_DOCKERFILE_TEMPLATE) internal/envoy_modules/generate-dockerfile.sh $(ENVOY_MODULES_DIR)/Cargo.toml
internal/envoy_modules/generate-dockerfile.sh $(ENVOY_MODULES_DIR) $< $@
$(ENVOY_MODULE_OUTPUT_DIR)/librust_module.so: $(ENVOY_MODULES_SRC_FILES) $(ENVOY_MODULE_DOCKERFILE)
mkdir -p $(ENVOY_MODULE_OUTPUT_DIR)
$(BUILDX_BUILD) \
$(PLATFORM) \
--output type=local,dest=$(ENVOY_MODULE_OUTPUT_DIR) \
--target export \
--build-arg RUST_BUILD_ARCH=$(RUST_BUILD_ARCH) \
-f $(ENVOY_MODULE_DOCKERFILE) \
$(ENVOY_MODULES_DIR)
$(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit: $(ENVOYINIT_DOCKERFILE)
cp $< $@
$(ENVOYINIT_OUTPUT_DIR)/docker-entrypoint.sh: cmd/envoyinit/docker-entrypoint.sh
cp $< $@
$(ENVOYINIT_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH): $(ENVOYINIT_OUTPUT_DIR)/envoyinit-linux-$(GOARCH) $(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit $(ENVOYINIT_OUTPUT_DIR)/docker-entrypoint.sh $(ENVOY_MODULE_OUTPUT_DIR)/librust_module.so
cp $(ENVOY_MODULE_OUTPUT_DIR)/librust_module.so $(ENVOYINIT_OUTPUT_DIR)/librust_module.so
$(BUILDX_BUILD) --load $(PLATFORM) $(ENVOYINIT_OUTPUT_DIR) -f $(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit \
--build-arg GOARCH=$(GOARCH) \
--build-arg ENVOY_IMAGE=$(ENVOY_IMAGE) \
--build-arg BASE_IMAGE=$(DISTROLESS_BASE_IMAGE) \
$(ENVOYINIT_CACHE_FROM) \
$(ENVOYINIT_LOCAL_CACHE_FROM_ARG) \
$(ENVOYINIT_LOCAL_CACHE_TO_ARG) \
-t $(IMAGE_REGISTRY)/$(ENVOYINIT_IMAGE_REPO):$(VERSION)
@touch $@
.PHONY: envoy-wrapper-docker
envoy-wrapper-docker: $(ENVOYINIT_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH)
#----------------------------------------------------------------------------------
# dummy idp (used in e2e tests)
#----------------------------------------------------------------------------------
DUMMY_IDP_DIR=hack/dummy-idp
DUMMY_IDP_OUTPUT_DIR=$(OUTPUT_DIR)/$(DUMMY_IDP_DIR)
export DUMMY_IDP_IMAGE_REPO ?= dummy-idp
DUMMY_IDP_VERSION=0.0.1
$(DUMMY_IDP_OUTPUT_DIR)/dummy-idp-linux-$(GOARCH): $(DUMMY_IDP_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ ./hack/dummy-idp...
.PHONY: dummy-idp
dummy-idp: $(DUMMY_IDP_OUTPUT_DIR)/dummy-idp-linux-$(GOARCH)
$(DUMMY_IDP_OUTPUT_DIR)/Dockerfile.dummy-idp: ./hack/dummy-idp/Dockerfile
cp $< $@
$(DUMMY_IDP_OUTPUT_DIR)/.docker-stamp-$(DUMMY_IDP_VERSION)-$(GOARCH): $(DUMMY_IDP_OUTPUT_DIR)/dummy-idp-linux-$(GOARCH) $(DUMMY_IDP_OUTPUT_DIR)/Dockerfile.dummy-idp
$(BUILDX_BUILD) --load $(PLATFORM) $(DUMMY_IDP_OUTPUT_DIR) -f $(DUMMY_IDP_OUTPUT_DIR)/Dockerfile.dummy-idp \
--build-arg GOARCH=$(GOARCH) \
--build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) \
-t $(IMAGE_REGISTRY)/$(DUMMY_IDP_IMAGE_REPO):$(DUMMY_IDP_VERSION)
@touch $@
.PHONY: dummy-idp-docker
dummy-idp-docker: $(DUMMY_IDP_OUTPUT_DIR)/.docker-stamp-$(DUMMY_IDP_VERSION)-$(GOARCH)
.PHONY: kind-load-dummy-idp
kind-load-dummy-idp:
$(KIND) load docker-image $(IMAGE_REGISTRY)/$(DUMMY_IDP_IMAGE_REPO):$(DUMMY_IDP_VERSION) --name $(CLUSTER_NAME)
#----------------------------------------------------------------------------------
# extproc-server (used in e2e tests)
#----------------------------------------------------------------------------------
EXTPROC_SERVER_DIR=test/e2e/defaults/extproc
EXTPROC_SERVER_OUTPUT_DIR=$(OUTPUT_DIR)/$(EXTPROC_SERVER_DIR)
export EXTPROC_SERVER_IMAGE_REPO ?= extproc-server
EXTPROC_SERVER_VERSION=0.0.1
$(EXTPROC_SERVER_OUTPUT_DIR)/.docker-stamp-$(EXTPROC_SERVER_VERSION)-$(GOARCH): $(shell find $(EXTPROC_SERVER_DIR) -name '*.go') $(EXTPROC_SERVER_DIR)/Dockerfile
$(BUILDX_BUILD) --load $(PLATFORM) $(EXTPROC_SERVER_DIR) -f $(EXTPROC_SERVER_DIR)/Dockerfile \
-t $(IMAGE_REGISTRY)/$(EXTPROC_SERVER_IMAGE_REPO):$(EXTPROC_SERVER_VERSION)
@mkdir -p $(dir $@)
@touch $@
.PHONY: extproc-server-docker
extproc-server-docker: $(EXTPROC_SERVER_OUTPUT_DIR)/.docker-stamp-$(EXTPROC_SERVER_VERSION)-$(GOARCH)
.PHONY: kind-load-extproc-server
kind-load-extproc-server:
$(KIND) load docker-image $(IMAGE_REGISTRY)/$(EXTPROC_SERVER_IMAGE_REPO):$(EXTPROC_SERVER_VERSION) --name $(CLUSTER_NAME)
#----------------------------------------------------------------------------------
# Helm
#----------------------------------------------------------------------------------
HELM ?= go tool helm
# It would be nice to use actual semver '--version', as Helm docs clearly state
# is intended (and yet is not enforced by 'helm lint'). Here we say '--version
# v2.0.0', not '--version 2.0.0', e.g. To do it cleanly, you'd probably
# repackage all published versions' charts and republish as vA.B.C and A.B.C
# both. Users would be surprised if their installation recipes had to change on
# some patch or minor version release. ('--app-version v2.0.0' is acceptable
# and in fact preferred since it matches our git tags and OCI image tags.)
HELM_PACKAGE_ARGS ?= --version $(VERSION) --app-version $(VERSION)
HELM_CHART_DIR=install/helm/kgateway
HELM_CHART_DIR_CRD=install/helm/kgateway-crds
.PHONY: package-kgateway-charts
package-kgateway-charts: package-kgateway-chart package-kgateway-crd-chart ## Package the kgateway charts
.PHONY: package-kgateway-chart
package-kgateway-chart: ## Package the kgateway charts
mkdir -p $(TEST_ASSET_DIR); \
$(HELM) package $(HELM_PACKAGE_ARGS) --destination $(TEST_ASSET_DIR) $(HELM_CHART_DIR); \
$(HELM) repo index $(TEST_ASSET_DIR);
.PHONY: package-kgateway-crd-chart
package-kgateway-crd-chart: ## Package the kgateway crd chart
mkdir -p $(TEST_ASSET_DIR); \
$(HELM) package $(HELM_PACKAGE_ARGS) --destination $(TEST_ASSET_DIR) $(HELM_CHART_DIR_CRD); \
$(HELM) repo index $(TEST_ASSET_DIR);
# VERSION_NO_V strips the leading 'v' from VERSION (e.g., v2.0.0 -> 2.0.0)
VERSION_NO_V := $(patsubst v%,%,$(VERSION))
CHART_NAMES := kgateway kgateway-crds
.PHONY: release-charts
release-charts: ## Release the kgateway charts (publishes both vX.Y.Z and X.Y.Z tags)
@for v in $(VERSION) $(VERSION_NO_V); do \
$(MAKE) package-kgateway-charts VERSION=$$v; \
for chart in $(CHART_NAMES); do \
$(HELM) push $(TEST_ASSET_DIR)/$$chart-$$v.tgz oci://$(IMAGE_REGISTRY)/charts; \
done; \
done
.PHONY: deploy-kgateway-crd-chart