From f81d19e6921237024f15f12c208aa48a6f2127c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Serv=C3=A9n=20Mar=C3=ADn?= Date: Mon, 5 Jul 2021 13:14:23 +0200 Subject: [PATCH] e2e: allow parameterizing kind config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit allows the kind cluster configuration to be parameterized at call time. This enables the test suite to build multiple clusters with different configurations, e.g. different CIDRs, different numbers of nodes, etc. Signed-off-by: Lucas Servén Marín --- e2e/kind-config.yaml | 9 ++++----- e2e/lib.sh | 20 +++++++++++++++++++- e2e/setup.sh | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/e2e/kind-config.yaml b/e2e/kind-config.yaml index 7e52b8c..ba65473 100644 --- a/e2e/kind-config.yaml +++ b/e2e/kind-config.yaml @@ -1,11 +1,10 @@ kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: -- role: control-plane -- role: worker -- role: worker +- role: control-plane$WORKERS networking: disableDefaultCNI: true # disable kindnet - podSubnet: 10.42.0.0/16 apiServerAddress: 172.18.0.1 - apiServerPort: 6443 + apiServerPort: $API_SERVER_PORT + podSubnet: $POD_SUBNET + serviceSubnet: $SERVICE_SUBNET diff --git a/e2e/lib.sh b/e2e/lib.sh index d8baa1c..64ef9c5 100755 --- a/e2e/lib.sh +++ b/e2e/lib.sh @@ -48,6 +48,22 @@ _kind() { $KIND_BINARY --kubeconfig="$KUBECONFIG" "$@" } +# shellcheck disable=SC2120 +build_kind_config() { + local WORKER_COUNT="${1:-0}" + export API_SERVER_PORT="${2:-6443}" + export POD_SUBNET="${3:-10.42.0.0/16}" + export SERVICE_SUBNET="${4:-10.43.0.0/16}" + export WORKERS="" + local i=0 + while [ "$i" -lt "$WORKER_COUNT" ]; do + WORKERS="$(printf "%s\n- role: worker" "$WORKERS")" + ((i++)) + done + envsubst < ./kind-config.yaml + unset API_SERVER_PORT POD_SUBNET SERVICE_SUBNET WORKERS +} + create_interface() { docker run -d --name="$1" --rm --network=host --cap-add=NET_ADMIN --device=/dev/net/tun -v /var/run/wireguard:/var/run/wireguard -e WG_LOG_LEVEL=debug leonnicolas/boringtun --foreground --disable-drop-privileges true "$1" } @@ -96,9 +112,11 @@ block_until_ready() { # create_cluster launches a kind cluster and deploys Kilo, Adjacency, and a helper with curl. create_cluster() { + # shellcheck disable=SC2119 + local CONFIG="${1:-$(build_kind_config)}" _kind delete clusters $KIND_CLUSTER > /dev/null # Create the kind cluster. - _kind create cluster --name $KIND_CLUSTER --config ./kind-config.yaml + _kind create cluster --name $KIND_CLUSTER --config <(echo "$CONFIG") # Load the Kilo image into kind. docker tag "$KILO_IMAGE" squat/kilo:test # This command does not accept the --kubeconfig flag, so call the command directly. diff --git a/e2e/setup.sh b/e2e/setup.sh index 370774c..9185c4a 100644 --- a/e2e/setup.sh +++ b/e2e/setup.sh @@ -3,5 +3,5 @@ . lib.sh setup_suite() { - create_cluster + create_cluster "$(build_kind_config 2)" }