github.com/cilium/cilium@v1.16.2/Makefile.kind (about) 1 # Copyright Authors of Cilium 2 # SPDX-License-Identifier: Apache-2.0 3 4 ##@ Development (Kind) 5 6 .PHONY: kind 7 kind: ## Create a kind cluster for Cilium development. 8 $(QUIET)SED=$(SED) ./contrib/scripts/kind.sh 9 10 .PHONY: kind-egressgw 11 kind-egressgw: ## Create a kind cluster for egress gateway Cilium development. 12 $(QUIET)SED=$(SED) WORKERS=3 ./contrib/scripts/kind.sh 13 kubectl patch node kind-worker3 --type=json -p='[{"op":"add","path":"/metadata/labels/cilium.io~1no-schedule","value":"true"}]' 14 15 .PHONY: kind-down 16 kind-down: ## Destroy a kind cluster for Cilium development. 17 $(QUIET)./contrib/scripts/kind-down.sh 18 19 .PHONY: kind-clustermesh 20 kind-clustermesh: ## Create two kind clusters for clustermesh development. 21 @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" 22 $(QUIET) CLUSTER_NAME=clustermesh1 IPFAMILY=dual PODSUBNET=10.1.0.0/16,fd00:10:1::/48 SERVICESUBNET=172.20.1.0/24,fd00:10:f1::/112 ./contrib/scripts/kind.sh 23 $(QUIET) CLUSTER_NAME=clustermesh2 AGENTPORTPREFIX=236 OPERATORPORTPREFIX=237 IPFAMILY=dual PODSUBNET=10.2.0.0/16,fd00:10:2::/48 SERVICESUBNET=172.20.2.0/24,fd00:10:f2::/112 ./contrib/scripts/kind.sh 24 25 .PHONY: kind-clustermesh-down 26 kind-clustermesh-down: ## Destroy kind clusters for clustermesh development. 27 $(QUIET)./contrib/scripts/kind-down.sh clustermesh1 clustermesh2 28 29 .PHONY: kind-clustermesh-ready 30 kind-clustermesh-ready: ## Check if both kind clustermesh clusters exist 31 @$(ECHO_CHECK) clustermesh kind is ready... 32 @kind get clusters 2>&1 | grep "clustermesh1" \ 33 && exit 0 || exit 1 34 @kind get clusters 2>&1 | grep "clustermesh2" \ 35 && exit 0 || exit 1 36 37 .PHONY: kind-bgp-v4 38 kind-bgp-v4: 39 $(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-v4 deploy 40 41 .PHONY: kind-bgp-v4-down 42 kind-bgp-v4-down: 43 $(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-v4 destroy 44 45 .PHONY: kind-bgp-v4-apply-policy 46 kind-bgp-v4-apply-policy: 47 $(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-v4 apply-policy 48 49 .PHONY: kind-bgp-v6 50 kind-bgp-v6: 51 $(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-v6 deploy 52 53 .PHONY: kind-bgp-v6-down 54 kind-bgp-v6-down: 55 $(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-v6 destroy 56 57 .PHONY: kind-bgp-v6-apply-policy 58 kind-bgp-v6-apply-policy: 59 $(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-v6 apply-policy 60 61 .PHONY: kind-bgp-dual 62 kind-bgp-dual: 63 $(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-dual deploy 64 65 .PHONY: kind-bgp-dual-down 66 kind-bgp-dual-down: 67 $(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-dual destroy 68 69 .PHONY: kind-bgp-dual-apply-policy 70 kind-bgp-dual-apply-policy: 71 $(QUIET) $(MAKE) -C contrib/containerlab/bgp-cplane-dev-dual apply-policy 72 73 # Template for kind environment for a target. Parameters are: 74 # $(1) Makefile target name 75 define KIND_ENV 76 .PHONY: $(1) 77 $(1): export DOCKER_REGISTRY=localhost:5000 78 $(1): export LOCAL_AGENT_IMAGE=$$(DOCKER_REGISTRY)/$$(DOCKER_DEV_ACCOUNT)/cilium-dev:$$(LOCAL_IMAGE_TAG) 79 $(1): export LOCAL_OPERATOR_IMAGE=$$(DOCKER_REGISTRY)/$$(DOCKER_DEV_ACCOUNT)/operator-generic:$$(LOCAL_IMAGE_TAG) 80 $(1): export LOCAL_CLUSTERMESH_IMAGE=$$(DOCKER_REGISTRY)/$$(DOCKER_DEV_ACCOUNT)/clustermesh-apiserver:$$(LOCAL_IMAGE_TAG) 81 endef 82 83 $(eval $(call KIND_ENV,kind-clustermesh-images)) 84 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 85 $(QUIET)kind load docker-image $(LOCAL_CLUSTERMESH_IMAGE) --name clustermesh1 86 $(QUIET)kind load docker-image $(LOCAL_CLUSTERMESH_IMAGE) --name clustermesh2 87 $(QUIET)kind load docker-image $(LOCAL_AGENT_IMAGE) --name clustermesh1 88 $(QUIET)kind load docker-image $(LOCAL_AGENT_IMAGE) --name clustermesh2 89 $(QUIET)kind load docker-image $(LOCAL_OPERATOR_IMAGE) --name clustermesh1 90 $(QUIET)kind load docker-image $(LOCAL_OPERATOR_IMAGE) --name clustermesh2 91 92 .PHONY: kind-connect-clustermesh ## Connect the ClusterMesh clusters. 93 kind-connect-clustermesh: check_deps kind-clustermesh-ready 94 @echo " CONNECT the two clusters" 95 $(CILIUM_CLI) clustermesh connect --context kind-clustermesh1 --destination-context kind-clustermesh2 96 $(CILIUM_CLI) clustermesh status --context kind-clustermesh1 --wait 97 $(CILIUM_CLI) clustermesh status --context kind-clustermesh2 --wait 98 99 ENABLE_KVSTOREMESH ?= true 100 $(eval $(call KIND_ENV,kind-install-cilium-clustermesh)) 101 kind-install-cilium-clustermesh: check_deps kind-clustermesh-ready ## Install a local Cilium version into the clustermesh clusters and enable clustermesh. 102 @echo " INSTALL cilium on clustermesh1 cluster" 103 -$(CILIUM_CLI) --context=kind-clustermesh1 uninstall >/dev/null 104 $(CILIUM_CLI) --context=kind-clustermesh1 install \ 105 --chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \ 106 --values=$(ROOT_DIR)/contrib/testing/kind-clustermesh1.yaml \ 107 --set=image.override=$(LOCAL_AGENT_IMAGE) \ 108 --set=operator.image.override=$(LOCAL_OPERATOR_IMAGE) \ 109 --set=clustermesh.apiserver.image.override=$(LOCAL_CLUSTERMESH_IMAGE) \ 110 --set=clustermesh.apiserver.kvstoremesh.enabled=$(ENABLE_KVSTOREMESH) 111 112 @echo " INSTALL cilium on clustermesh2 cluster" 113 -$(CILIUM_CLI) --context=kind-clustermesh2 uninstall >/dev/null 114 $(KUBECTL) --context=kind-clustermesh1 get secret -n kube-system cilium-ca -o yaml | \ 115 $(KUBECTL) --context=kind-clustermesh2 replace --force -f - 116 $(CILIUM_CLI) --context=kind-clustermesh2 install \ 117 --chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \ 118 --values=$(ROOT_DIR)/contrib/testing/kind-clustermesh2.yaml \ 119 --set=image.override=$(LOCAL_AGENT_IMAGE) \ 120 --set=operator.image.override=$(LOCAL_OPERATOR_IMAGE) \ 121 --set=clustermesh.apiserver.image.override=$(LOCAL_CLUSTERMESH_IMAGE) \ 122 --set=clustermesh.apiserver.kvstoremesh.enabled=$(ENABLE_KVSTOREMESH) 123 124 $(MAKE) kind-connect-clustermesh 125 126 .PHONY: kind-install-cilium-clustermesh-fast 127 kind-install-cilium-clustermesh-fast: check_deps kind-clustermesh-ready ## "Fast" Install a local Cilium version using volume-mounted binaries into the ClusterMesh clusters and enable ClusterMesh. 128 @echo " INSTALL cilium on clustermesh1 cluster" 129 docker pull quay.io/cilium/cilium-ci:latest 130 kind load docker-image --name clustermesh1 quay.io/cilium/cilium-ci:latest 131 -$(CILIUM_CLI) --context=kind-clustermesh1 uninstall >/dev/null 132 $(CILIUM_CLI) --context=kind-clustermesh1 install \ 133 --chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \ 134 --values=$(ROOT_DIR)/contrib/testing/kind-clustermesh1.yaml \ 135 --values=$(ROOT_DIR)/contrib/testing/kind-fast.yaml \ 136 --set=clustermesh.apiserver.kvstoremesh.enabled=$(ENABLE_KVSTOREMESH) 137 138 @echo " INSTALL cilium on clustermesh2 cluster" 139 kind load docker-image --name clustermesh2 quay.io/cilium/cilium-ci:latest 140 -$(CILIUM_CLI) --context=kind-clustermesh2 uninstall >/dev/null 141 $(KUBECTL) --context=kind-clustermesh1 get secret -n kube-system cilium-ca -o yaml | \ 142 $(KUBECTL) --context=kind-clustermesh2 replace --force -f - 143 $(CILIUM_CLI) --context=kind-clustermesh2 install \ 144 --chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \ 145 --values=$(ROOT_DIR)/contrib/testing/kind-clustermesh2.yaml \ 146 --values=$(ROOT_DIR)/contrib/testing/kind-fast.yaml \ 147 --set=clustermesh.apiserver.kvstoremesh.enabled=$(ENABLE_KVSTOREMESH) 148 149 $(MAKE) kind-image-fast 150 $(MAKE) kind-connect-clustermesh 151 152 KIND_CLUSTER_NAME ?= $(shell kind get clusters -q | head -n1) 153 154 .PHONY: kind-ready 155 kind-ready: 156 @$(ECHO_CHECK) kind-ready 157 @if [ -n "$(shell kind get clusters -q)" ]; then echo "kind is ready"; else echo "kind not ready"; exit 1; fi 158 159 $(eval $(call KIND_ENV,kind-build-image-agent)) 160 kind-build-image-agent: ## Build cilium-dev docker image 161 $(QUIET)$(MAKE) dev-docker-image$(DEBUGGER_SUFFIX) DOCKER_IMAGE_TAG=$(LOCAL_IMAGE_TAG) 162 163 $(eval $(call KIND_ENV,kind-image-agent)) 164 kind-image-agent: kind-ready kind-build-image-agent ## Build cilium-dev docker image and import it into kind. 165 $(QUIET)kind load docker-image $(LOCAL_AGENT_IMAGE) -n $(KIND_CLUSTER_NAME) 166 167 $(eval $(call KIND_ENV,kind-build-image-operator)) 168 kind-build-image-operator: ## Build cilium-operator-dev docker image 169 $(QUIET)$(MAKE) dev-docker-operator-generic-image$(DEBUGGER_SUFFIX) DOCKER_IMAGE_TAG=$(LOCAL_IMAGE_TAG) 170 171 $(eval $(call KIND_ENV,kind-image-operator)) 172 kind-image-operator: kind-ready kind-build-image-operator ## Build cilium-operator-dev docker image and import it into kind. 173 $(QUIET)kind load docker-image $(LOCAL_OPERATOR_IMAGE) -n $(KIND_CLUSTER_NAME) 174 175 $(eval $(call KIND_ENV,kind-build-clustermesh-apiserver)) 176 kind-build-clustermesh-apiserver: ## Build cilium-clustermesh-apiserver docker image 177 $(QUIET)$(MAKE) docker-clustermesh-apiserver-image DOCKER_IMAGE_TAG=$(LOCAL_IMAGE_TAG) 178 179 .PHONY: kind-image 180 kind-image: ## Build cilium and operator images and import them into kind. 181 $(MAKE) kind-image-agent 182 $(MAKE) kind-image-operator 183 184 define KIND_VALUES_FAST_FILES 185 --helm-values=$(ROOT_DIR)/contrib/testing/kind-common.yaml \ 186 --helm-values=$(ROOT_DIR)/contrib/testing/kind-fast.yaml 187 endef 188 189 ifneq ("$(wildcard $(ROOT_DIR)/contrib/testing/kind-custom.yaml)","") 190 KIND_VALUES_FAST_FILES := $(KIND_VALUES_FAST_FILES) --helm-values=$(ROOT_DIR)/contrib/testing/kind-custom.yaml 191 endif 192 193 .PHONY: kind-install-cilium-fast 194 kind-install-cilium-fast: check_deps kind-ready ## "Fast" Install a local Cilium version using volume-mounted binaries into all clusters. 195 @echo " INSTALL cilium" 196 docker pull quay.io/cilium/cilium-ci:latest 197 for cluster_name in $${KIND_CLUSTERS:-$(shell kind get clusters)}; do \ 198 kind load docker-image --name $$cluster_name quay.io/cilium/cilium-ci:latest; \ 199 $(CILIUM_CLI) --context=kind-$$cluster_name uninstall >/dev/null 2>&1 || true; \ 200 $(CILIUM_CLI) install --context=kind-$$cluster_name \ 201 --chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \ 202 $(KIND_VALUES_FAST_FILES) \ 203 --version= >/dev/null 2>&1 & \ 204 done 205 206 .PHONY: build-cli 207 build-cli: ## Build cilium cli binary 208 $(QUIET)$(MAKE) -C cilium-dbg GOOS=linux 209 210 .PHONY: build-agent 211 build-agent: ## Build cilium daemon binary 212 $(QUIET)$(MAKE) -C daemon GOOS=linux 213 214 .PHONY: build-operator 215 build-operator: ## Build cilium operator binary 216 $(QUIET)$(MAKE) -C operator cilium-operator-generic GOOS=linux 217 218 .PHONY: build-clustermesh-apiserver 219 build-clustermesh-apiserver: ## Build cilium clustermesh-apiserver binary 220 $(QUIET)$(MAKE) -C clustermesh-apiserver GOOS=linux 221 222 .PHONY: kind-image-fast-agent 223 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. 224 $(eval dst:=/cilium-binaries) 225 for cluster_name in $${KIND_CLUSTERS:-$(shell kind get clusters)}; do \ 226 for node_name in $$(kind get nodes -n "$$cluster_name"); do \ 227 docker exec $${node_name} mkdir -p "${dst}"; \ 228 \ 229 docker exec $${node_name} rm -rf "${dst}/var/lib/cilium"; \ 230 docker exec $${node_name} mkdir -p "${dst}/var/lib/cilium"; \ 231 docker cp "./bpf/" $${node_name}:"${dst}/var/lib/cilium/bpf"; \ 232 docker exec $${node_name} find "${dst}/var/lib/cilium/bpf" -type f -exec chmod 0644 {} + ;\ 233 \ 234 docker exec $${node_name} rm -f "${dst}/cilium-dbg"; \ 235 docker cp "./cilium-dbg/cilium-dbg" $${node_name}:"${dst}"; \ 236 docker exec $${node_name} chmod +x "${dst}/cilium-dbg"; \ 237 \ 238 docker exec $${node_name} rm -f "${dst}/cilium-agent"; \ 239 docker cp "./daemon/cilium-agent" $${node_name}:"${dst}"; \ 240 docker exec $${node_name} chmod +x "${dst}/cilium-agent"; \ 241 done; \ 242 kubectl --context=kind-$${cluster_name} delete pods -n kube-system -l k8s-app=cilium --force; \ 243 done 244 245 .PHONY: kind-image-fast-operator 246 kind-image-fast-operator: kind-ready build-operator ## Build cilium operator binary and copy it to all kind nodes. 247 $(eval dst:=/cilium-binaries) 248 for cluster_name in $${KIND_CLUSTERS:-$(shell kind get clusters)}; do \ 249 for node_name in $$(kind get nodes -n "$$cluster_name"); do \ 250 docker exec $${node_name} mkdir -p "${dst}"; \ 251 \ 252 docker exec $${node_name} rm -f "${dst}/cilium-operator-generic"; \ 253 docker cp "./operator/cilium-operator-generic" $${node_name}:"${dst}"; \ 254 docker exec $${node_name} chmod +x "${dst}/cilium-operator-generic"; \ 255 done; \ 256 kubectl --context=kind-$${cluster_name} delete pods -n kube-system -l name=cilium-operator --force; \ 257 done 258 259 .PHONY: kind-image-fast-clustermesh-apiserver 260 kind-image-fast-clustermesh-apiserver: kind-ready build-clustermesh-apiserver ## Build clustermesh-apiserver binary and copy it to all kind nodes. 261 $(eval dst:=/cilium-binaries) 262 for cluster_name in $${KIND_CLUSTERS:-$(shell kind get clusters)}; do \ 263 for node_name in $$(kind get nodes -n "$$cluster_name"); do \ 264 docker exec $${node_name} mkdir -p "${dst}"; \ 265 \ 266 docker exec $${node_name} rm -f "${dst}/clustermesh-apiserver"; \ 267 docker cp "./clustermesh-apiserver/clustermesh-apiserver" $${node_name}:"${dst}"; \ 268 docker exec $${node_name} chmod +x "${dst}/clustermesh-apiserver"; \ 269 done; \ 270 kubectl --context=kind-$${cluster_name} delete pods -n kube-system -l k8s-app=clustermesh-apiserver --force; \ 271 done 272 273 .PHONY: kind-image-fast 274 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. 275 276 define KIND_VALUES_FILES 277 --helm-values=$(ROOT_DIR)/contrib/testing/kind-common.yaml \ 278 --helm-values=$(ROOT_DIR)/contrib/testing/kind-values.yaml 279 endef 280 281 ifneq ("$(wildcard $(ROOT_DIR)/contrib/testing/kind-custom.yaml)","") 282 KIND_VALUES_FILES := $(KIND_VALUES_FILES) --helm-values=$(ROOT_DIR)/contrib/testing/kind-custom.yaml 283 endif 284 285 .PHONY: kind-install-cilium 286 kind-install-cilium: check_deps kind-ready ## Install a local Cilium version into the cluster. 287 @echo " INSTALL cilium" 288 # cilium-cli doesn't support idempotent installs, so we uninstall and 289 # reinstall here. https://github.com/cilium/cilium-cli/issues/205 290 -@$(CILIUM_CLI) uninstall >/dev/null 2>&1 || true 291 292 # cilium-cli's --wait flag doesn't work, so we just force it to run 293 # in the background instead and wait for the resources to be available. 294 # https://github.com/cilium/cilium-cli/issues/1070 295 $(CILIUM_CLI) install \ 296 --chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \ 297 $(KIND_VALUES_FILES) \ 298 --version= \ 299 >/dev/null 2>&1 & 300 301 302 .PHONY: kind-egressgw-install-cilium 303 kind-egressgw-install-cilium: check_deps kind-ready ## Install a local Cilium version into the cluster. 304 @echo " INSTALL cilium" 305 # cilium-cli doesn't support idempotent installs, so we uninstall and 306 # reinstall here. https://github.com/cilium/cilium-cli/issues/205 307 -@$(CILIUM_CLI) uninstall >/dev/null 2>&1 || true 308 309 # cilium-cli's --wait flag doesn't work, so we just force it to run 310 # in the background instead and wait for the resources to be available. 311 # https://github.com/cilium/cilium-cli/issues/1070 312 $(CILIUM_CLI) install \ 313 --chart-directory=$(ROOT_DIR)/install/kubernetes/cilium \ 314 $(KIND_VALUES_FILES) \ 315 --helm-values=$(ROOT_DIR)/contrib/testing/kind-egressgw-values.yaml \ 316 --nodes-without-cilium \ 317 --version= \ 318 >/dev/null 2>&1 & 319 320 .PHONY: kind-uninstall-cilium 321 kind-uninstall-cilium: check_deps ## Uninstall Cilium from the cluster. 322 @echo " UNINSTALL cilium" 323 -$(CILIUM_CLI) uninstall 324 325 .PHONY: kind-check-cilium 326 kind-check-cilium: check_deps 327 @echo " CHECK cilium is ready..." 328 $(CILIUM_CLI) status --wait --wait-duration 1s >/dev/null 2>/dev/null 329 330 # Template for kind debug targets. Parameters are: 331 # $(1) agent target 332 define DEBUG_KIND_TEMPLATE 333 .PHONY: kind-image$(1)-debug 334 kind-image$(1)-debug: export DEBUGGER_SUFFIX=-debug 335 kind-image$(1)-debug: export NOSTRIP=1 336 kind-image$(1)-debug: export NOOPT=1 337 kind-image$(1)-debug: ## Build cilium$(1) docker image with a dlv debugger wrapper and import it into kind. 338 $(MAKE) kind-image$(1) 339 endef 340 341 # kind-image-agent-debug 342 $(eval $(call DEBUG_KIND_TEMPLATE,-agent)) 343 344 # kind-image-operator-debug 345 $(eval $(call DEBUG_KIND_TEMPLATE,-operator)) 346 347 $(eval $(call KIND_ENV,kind-debug-agent)) 348 kind-debug-agent: ## Create a local kind development environment with cilium-agent attached to a debugger. 349 $(QUIET)$(MAKE) kind-ready 2>/dev/null \ 350 || $(MAKE) kind 351 $(MAKE) kind-image-agent-debug 352 # Not debugging cilium-operator here; any image is good enough. 353 kind load docker-image $(LOCAL_OPERATOR_IMAGE) \ 354 || $(MAKE) kind-image-operator 355 $(MAKE) kind-check-cilium 2>/dev/null \ 356 || $(MAKE) kind-install-cilium 357 @echo "Attach delve to localhost on these ports to continue:" 358 @echo " - 23401: cilium-agent (kind-control-plane)" 359 @echo " - 23411: cilium-agent (kind-worker)" 360 361 $(eval $(call KIND_ENV,kind-debug)) 362 kind-debug: ## Create a local kind development environment with cilium-agent & cilium-operator attached to a debugger. 363 $(QUIET)$(MAKE) kind-ready 2>/dev/null \ 364 || $(MAKE) kind 365 $(MAKE) kind-image-agent-debug 366 $(MAKE) kind-image-operator-debug 367 $(MAKE) kind-check-cilium 2>/dev/null \ 368 || $(MAKE) kind-install-cilium 369 @echo "Attach delve to localhost on these ports to continue:" 370 @echo " - 23401: cilium-agent (kind-control-plane)" 371 @echo " - 23411: cilium-agent (kind-worker)" 372 @echo " - 23511: cilium-operator (kind-worker)"