forked from cilium/cilium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.kind
372 lines (314 loc) · 16.6 KB
/
Makefile.kind
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
# Copyright Authors of Cilium
# SPDX-License-Identifier: Apache-2.0
##@ Development (Kind)
.PHONY: kind
kind: ## Create a kind cluster for Cilium development.
$(QUIET)SED=$(SED) ./contrib/scripts/kind.sh
.PHONY: kind-egressgw
kind-egressgw: ## Create a kind cluster for egress gateway Cilium development.
$(QUIET)SED=$(SED) WORKERS=3 ./contrib/scripts/kind.sh
kubectl patch node kind-worker3 --type=json -p='[{"op":"add","path":"/metadata/labels/cilium.io~1no-schedule","value":"true"}]'
.PHONY: kind-down
kind-down: ## Destroy a kind cluster for Cilium development.
$(QUIET)./contrib/scripts/kind-down.sh
.PHONY: kind-clustermesh
kind-clustermesh: ## Create two kind clusters for clustermesh development.
@echo " If you have problems with too many open file, check https://kind.sigs.k8s.io/docs/user/known-issues/#pod-errors-due-to-too-many-open-files"
$(QUIET) CLUSTER_NAME=clustermesh1 IPFAMILY=ipv4 PODSUBNET=10.1.0.0/16 SERVICESUBNET=172.20.1.0/24 ./contrib/scripts/kind.sh
$(QUIET) CLUSTER_NAME=clustermesh2 AGENTPORTPREFIX=236 OPERATORPORTPREFIX=237 IPFAMILY=ipv4 PODSUBNET=10.2.0.0/16 SERVICESUBNET=172.20.2.0/24 ./contrib/scripts/kind.sh
.PHONY: kind-clustermesh-down
kind-clustermesh-down: ## Destroy kind clusters for clustermesh development.
$(QUIET)./contrib/scripts/kind-down.sh clustermesh1 clustermesh2
.PHONY: kind-clustermesh-ready
kind-clustermesh-ready: ## Check if both kind clustermesh clusters exist
@$(ECHO_CHECK) clustermesh kind is ready...
@kind get clusters 2>&1 | grep "clustermesh1" \
&& exit 0 || exit 1
@kind get clusters 2>&1 | grep "clustermesh2" \
&& exit 0 || exit 1
.PHONY: kind-bgp-v4
kind-bgp-v4:
$(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-v4 deploy
.PHONY: kind-bgp-v4-down
kind-bgp-v4-down:
$(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-v4 destroy
.PHONY: kind-bgp-v4-apply-policy
kind-bgp-v4-apply-policy:
$(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-v4 apply-policy
.PHONY: kind-bgp-v6
kind-bgp-v6:
$(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-v6 deploy
.PHONY: kind-bgp-v6-down
kind-bgp-v6-down:
$(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-v6 destroy
.PHONY: kind-bgp-v6-apply-policy
kind-bgp-v6-apply-policy:
$(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-v6 apply-policy
.PHONY: kind-bgp-dual
kind-bgp-dual:
$(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-dual deploy
.PHONY: kind-bgp-dual-down
kind-bgp-dual-down:
$(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-dual destroy
.PHONY: kind-bgp-dual-apply-policy
kind-bgp-dual-apply-policy:
$(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-dual apply-policy
# Template for kind environment for a target. Parameters are:
# $(1) Makefile target name
define KIND_ENV
.PHONY: $(1)
$(1): export DOCKER_REGISTRY=localhost:5000
$(1): export LOCAL_AGENT_IMAGE=$$(DOCKER_REGISTRY)/$$(DOCKER_DEV_ACCOUNT)/cilium-dev:$$(LOCAL_IMAGE_TAG)
$(1): export LOCAL_OPERATOR_IMAGE=$$(DOCKER_REGISTRY)/$$(DOCKER_DEV_ACCOUNT)/operator-generic:$$(LOCAL_IMAGE_TAG)
$(1): export LOCAL_CLUSTERMESH_IMAGE=$$(DOCKER_REGISTRY)/$$(DOCKER_DEV_ACCOUNT)/clustermesh-apiserver:$$(LOCAL_IMAGE_TAG)
endef
$(eval $(call KIND_ENV,kind-clustermesh-images))
kind-clustermesh-images: kind-clustermesh-ready kind-build-clustermesh-apiserver kind-build-image-agent kind-build-image-operator ## Builds images and imports them into clustermesh clusters
$(QUIET)kind load docker-image $(LOCAL_CLUSTERMESH_IMAGE) --name clustermesh1
$(QUIET)kind load docker-image $(LOCAL_CLUSTERMESH_IMAGE) --name clustermesh2
$(QUIET)kind load docker-image $(LOCAL_AGENT_IMAGE) --name clustermesh1
$(QUIET)kind load docker-image $(LOCAL_AGENT_IMAGE) --name clustermesh2
$(QUIET)kind load docker-image $(LOCAL_OPERATOR_IMAGE) --name clustermesh1
$(QUIET)kind load docker-image $(LOCAL_OPERATOR_IMAGE) --name clustermesh2
.PHONY: kind-connect-clustermesh ## Connect the ClusterMesh clusters.
kind-connect-clustermesh: kind-clustermesh-ready
@echo " CONNECT the two clusters"
$(CILIUM_CLI) clustermesh connect --context kind-clustermesh1 --destination-context kind-clustermesh2
$(CILIUM_CLI) clustermesh status --context kind-clustermesh1 --wait
$(CILIUM_CLI) clustermesh status --context kind-clustermesh2 --wait
ENABLE_KVSTOREMESH ?= false
$(eval $(call KIND_ENV,kind-install-cilium-clustermesh))
kind-install-cilium-clustermesh: kind-clustermesh-ready ## Install a local Cilium version into the clustermesh clusters and enable clustermesh.
@echo " INSTALL cilium on clustermesh1 cluster"
-$(CILIUM_CLI) --context=kind-clustermesh1 uninstall >/dev/null
$(CILIUM_CLI) --context=kind-clustermesh1 install \
--chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \
--values=$(ROOT_DIR)/contrib/testing/kind-clustermesh1.yaml \
--set=image.override=$(LOCAL_AGENT_IMAGE) \
--set=operator.image.override=$(LOCAL_OPERATOR_IMAGE) \
--set=clustermesh.apiserver.image.override=$(LOCAL_CLUSTERMESH_IMAGE) \
--set=clustermesh.apiserver.kvstoremesh.enabled=$(ENABLE_KVSTOREMESH)
@echo " INSTALL cilium on clustermesh2 cluster"
-$(CILIUM_CLI) --context=kind-clustermesh2 uninstall >/dev/null
$(KUBECTL) --context=kind-clustermesh1 get secret -n kube-system cilium-ca -o yaml | \
$(KUBECTL) --context=kind-clustermesh2 replace --force -f -
$(CILIUM_CLI) --context=kind-clustermesh2 install \
--chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \
--values=$(ROOT_DIR)/contrib/testing/kind-clustermesh2.yaml \
--set=image.override=$(LOCAL_AGENT_IMAGE) \
--set=operator.image.override=$(LOCAL_OPERATOR_IMAGE) \
--set=clustermesh.apiserver.image.override=$(LOCAL_CLUSTERMESH_IMAGE) \
--set=clustermesh.apiserver.kvstoremesh.enabled=$(ENABLE_KVSTOREMESH)
$(MAKE) kind-connect-clustermesh
.PHONY: kind-install-cilium-clustermesh-fast
kind-install-cilium-clustermesh-fast: kind-clustermesh-ready ## "Fast" Install a local Cilium version using volume-mounted binaries into the ClusterMesh clusters and enable ClusterMesh.
@echo " INSTALL cilium on clustermesh1 cluster"
docker pull quay.io/cilium/cilium-ci:latest
kind load docker-image --name clustermesh1 quay.io/cilium/cilium-ci:latest
-$(CILIUM_CLI) --context=kind-clustermesh1 uninstall >/dev/null
$(CILIUM_CLI) --context=kind-clustermesh1 install \
--chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \
--values=$(ROOT_DIR)/contrib/testing/kind-clustermesh1.yaml \
--values=$(ROOT_DIR)/contrib/testing/kind-fast.yaml \
--set=clustermesh.apiserver.kvstoremesh.enabled=$(ENABLE_KVSTOREMESH)
@echo " INSTALL cilium on clustermesh2 cluster"
kind load docker-image --name clustermesh2 quay.io/cilium/cilium-ci:latest
-$(CILIUM_CLI) --context=kind-clustermesh2 uninstall >/dev/null
$(KUBECTL) --context=kind-clustermesh1 get secret -n kube-system cilium-ca -o yaml | \
$(KUBECTL) --context=kind-clustermesh2 replace --force -f -
$(CILIUM_CLI) --context=kind-clustermesh2 install \
--chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \
--values=$(ROOT_DIR)/contrib/testing/kind-clustermesh2.yaml \
--values=$(ROOT_DIR)/contrib/testing/kind-fast.yaml \
--set=clustermesh.apiserver.kvstoremesh.enabled=$(ENABLE_KVSTOREMESH)
$(MAKE) kind-image-fast
$(MAKE) kind-connect-clustermesh
KIND_CLUSTER_NAME ?= $(shell kind get clusters -q | head -n1)
.PHONY: kind-ready
kind-ready:
@$(ECHO_CHECK) kind-ready
@if [ -n "$(shell kind get clusters -q)" ]; then echo "kind is ready"; else echo "kind not ready"; exit 1; fi
$(eval $(call KIND_ENV,kind-build-image-agent))
kind-build-image-agent: ## Build cilium-dev docker image
$(QUIET)$(MAKE) dev-docker-image$(DEBUGGER_SUFFIX) DOCKER_IMAGE_TAG=$(LOCAL_IMAGE_TAG)
$(eval $(call KIND_ENV,kind-image-agent))
kind-image-agent: kind-ready kind-build-image-agent ## Build cilium-dev docker image and import it into kind.
$(QUIET)kind load docker-image $(LOCAL_AGENT_IMAGE) -n $(KIND_CLUSTER_NAME)
$(eval $(call KIND_ENV,kind-build-image-operator))
kind-build-image-operator: ## Build cilium-operator-dev docker image
$(QUIET)$(MAKE) dev-docker-operator-generic-image$(DEBUGGER_SUFFIX) DOCKER_IMAGE_TAG=$(LOCAL_IMAGE_TAG)
$(eval $(call KIND_ENV,kind-image-operator))
kind-image-operator: kind-ready kind-build-image-operator ## Build cilium-operator-dev docker image and import it into kind.
$(QUIET)kind load docker-image $(LOCAL_OPERATOR_IMAGE) -n $(KIND_CLUSTER_NAME)
$(eval $(call KIND_ENV,kind-build-clustermesh-apiserver))
kind-build-clustermesh-apiserver: ## Build cilium-clustermesh-apiserver docker image
$(QUIET)$(MAKE) docker-clustermesh-apiserver-image DOCKER_IMAGE_TAG=$(LOCAL_IMAGE_TAG)
.PHONY: kind-image
kind-image: ## Build cilium and operator images and import them into kind.
$(MAKE) kind-image-agent
$(MAKE) kind-image-operator
define KIND_VALUES_FAST_FILES
--helm-values=$(ROOT_DIR)/contrib/testing/kind-common.yaml \
--helm-values=$(ROOT_DIR)/contrib/testing/kind-fast.yaml
endef
ifneq ("$(wildcard $(ROOT_DIR)/contrib/testing/kind-custom.yaml)","")
KIND_VALUES_FAST_FILES := $(KIND_VALUES_FAST_FILES) --helm-values=$(ROOT_DIR)/contrib/testing/kind-custom.yaml
endif
.PHONY: kind-install-cilium-fast
kind-install-cilium-fast: kind-ready ## "Fast" Install a local Cilium version using volume-mounted binaries into all clusters.
@echo " INSTALL cilium"
docker pull quay.io/cilium/cilium-ci:latest
for cluster_name in $${KIND_CLUSTERS:-$(shell kind get clusters)}; do \
kind load docker-image --name $$cluster_name quay.io/cilium/cilium-ci:latest; \
$(CILIUM_CLI) --context=kind-$$cluster_name uninstall >/dev/null 2>&1 || true; \
$(CILIUM_CLI) install --context=kind-$$cluster_name \
--chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \
$(KIND_VALUES_FAST_FILES) \
--version= >/dev/null 2>&1 & \
done
.PHONY: build-cli
build-cli: ## Build cilium cli binary
$(QUIET)$(MAKE) -C cilium-dbg GOOS=linux
.PHONY: build-agent
build-agent: ## Build cilium daemon binary
$(QUIET)$(MAKE) -C daemon GOOS=linux
.PHONY: build-operator
build-operator: ## Build cilium operator binary
$(QUIET)$(MAKE) -C operator cilium-operator-generic GOOS=linux
.PHONY: build-clustermesh-apiserver
build-clustermesh-apiserver: ## Build cilium clustermesh-apiserver binary
$(QUIET)$(MAKE) -C clustermesh-apiserver GOOS=linux
.PHONY: kind-image-fast-agent
kind-image-fast-agent: kind-ready build-cli build-agent ## Build cilium cli and daemon binaries. Copy the bins and bpf files to kind nodes.
$(eval dst:=/cilium-binaries)
for cluster_name in $${KIND_CLUSTERS:-$(shell kind get clusters)}; do \
for node_name in $$(kind get nodes -n "$$cluster_name"); do \
docker exec -ti $${node_name} mkdir -p "${dst}"; \
\
docker exec -ti $${node_name} rm -rf "${dst}/var/lib/cilium"; \
docker exec -ti $${node_name} mkdir -p "${dst}/var/lib/cilium"; \
docker cp "./bpf/" $${node_name}:"${dst}/var/lib/cilium/bpf"; \
docker exec -ti $${node_name} find "${dst}/var/lib/cilium/bpf" -type f -exec chmod 0644 {} + ;\
\
docker exec -ti $${node_name} rm -f "${dst}/cilium-dbg"; \
docker cp "./cilium-dbg/cilium-dbg" $${node_name}:"${dst}"; \
docker exec -ti $${node_name} chmod +x "${dst}/cilium-dbg"; \
\
docker exec -ti $${node_name} rm -f "${dst}/cilium-agent"; \
docker cp "./daemon/cilium-agent" $${node_name}:"${dst}"; \
docker exec -ti $${node_name} chmod +x "${dst}/cilium-agent"; \
done; \
kubectl --context=kind-$${cluster_name} delete pods -n kube-system -l k8s-app=cilium --force; \
done
.PHONY: kind-image-fast-operator
kind-image-fast-operator: kind-ready build-operator ## Build cilium operator binary and copy it to all kind nodes.
$(eval dst:=/cilium-binaries)
for cluster_name in $${KIND_CLUSTERS:-$(shell kind get clusters)}; do \
for node_name in $$(kind get nodes -n "$$cluster_name"); do \
docker exec -ti $${node_name} mkdir -p "${dst}"; \
\
docker exec -ti $${node_name} rm -f "${dst}/cilium-operator-generic"; \
docker cp "./operator/cilium-operator-generic" $${node_name}:"${dst}"; \
docker exec -ti $${node_name} chmod +x "${dst}/cilium-operator-generic"; \
done; \
kubectl --context=kind-$${cluster_name} delete pods -n kube-system -l name=cilium-operator --force; \
done
.PHONY: kind-image-fast-clustermesh-apiserver
kind-image-fast-clustermesh-apiserver: kind-ready build-clustermesh-apiserver ## Build clustermesh-apiserver binary and copy it to all kind nodes.
$(eval dst:=/cilium-binaries)
for cluster_name in $${KIND_CLUSTERS:-$(shell kind get clusters)}; do \
for node_name in $$(kind get nodes -n "$$cluster_name"); do \
docker exec -ti $${node_name} mkdir -p "${dst}"; \
\
docker exec -ti $${node_name} rm -f "${dst}/clustermesh-apiserver"; \
docker cp "./clustermesh-apiserver/clustermesh-apiserver" $${node_name}:"${dst}"; \
docker exec -ti $${node_name} chmod +x "${dst}/clustermesh-apiserver"; \
done; \
kubectl --context=kind-$${cluster_name} delete pods -n kube-system -l k8s-app=clustermesh-apiserver --force; \
done
.PHONY: kind-image-fast
kind-image-fast: kind-image-fast-agent kind-image-fast-operator kind-image-fast-clustermesh-apiserver ## Build all binaries and copy them to kind nodes.
define KIND_VALUES_FILES
--helm-values=$(ROOT_DIR)/contrib/testing/kind-common.yaml \
--helm-values=$(ROOT_DIR)/contrib/testing/kind-values.yaml
endef
ifneq ("$(wildcard $(ROOT_DIR)/contrib/testing/kind-custom.yaml)","")
KIND_VALUES_FILES := $(KIND_VALUES_FILES) --helm-values=$(ROOT_DIR)/contrib/testing/kind-custom.yaml
endif
.PHONY: kind-install-cilium
kind-install-cilium: kind-ready ## Install a local Cilium version into the cluster.
@echo " INSTALL cilium"
# cilium-cli doesn't support idempotent installs, so we uninstall and
# reinstall here. https://github.com/cilium/cilium-cli/issues/205
-@$(CILIUM_CLI) uninstall >/dev/null 2>&1 || true
# cilium-cli's --wait flag doesn't work, so we just force it to run
# in the background instead and wait for the resources to be available.
# https://github.com/cilium/cilium-cli/issues/1070
$(CILIUM_CLI) install \
--chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \
$(KIND_VALUES_FILES) \
--version= \
>/dev/null 2>&1 &
.PHONY: kind-egressgw-install-cilium
kind-egressgw-install-cilium: kind-ready ## Install a local Cilium version into the cluster.
@echo " INSTALL cilium"
# cilium-cli doesn't support idempotent installs, so we uninstall and
# reinstall here. https://github.com/cilium/cilium-cli/issues/205
-@$(CILIUM_CLI) uninstall >/dev/null 2>&1 || true
# cilium-cli's --wait flag doesn't work, so we just force it to run
# in the background instead and wait for the resources to be available.
# https://github.com/cilium/cilium-cli/issues/1070
$(CILIUM_CLI) install \
--chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \
$(KIND_VALUES_FILES) \
--helm-values=$(ROOT_DIR)/contrib/testing/kind-egressgw-values.yaml \
--nodes-without-cilium=kind-worker3 \
--version= \
>/dev/null 2>&1 &
.PHONY: kind-uninstall-cilium
kind-uninstall-cilium: ## Uninstall Cilium from the cluster.
@echo " UNINSTALL cilium"
-$(CILIUM_CLI) uninstall
.PHONY: kind-check-cilium
kind-check-cilium:
@echo " CHECK cilium is ready..."
$(CILIUM_CLI) status --wait --wait-duration 1s >/dev/null 2>/dev/null
# Template for kind debug targets. Parameters are:
# $(1) agent target
define DEBUG_KIND_TEMPLATE
.PHONY: kind-image$(1)-debug
kind-image$(1)-debug: export DEBUGGER_SUFFIX=-debug
kind-image$(1)-debug: export NOSTRIP=1
kind-image$(1)-debug: export NOOPT=1
kind-image$(1)-debug: ## Build cilium$(1) docker image with a dlv debugger wrapper and import it into kind.
$(MAKE) kind-image$(1)
endef
# kind-image-agent-debug
$(eval $(call DEBUG_KIND_TEMPLATE,-agent))
# kind-image-operator-debug
$(eval $(call DEBUG_KIND_TEMPLATE,-operator))
$(eval $(call KIND_ENV,kind-debug-agent))
kind-debug-agent: ## Create a local kind development environment with cilium-agent attached to a debugger.
$(QUIET)$(MAKE) kind-ready 2>/dev/null \
|| $(MAKE) kind
$(MAKE) kind-image-agent-debug
# Not debugging cilium-operator here; any image is good enough.
kind load docker-image $(LOCAL_OPERATOR_IMAGE) \
|| $(MAKE) kind-image-operator
$(MAKE) kind-check-cilium 2>/dev/null \
|| $(MAKE) kind-install-cilium
@echo "Attach delve to localhost on these ports to continue:"
@echo " - 23401: cilium-agent (kind-control-plane)"
@echo " - 23411: cilium-agent (kind-worker)"
$(eval $(call KIND_ENV,kind-debug))
kind-debug: ## Create a local kind development environment with cilium-agent & cilium-operator attached to a debugger.
$(QUIET)$(MAKE) kind-ready 2>/dev/null \
|| $(MAKE) kind
$(MAKE) kind-image-agent-debug
$(MAKE) kind-image-operator-debug
$(MAKE) kind-check-cilium 2>/dev/null \
|| $(MAKE) kind-install-cilium
@echo "Attach delve to localhost on these ports to continue:"
@echo " - 23401: cilium-agent (kind-control-plane)"
@echo " - 23411: cilium-agent (kind-worker)"
@echo " - 23511: cilium-operator (kind-worker)"