Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
265 lines (202 loc) · 9.85 KB
/
Copy pathMakefile
File metadata and controls
265 lines (202 loc) · 9.85 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
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.31.0
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
GO_BUILD_TAGS ?= privileged
REGISTRY ?= registry.cn-hangzhou.aliyuncs.com/acs
GIT_COMMIT_SHORT ?= $(shell git rev-parse --short=8 HEAD 2>/dev/null)
BUILD_PLATFORMS ?= linux/amd64,linux/arm64
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.PHONY: all
all: build
##@ General
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./pkg/apis/..." output:crd:artifacts:config=pkg/apis/crds
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/apis/..."
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
GOOS=linux go vet --tags "$(GO_BUILD_TAGS)" ./...
.PHONY: test
test: datapath-test test-quick ## Run tests.
.PHONY: test-quick
test-quick: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -gcflags=all=-l -race --tags "$(GO_BUILD_TAGS)" $$(go list ./... | grep -Ev '/e2e|/mocks|/generated|/apis|/examples|/tests|/rpc|/windows|/internal/testutil|/cmd') -coverprofile coverage.txt
@grep -v "_gen.go" coverage.txt > coverage.tmp && mv coverage.tmp coverage.txt
.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter & yamllint
$(GOLANGCI_LINT) run
.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
$(GOLANGCI_LINT) run
.PHONY: datapath-test
datapath-test: ## Run datapath tests using the Makefile in tests/kind directory.
make -C tests/kind datapath-test
.PHONY: e2e-test
e2e-test: e2e-test-phased ## Run e2e functional tests in phases: connectivity → mutating → prefix (excludes upgrade and migrate).
.PHONY: e2e-test-connectivity
e2e-test-connectivity: ## Run read-only connectivity/networking e2e tests.
go test -v -count=1 -timeout 30m -parallel 2 -tags e2e ./tests \
-run 'Test(SharedENI_Connectivity|ExclusiveENI_Connectivity|SharedENI_NetworkPolicy|PodNetworking|SecurityGroup|Normal_Host|ConnectivityWithReport)' $(TESTARGS)
.PHONY: e2e-test-mutating
e2e-test-mutating: ## Run cluster-mutating e2e tests (IP pool, warm-up, reclaim, perf).
go test -v -count=1 -timeout 40m -parallel 2 -tags e2e ./tests \
-run 'Test(IPPool|SharedENI_HostPort|SharedENI_WarmUp|SharedENI_IdleIPReclaim|IPAllocationPerf)' $(TESTARGS)
.PHONY: e2e-test-prefix
e2e-test-prefix: ## Run IP prefix e2e tests.
go test -v -count=1 -timeout 60m -parallel 2 -tags e2e ./tests \
-run 'TestPrefix_' $(TESTARGS)
.PHONY: e2e-test-phased
e2e-test-phased: e2e-test-connectivity e2e-test-mutating e2e-test-prefix ## Run e2e tests in phases: connectivity → mutating → prefix.
.PHONY: e2e-upgrade-test
e2e-upgrade-test: ## Run e2e upgrade tests only.
go test -v -count=1 -timeout 60m -tags e2e ./tests -run 'TestUpgrade' $(TESTARGS)
.PHONY: e2e-upgrade-compat-test
e2e-upgrade-compat-test: ## Run terway upgrade compatibility tests (requires cluster + templates).
./tests/upgrade/run-upgrade-test.sh $(UPGRADE_ARGS)
.PHONY: e2e-migrate-test
e2e-migrate-test: ## Run e2e migration tests only.
go test -v -count=1 -timeout 120m -tags e2e ./tests -run 'TestMigrate' $(TESTARGS)
.PHONY: e2e-test-all
e2e-test-all: ## Run all e2e tests (functional + upgrade + migrate).
go test -v -count=1 -timeout 120m -tags e2e ./tests $(TESTARGS)
##@ ACK E2E Cluster
ACK_CLUSTER_DIR := hack/terraform/ack
# Each `ack-cluster-*` target materializes an isolated workdir under
# $(ACK_CLUSTER_DIR)/runs/, so multiple clusters can coexist (e.g. running
# byo-ipv4 and ack-dual side-by-side for comparison).
#
# `make ack-destroy WORKDIR=...` and `make ack-kubeconfig WORKDIR=...` accept
# an explicit workdir; without WORKDIR they default to the most recent run.
.PHONY: ack-cluster-byo-ipv4
ack-cluster-byo-ipv4: ## Create ACK cluster: ipv4, BYO CNI (helm-installed terway).
$(ACK_CLUSTER_DIR)/e2e-cluster.sh create byo-ipv4
.PHONY: ack-cluster-byo-dual
ack-cluster-byo-dual: ## Create ACK cluster: dual stack, BYO CNI (helm-installed terway).
$(ACK_CLUSTER_DIR)/e2e-cluster.sh create byo-dual
.PHONY: ack-cluster-byo-dual-cni-ipv6-default
ack-cluster-byo-dual-cni-ipv6-default: ## Create dual-stack ACK with IPv6-only Terway, default IPAM.
$(ACK_CLUSTER_DIR)/e2e-cluster.sh create byo-dual-cni-ipv6-default
.PHONY: ack-cluster-byo-dual-cni-ipv6-crd
ack-cluster-byo-dual-cni-ipv6-crd: ## Create dual-stack ACK with IPv6-only Terway, CRD IPAM.
$(ACK_CLUSTER_DIR)/e2e-cluster.sh create byo-dual-cni-ipv6-crd
.PHONY: ack-cluster-ack-ipv4
ack-cluster-ack-ipv4: ## Create ACK cluster: ipv4, terway-eniip installed by ACK addon.
$(ACK_CLUSTER_DIR)/e2e-cluster.sh create ack-ipv4
.PHONY: ack-cluster-ack-dual
ack-cluster-ack-dual: ## Create ACK cluster: dual stack, terway-eniip installed by ACK addon.
$(ACK_CLUSTER_DIR)/e2e-cluster.sh create ack-dual
.PHONY: ack-list
ack-list: ## List active ACK cluster workdirs.
@$(ACK_CLUSTER_DIR)/e2e-cluster.sh list
.PHONY: ack-destroy
ack-destroy: ## Destroy a workdir cluster. Use WORKDIR=<path> (defaults to most recent run).
@if [ -n "$(WORKDIR)" ]; then \
$(ACK_CLUSTER_DIR)/e2e-cluster.sh destroy "$(WORKDIR)"; \
else \
set -e; \
latest=$$(ls -dt $(ACK_CLUSTER_DIR)/runs/*/ 2>/dev/null | head -1); \
if [ -z "$$latest" ]; then echo "No runs found. Specify WORKDIR=<path>."; exit 1; fi; \
echo "WORKDIR not set; destroying most recent: $$latest"; \
$(ACK_CLUSTER_DIR)/e2e-cluster.sh destroy "$$latest"; \
fi
.PHONY: ack-kubeconfig
ack-kubeconfig: ## Print kubeconfig path. Use WORKDIR=<path> (defaults to most recent run).
@$(ACK_CLUSTER_DIR)/e2e-cluster.sh kubeconfig $(WORKDIR)
##@ Build
.PHONY: build
build: manifests generate fmt vet build-terway build-terway-controlplane
PUSH ?= false
BUILD_ARGS = --push=$(PUSH) --build-arg GIT_VERSION=$(GIT_COMMIT_SHORT) --platform $(BUILD_PLATFORMS)
ifdef GITHUB_ACTIONS
BUILD_ARGS += --cache-from type=gha,scope=$(GHA_SCOPE) --cache-to type=gha,scope=$(GHA_SCOPE)
endif
.PHONY: build-policy
build-policy: GHA_SCOPE = policy
build-policy:
docker buildx build $(BUILD_ARGS) -t $(REGISTRY)/terway:policy-$(GIT_COMMIT_SHORT) -f deploy/images/policy/Dockerfile .
.PHONY: build-terway
build-terway: GHA_SCOPE = terway
build-terway:
docker buildx build $(BUILD_ARGS) -t $(REGISTRY)/terway:$(GIT_COMMIT_SHORT) -f deploy/images/terway/Dockerfile .
.PHONY: build-terway-controlplane
build-terway-controlplane: GHA_SCOPE = controlplane
build-terway-controlplane:
docker buildx build $(BUILD_ARGS) -t $(REGISTRY)/terway-controlplane:$(GIT_COMMIT_SHORT) -f deploy/images/terway-controlplane/Dockerfile .
.PHONY: build-push
build-push: build-push-terway build-push-terway-controlplane
.PHONY: build-push-policy
build-push-policy: PUSH = true
build-push-policy: build-policy
.PHONY: build-push-terway
build-push-terway: PUSH = true
build-push-terway: build-terway
.PHONY: build-terway-controlplane
build-push-terway-controlplane: PUSH = true
build-push-terway-controlplane: build-terway-controlplane
##@ Dependencies
.PHONY: go-generate
go-generate:
@echo "Running go generate"
@go generate ./...
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Platform Information
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
PLATFORM_SUFFIX ?= $(GOOS)-$(GOARCH)
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.17.2
ENVTEST_VERSION ?= release-0.20
GOLANGCI_LINT_VERSION ?= v2.11.4
## Tool Binaries
KUBECTL ?= kubectl
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)-$(PLATFORM_SUFFIX)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)-$(PLATFORM_SUFFIX)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(PLATFORM_SUFFIX)
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
.PHONY: envtest
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
.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})
golangci-lint-docker:
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:${GOLANGCI_LINT_VERSION} golangci-lint run -v
# 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 (ideally with version and platform)
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f $(1) ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
binary_name=$$(basename $(2)) ;\
mv "$(LOCALBIN)/$${binary_name}" $(1) ;\
}
endef