Procházet zdrojové kódy

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>
Lucas Servén Marín před 4 roky
rodič
revize
f81d19e692
3 změnil soubory, kde provedl 24 přidání a 7 odebrání
  1. 4 5
      e2e/kind-config.yaml
  2. 19 1
      e2e/lib.sh
  3. 1 1
      e2e/setup.sh

+ 4 - 5
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

+ 19 - 1
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.

+ 1 - 1
e2e/setup.sh

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