Skip to content

Commit 8a26d3a

Browse files
committed
Update Kind scripts to support KubeVirt
Signed-off-by: Johanan Liebermann <[email protected]>
1 parent 2f5d70a commit 8a26d3a

File tree

3 files changed

+146
-14
lines changed

3 files changed

+146
-14
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,10 @@ test-e2e: $(GINKGO) generate-e2e-templates ## Run the end-to-end tests
996996
kind-cluster: ## Create a new kind cluster designed for development with Tilt
997997
hack/kind-install-for-capd.sh
998998

999+
.PHONY: kind-cluster-kubevirt
1000+
kind-cluster-kubevirt: ## Create a new kind cluster with KubeVirt designed for development with Tilt
1001+
hack/kind-install-for-capk.sh
1002+
9991003
.PHONY: tilt-e2e-prerequisites
10001004
tilt-e2e-prerequisites: ## Build the corresponding kindest/node images required for e2e testing and generate the e2e templates
10011005
scripts/build-kind.sh

hack/kind-install-for-capd.sh

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ if [[ "${TRACE-0}" == "1" ]]; then
3131
fi
3232

3333
KIND_CLUSTER_NAME=${CAPI_KIND_CLUSTER_NAME:-"capi-test"}
34+
KIND_INFRA_PROVIDER=${CAPI_KIND_INFRA_PROVIDER:-""}
35+
# Required to support pulling KubeVirt container disk images from private registries as well as
36+
# avoid Docker Hub rate limiting
37+
KIND_DOCKER_CONFIG_PATH=${KIND_DOCKER_CONFIG_PATH:-"$HOME/.docker/config.json"}
3438
# See: https://kind.sigs.k8s.io/docs/user/configuration/#ip-family
3539
KIND_NETWORK_IPFAMILY=${KIND_NETWORK_IPFAMILY:-"dual"}
3640

@@ -56,21 +60,40 @@ fi
5660
# https://github.com/kubernetes-sigs/kind/issues/2875
5761
# https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration
5862
# See: https://github.com/containerd/containerd/blob/main/docs/hosts.md
59-
cat <<EOF | kind create cluster --name="$KIND_CLUSTER_NAME" --config=-
60-
kind: Cluster
61-
apiVersion: kind.x-k8s.io/v1alpha4
62-
networking:
63-
ipFamily: ${KIND_NETWORK_IPFAMILY}
64-
nodes:
65-
- role: control-plane
66-
extraMounts:
67-
- hostPath: /var/run/docker.sock
68-
containerPath: /var/run/docker.sock
69-
containerdConfigPatches:
70-
- |-
71-
[plugins."io.containerd.grpc.v1.cri".registry]
72-
config_path = "/etc/containerd/certs.d"
63+
64+
if [[ "$KIND_INFRA_PROVIDER" == "kubevirt" ]]; then
65+
cat <<EOF | kind create cluster --name="$KIND_CLUSTER_NAME" --config=-
66+
kind: Cluster
67+
apiVersion: kind.x-k8s.io/v1alpha4
68+
networking:
69+
disableDefaultCNI: true
70+
nodes:
71+
- role: control-plane
72+
extraMounts:
73+
- containerPath: /var/lib/kubelet/config.json
74+
hostPath: ${KIND_DOCKER_CONFIG_PATH}
75+
containerdConfigPatches:
76+
- |-
77+
[plugins."io.containerd.grpc.v1.cri".registry]
78+
config_path = "/etc/containerd/certs.d"
79+
EOF
80+
else
81+
cat <<EOF | kind create cluster --name="$KIND_CLUSTER_NAME" --config=-
82+
kind: Cluster
83+
apiVersion: kind.x-k8s.io/v1alpha4
84+
networking:
85+
ipFamily: ${KIND_NETWORK_IPFAMILY}
86+
nodes:
87+
- role: control-plane
88+
extraMounts:
89+
- hostPath: /var/run/docker.sock
90+
containerPath: /var/run/docker.sock
91+
containerdConfigPatches:
92+
- |-
93+
[plugins."io.containerd.grpc.v1.cri".registry]
94+
config_path = "/etc/containerd/certs.d"
7395
EOF
96+
fi
7497

7598
# 4. Add the registry config to the nodes
7699
#

