From 023e2f09aa69376372689475db5a3c8f03ee8672 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Mon, 12 Jan 2026 16:35:10 -0600 Subject: [PATCH] feat: add helper script for standing up three test clusters Utilize kind to stand up three test clusters for the purpose of validating the deployment of UnderStack. This does nothing past standing the three clusters up, deploying ArgoCD and configuring the other clusters to be accessed by ArgoCD. Lastly it includes a cleanup operation to tear everything back down. --- scripts/e2e-test-setup.sh | 165 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100755 scripts/e2e-test-setup.sh diff --git a/scripts/e2e-test-setup.sh b/scripts/e2e-test-setup.sh new file mode 100755 index 000000000..b9a13aeb9 --- /dev/null +++ b/scripts/e2e-test-setup.sh @@ -0,0 +1,165 @@ +#!/bin/bash +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" + +# Cluster names +MGMT_CLUSTER="mgmt" +GLOBAL_CLUSTER="global" +SITE_CLUSTER="site" + +cleanup() { + echo "Cleaning up clusters..." + kind delete cluster --name "${SITE_CLUSTER}" || true + kind delete cluster --name "${GLOBAL_CLUSTER}" || true + kind delete cluster --name "${MGMT_CLUSTER}" || true +} + +create_clusters() { + echo "Creating management cluster..." + kind create cluster --name "${MGMT_CLUSTER}" + + echo "Creating global cluster..." + kind create cluster --name "${GLOBAL_CLUSTER}" + + echo "Creating site cluster..." + kind create cluster --name "${SITE_CLUSTER}" +} + +install_argocd() { + echo "Installing ArgoCD..." + kubectl --context "kind-${MGMT_CLUSTER}" create namespace argocd + kubectl --context "kind-${MGMT_CLUSTER}" apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml + + # Wait for ArgoCD to be ready + kubectl --context "kind-${MGMT_CLUSTER}" wait --for=condition=available --timeout=300s deployment/argocd-server -n argocd +} + +setup_cluster_access() { + echo "Setting up cluster access..." + + # Register global cluster + register_cluster "${GLOBAL_CLUSTER}" "global" + + # Register site cluster + register_cluster "${SITE_CLUSTER}" "site" + + # Verify clusters are registered + verify_clusters +} + +verify_clusters() { + echo "Verifying cluster registration..." + + local max_attempts=30 + local attempt=0 + + while [ $attempt -lt $max_attempts ]; do + local registered_clusters=$(kubectl --context "kind-${MGMT_CLUSTER}" get secrets -n argocd -l argocd.argoproj.io/secret-type=cluster -o name | wc -l) + + if [ "$registered_clusters" -ge 2 ]; then + echo "✓ All clusters registered successfully" + kubectl --context "kind-${MGMT_CLUSTER}" get secrets -n argocd -l argocd.argoproj.io/secret-type=cluster -o custom-columns=NAME:.metadata.name,CLUSTER:.stringData.name + return 0 + fi + + echo "Waiting for clusters to register... ($((attempt + 1))/$max_attempts)" + sleep 2 + ((attempt++)) + done + + echo "✗ Cluster registration verification failed" + return 1 +} + +register_cluster() { + local cluster_name="$1" + local cluster_role="$2" + echo "Registering ${cluster_name} cluster with ArgoCD..." + + # Get cluster config + TARGET_SERVER=$(kubectl --context "kind-${cluster_name}" config view --minify -o jsonpath='{.clusters[0].cluster.server}') + TARGET_CA=$(kubectl --context "kind-${cluster_name}" config view --raw --minify --flatten -o jsonpath='{.clusters[0].cluster.certificate-authority-data}') + + # Create service account in target cluster + kubectl --context "kind-${cluster_name}" apply -f - <