This repository was archived by the owner on Sep 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathMakefile
More file actions
219 lines (176 loc) · 7.59 KB
/
Makefile
File metadata and controls
219 lines (176 loc) · 7.59 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
# ------------------------------------------------------------------------------
# Build Dependencies
# ------------------------------------------------------------------------------
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/build/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
CFSSL ?= $(LOCALBIN)/cfssl
CFSSLJSON ?= $(LOCALBIN)/cfssljson
ENVTEST ?= $(LOCALBIN)/setup-envtest
KIND ?= $(LOCALBIN)/kind
CLOUD_PROVIDER_KIND ?= $(LOCALBIN)/cloud-provider-kind
## Tool Versions
CFSSL_VERSION ?= v1.6.5
KUSTOMIZE_VERSION ?= v5.3.0
KIND_VERSION ?= v0.29.0
CLOUD_PROVIDER_KIND_VERSION ?= v0.6.0
# CFSSL config
TEST_CERTS_PATH ?= config/tests/auth/certs
.PHONY: cfssl
cfssl: $(CFSSL) ## Download cfssl locally if necessary
$(CFSSL): $(LOCALBIN)
test -s $(LOCALBIN)/cfssl || GOBIN=$(LOCALBIN) go install github.com/cloudflare/cfssl/cmd/cfssl@$(CFSSL_VERSION)
.PHONY: cfssljson
cfssljson: $(CFSSLJSON)
$(CFSSLJSON): $(LOCALBIN)
test -s $(LOCALBIN)/cfssljson || GOBIN=$(LOCALBIN) go install github.com/cloudflare/cfssl/cmd/cfssljson@$(CFSSL_VERSION)
.PHONY: cloud-provider-kind
cloud-provider-kind: $(CLOUD_PROVIDER_KIND)
$(CLOUD_PROVIDER_KIND): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/cloud-provider-kind@$(CLOUD_PROVIDER_KIND_VERSION)
.PHONY: kind
kind: $(CLOUD_PROVIDER_KIND) $(KIND)
$(KIND): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/kind@$(KIND_VERSION)
# ------------------------------------------------------------------------------
# Build
# ------------------------------------------------------------------------------
.PHONY: all
all: build
.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)
.PHONY: clean
clean: ## clean repo
cargo clean
rm $(TEST_CERTS_PATH)/{*.pem,*.csr}
.PHONY: build
build:
cargo xtask build-ebpf
cargo build
build.reuse:
CARGO_HOME="$(WORK_DIR)/target" RUSTUP_HOME="$(WORK_DIR)/target" cargo xtask build-ebpf
CARGO_HOME="$(WORK_DIR)/target" RUSTUP_HOME="$(WORK_DIR)/target" cargo build
.PHONY: build.release
build.release: ## Build dataplane release
cargo xtask build-ebpf --release
cargo build --release
# ------------------------------------------------------------------------------
# Build Images
# ------------------------------------------------------------------------------
# Container Runtimes
CONTAINER_RUNTIME ?= podman
# Container Images
REGISTRY ?= ghcr.io/kubernetes-sigs
BLIXT_CONTROLPLANE_IMAGE ?= $(REGISTRY)/blixt-controlplane
BLIXT_DATAPLANE_IMAGE ?= $(REGISTRY)/blixt-dataplane
BLIXT_UDP_SERVER_IMAGE ?= $(REGISTRY)/blixt-udp-test-server
TAG ?= integration-tests
# Containerfile paths for each service
CONTROLPLANE_CONTAINERFILE ?= build/Containerfile.controlplane
DATAPLANE_CONTAINERFILE ?= build/Containerfile.dataplane
UDP_SERVER_CONTAINERFILE ?= build/Containerfile.udp-test-server
UID = $(shell id -u)
GID = $(shell id -g)
WORK_DIR= $(shell pwd)
BUILD_TIMESTAMP = $(shell date +%s%3N)
CONTAINER_BUILD_ARGS = --userns=host --volume "$(WORK_DIR):/workspace" --volume "$(WORK_DIR)/target:$(WORK_DIR)/target/" \
--build-arg BUILD_TIMESTAMP="$(BUILD_TIMESTAMP)" --build-arg UID="$(UID)" --build-arg GID="$(GID)" --build-arg WORK_DIR="$(WORK_DIR)" $(BUILD_ARGS)
.PHONY: build.image.controlplane
build.image.controlplane:
mkdir -p target/
$(CONTAINER_RUNTIME) build $(CONTAINER_BUILD_ARGS) --file=$(CONTROLPLANE_CONTAINERFILE) --tag $(BLIXT_CONTROLPLANE_IMAGE):$(TAG)
.PHONY: build.image.udp-test-server
build.image.udp-test-server:
mkdir -p target/
$(CONTAINER_RUNTIME) build $(CONTAINER_BUILD_ARGS) --file=$(UDP_SERVER_CONTAINERFILE) --tag $(BLIXT_UDP_SERVER_IMAGE):$(TAG)
.PHONY: build.image.dataplane
build.image.dataplane:
mkdir -p target/
$(CONTAINER_RUNTIME) build $(CONTAINER_BUILD_ARGS) --file=$(DATAPLANE_CONTAINERFILE) --tag $(BLIXT_DATAPLANE_IMAGE):$(TAG)
.PHONY: build.all.images
build.all.images:
$(MAKE) build.image.controlplane
$(MAKE) build.image.dataplane
$(MAKE) build.image.udp-test-server
# ------------------------------------------------------------------------------
# Development
# ------------------------------------------------------------------------------
.PHONY: fix.format
fix.format.rust: ## Autofix Rust code formatting
cargo fmt --manifest-path Cargo.toml --all
.PHONY: check.format
check.format: ## Check Rust code formatting
cargo fmt --manifest-path Cargo.toml --all -- --check
.PHONY: lint
lint:
cargo clippy --workspace --all-targets --all-features -- -D warnings
# ------------------------------------------------------------------------------
# Testing
# ------------------------------------------------------------------------------
.PHONY: test
test:
cargo test -vv --workspace --exclude tests-integration
test.integration:
cargo test --package tests-integration
test.integration.reuse:
CARGO_HOME="$(WORK_DIR)/target" RUSTUP_HOME="$(WORK_DIR)/target" cargo test --package tests-integration
.PHONY: test.gencert
test.gencert: cfssl cfssljson
$(CFSSL) gencert \
-initca $(TEST_CERTS_PATH)/ca-csr.json | $(CFSSLJSON) -bare $(TEST_CERTS_PATH)/ca
$(CFSSL) gencert \
-ca=$(TEST_CERTS_PATH)/ca.pem \
-ca-key=$(TEST_CERTS_PATH)/ca-key.pem \
-config=$(TEST_CERTS_PATH)/ca-config.json \
-profile=server \
$(TEST_CERTS_PATH)/server-csr.json | $(CFSSLJSON) -bare $(TEST_CERTS_PATH)/server
$(CFSSL) gencert \
-ca=$(TEST_CERTS_PATH)/ca.pem \
-ca-key=$(TEST_CERTS_PATH)/ca-key.pem \
-config=$(TEST_CERTS_PATH)/ca-config.json \
-profile=clinet \
$(TEST_CERTS_PATH)/client-csr.json | $(CFSSLJSON) -bare $(TEST_CERTS_PATH)/client
.PHONY: test.rmcert
test.rmcert:
rm $(TEST_CERTS_PATH)/{*.pem,*.csr}
# ------------------------------------------------------------------------------
# Deployment
# ------------------------------------------------------------------------------
KIND_CLUSTER ?= blixt-dev
.PHONY: install
install: manifests
kubectl kustomize config/crd | kubectl apply -f -
.PHONY: uninstall
uninstall: manifests
kubectl kustomize config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
.PHONY: deploy
deploy: manifests
kubectl kustomize config/default | kubectl apply -f -
.PHONY: undeploy
undeploy:
kubectl kustomize config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
.PHONY: build.cluster
build.cluster: $(KIND)
$(KIND) create cluster --name $(KIND_CLUSTER)
echo "use $(CLOUD_PROVIDER_KIND) to enable LoadBalancer type Services"
.PHONY: load.image.controlplane
load.image.controlplane: build.image.controlplane
kubectl create namespace blixt-system || true && \
kind load docker-image $(BLIXT_CONTROLPLANE_IMAGE):$(TAG) --name $(KIND_CLUSTER) && \
kubectl -n blixt-system get deployment blixt-controlplane >/dev/null 2>&1 && \
kubectl -n blixt-system rollout restart deployment blixt-controlplane || true
.PHONY: load.image.dataplane
load.image.dataplane: build.image.dataplane
kubectl create namespace blixt-system || true && \
kind load docker-image $(BLIXT_DATAPLANE_IMAGE):$(TAG) --name $(KIND_CLUSTER) && \
kubectl -n blixt-system rollout restart daemonset dataplane || true
.PHONY: load.all.images
load.all.images: build.all.images
kind load docker-image $(BLIXT_CONTROLPLANE_IMAGE):$(TAG) --name $(KIND_CLUSTER) && \
kind load docker-image $(BLIXT_DATAPLANE_IMAGE):$(TAG) --name $(KIND_CLUSTER) && \
kind load docker-image $(BLIXT_UDP_SERVER_IMAGE):$(TAG) --name $(KIND_CLUSTER) && \
kubectl -n blixt-system get deployment blixt-controlplane >/dev/null 2>&1 && \
kubectl -n blixt-system rollout restart deployment blixt-controlplane || true