Skip to content

Commit

Permalink
contrib/kind: Add secondary iface to KIND network
Browse files Browse the repository at this point in the history
Add secondary iface to KIND network, so that we can test the NodePort
via secondary iface.

Signed-off-by: Yusuke Suzuki <yusuke-suzuki@cybozu.co.jp>
  • Loading branch information
ysksuzuki committed Jun 19, 2023
1 parent bfa8697 commit 9a4b4b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions contrib/scripts/kind-down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ fi

default_cluster_name="kind"
default_network="kind-cilium"
default_secondary_network="${default_network}-secondary"

for cluster in "${@:-${default_cluster_name}}"; do
kind delete cluster --name "$cluster"
done

docker network rm ${default_network}
docker network rm ${default_secondary_network}
20 changes: 18 additions & 2 deletions contrib/scripts/kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ default_service_subnet=""
default_agent_port_prefix="234"
default_operator_port_prefix="235"
default_network="kind-cilium"
default_secondary_network="${default_network}-secondary"

PROG=${0}

Expand All @@ -40,7 +41,9 @@ agent_port_prefix="${AGENTPORTPREFIX:=${default_agent_port_prefix}}"
operator_port_prefix="${OPERATORPORTPREFIX:=${default_operator_port_prefix}}"

bridge_dev="br-${default_network}"
bridge_dev_secondary="${bridge_dev}2"
v6_prefix="fc00:c111::/64"
v6_prefix_secondary="fc00:c112::/64"
CILIUM_ROOT="$(git rev-parse --show-toplevel)"

usage() {
Expand Down Expand Up @@ -125,6 +128,14 @@ if ! docker network inspect "${default_network}" >/dev/null 2>&1; then
"${default_network}"
fi

if ! docker network inspect "${default_secondary_network}" >/dev/null 2>&1; then
docker network create -d=bridge \
-o "com.docker.network.bridge.enable_ip_masquerade=false" \
-o "com.docker.network.bridge.name=${bridge_dev_secondary}" \
--ipv6 --subnet "${v6_prefix_secondary}" \
"${default_secondary_network}"
fi

export KIND_EXPERIMENTAL_DOCKER_NETWORK="${default_network}"

# create a cluster with the local registry enabled in containerd
Expand All @@ -150,15 +161,20 @@ kubeadmConfigPatches:
"v": "3"
EOF

nodes=$(docker ps -a --filter label=io.x-k8s.kind.cluster=${cluster_name:-kind} --format {{.Names}})
for node in $nodes; do
docker network connect ${default_secondary_network} $node
done

if [ "${xdp}" = true ]; then
if ! [ -f "${CILIUM_ROOT}/test/l4lb/bpf_xdp_veth_host.o" ]; then
pushd "${CILIUM_ROOT}/test/l4lb/" > /dev/null
clang -O2 -Wall -target bpf -c bpf_xdp_veth_host.c -o bpf_xdp_veth_host.o
popd > /dev/null
fi

for ifc in /sys/class/net/"${bridge_dev}"/brif/*; do
ifc="${ifc#"/sys/class/net/${bridge_dev}/brif/"}"
for ifc in /sys/class/net/"${bridge_dev}"*/brif/*; do
ifc=$(echo $ifc | sed "s:/sys/class/net/${bridge_dev}.*/brif/::")

# Attach a dummy XDP prog to the host side of the veth so that XDP_TX in the
# pod side works.
Expand Down

0 comments on commit 9a4b4b2

Please sign in to comment.