e2e: allow parameterizing kind config

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 <lserven@gmail.com>
This commit is contained in:
Lucas Servén Marín 2021-07-05 13:14:23 +02:00
parent c728870b49
commit f81d19e692
No known key found for this signature in database
GPG Key ID: 586FEAF680DA74AD
3 changed files with 24 additions and 7 deletions

View File

@ -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

View File

@ -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.

View File

@ -3,5 +3,5 @@
. lib.sh
setup_suite() {
create_cluster
create_cluster "$(build_kind_config 2)"
}