hack/kind-install-for-capk.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
# This script installs a local Kind cluster with a local container registry and the correct files
19+
# mounted for using CAPK to test Cluster API.
20+
# The default Kind CNI is disabled because it doesn't work CAPK. Instead, Calico is used.
21+
# MetalLB is used as a local layer 2 load balancer to support exposing the API servers of workload
22+
# clusters on the local machine that's running this script.
23+
24+
set -o errexit
25+
set -o nounset
26+
set -o pipefail
27+
28+
CALICO_VERSION=${CAPI_CALICO_VERSION:-"v3.29.1"}
29+
METALLB_VERSION=${CAPI_METALLB_VERSION:-""}
30+
# Set manually for non-Docker runtimes - example: "172.20"
31+
METALLB_IP_PREFIX=${CAPI_IP_PREFIX:-""}
32+
KUBEVIRT_VERSION=${CAPI_KUBEVIRT_VERSION:-""}
33+
34+
# Deploy Kind cluster
35+
CAPI_KIND_INFRA_PROVIDER=kubevirt "$(dirname "${BASH_SOURCE[0]}")/kind-install-for-capd.sh"
36+
37+
# Deploy Calico
38+
kubectl apply -f \
39+
"https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/calico.yaml"
40+
41+
# Deploy MetalLB
42+
if [[ -z "$METALLB_VERSION" ]]; then
43+
METALLB_VERSION=$(curl "https://api.github.com/repos/metallb/metallb/releases/latest" \
44+
| jq -r ".tag_name")
45+
fi
46+
47+
kubectl apply -f \
48+
"https://raw.githubusercontent.com/metallb/metallb/${METALLB_VERSION}/config/manifests/metallb-native.yaml"
49+
50+
echo "Waiting for controller pod to be created..."
51+
while [[ -z $(kubectl -n metallb-system get pods \
52+
-l app=metallb,component=controller -o jsonpath="{.items[0].metadata.name}" 2>/dev/null) ]]; do
53+
sleep 2
54+
done
55+
echo "Pod created!"
56+
57+
echo "Waiting for speaker pod to be created..."
58+
while [[ -z $(kubectl -n metallb-system get pods \
59+
-l app=metallb,component=speaker -o jsonpath="{.items[0].metadata.name}" 2>/dev/null) ]]; do
60+
sleep 2
61+
done
62+
echo "Pod created!"
63+
64+
echo "Waiting for pods to become ready..."
65+
kubectl wait pods -n metallb-system \
66+
-l app=metallb,component=controller --for=condition=Ready --timeout=10m
67+
kubectl wait pods -n metallb-system \
68+
-l app=metallb,component=speaker --for=condition=Ready --timeout=2m
69+
echo "Pods ready!"
70+
71+
if [[ -z "$METALLB_IP_PREFIX" ]]; then
72+
SUBNET=$(docker network inspect \
73+
-f '{{range .IPAM.Config}}{{if .Gateway}}{{.Subnet}}{{end}}{{end}}' kind)
74+
METALLB_IP_PREFIX=$(echo "$SUBNET" | sed -E 's|^([0-9]+\.[0-9]+)\..*$|\1|g')
75+
fi
76+
77+
cat <<EOF | kubectl apply -f -
78+
apiVersion: metallb.io/v1beta1
79+
kind: IPAddressPool
80+
metadata:
81+
name: capi-ip-pool
82+
namespace: metallb-system
83+
spec:
84+
addresses:
85+
- ${METALLB_IP_PREFIX}.255.200-${METALLB_IP_PREFIX}.255.250
86+
---
87+
apiVersion: metallb.io/v1beta1
88+
kind: L2Advertisement
89+
metadata:
90+
name: empty
91+
namespace: metallb-system
92+
EOF
93+
94+
# Deploy KubeVirt
95+
if [[ -z "$KUBEVIRT_VERSION" ]]; then
96+
KUBEVIRT_VERSION=$(curl "https://api.github.com/repos/kubevirt/kubevirt/releases/latest" \
97+
| jq -r ".tag_name")
98+
fi
99+
kubectl apply -f \
100+
"https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml"
101+
kubectl apply -f \
102+
"https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml"
103+
echo "Waiting for KubeVirt to become ready..."
104+
kubectl wait -n kubevirt kv kubevirt --for=condition=Available --timeout=10m
105+
echo "KubeVirt ready!"

0 commit comments

Comments
 (0)