1+ #! /bin/bash
2+ set -euo pipefail
3+
4+ echo " === Step 1: Create a kind cluster ==="
5+ if kind get clusters | grep -q " spin-test" ; then
6+ echo " Deleting existing cluster..."
7+ kind delete cluster --name spin-test
8+ fi
9+
10+ echo " Creating kind cluster..."
11+ kind create cluster --config .kind/kind-config.yaml
12+ kubectl --context=kind-spin-test wait --for=condition=Ready nodes --all --timeout=90s
13+
14+ echo " === Step 2: Create namespace and deploy RuntimeClass ==="
15+ kubectl --context=kind-spin-test create namespace kwasm || true
16+ kubectl --context=kind-spin-test apply -f ../deployments/workloads/runtime.yaml
17+
18+ echo " === Step 3: Build and deploy the KWasm node installer ==="
19+ if ! docker image inspect ghcr.io/spinkube/containerd-shim-spin/node-installer:v0.18.0 > /dev/null 2>&1 ; then
20+ echo " Building node installer image..."
21+ PLATFORM=$( uname -m)
22+ if [ " $PLATFORM " = " x86_64" ]; then
23+ PLATFORM=" linux/amd64"
24+ ARCH=" x86_64"
25+ elif [ " $PLATFORM " = " aarch64" ] || [ " $PLATFORM " = " arm64" ]; then
26+ PLATFORM=" linux/arm64"
27+ ARCH=" aarch64"
28+ else
29+ echo " Unsupported platform: $PLATFORM "
30+ exit 1
31+ fi
32+
33+ PLATFORM=$PLATFORM ARCH=$ARCH IMAGE_NAME=ghcr.io/spinkube/containerd-shim-spin/node-installer:dev make build-dev-installer-image
34+ fi
35+
36+ echo " Loading node installer image into kind..."
37+ kind load docker-image ghcr.io/spinkube/containerd-shim-spin/node-installer:dev --name spin-test
38+
39+ echo " Applying KWasm node installer job..."
40+ kubectl --context=kind-spin-test apply -f ./kwasm-job.yml
41+
42+ echo " Waiting for node installer job to complete..."
43+ kubectl --context=kind-spin-test wait -n kwasm --for=condition=Ready pod --selector=job-name=spin-test-control-plane-provision-kwasm --timeout=90s || true
44+ kubectl --context=kind-spin-test wait -n kwasm --for=jsonpath=' {.status.phase}' =Succeeded pod --selector=job-name=spin-test-control-plane-provision-kwasm --timeout=60s
45+
46+ if ! kubectl --context=kind-spin-test get pods -n kwasm | grep -q " spin-test-control-plane-provision-kwasm.*Completed" ; then
47+ echo " Node installer job failed!"
48+ kubectl --context=kind-spin-test logs -n kwasm $( kubectl --context=kind-spin-test get pods -n kwasm -o name | grep spin-test-control-plane-provision-kwasm)
49+ exit 1
50+ fi
51+
52+ echo " === Step 4: Apply the workload ==="
53+ kubectl --context=kind-spin-test apply -f ../deployments/workloads/workload.yaml
54+
55+ echo " Waiting for deployment to be ready..."
56+ kubectl --context=kind-spin-test wait --for=condition=Available deployment/wasm-spin --timeout=120s
57+
58+ echo " Checking pod status..."
59+ kubectl --context=kind-spin-test get pods
60+
61+ echo " === Step 5: Test the workload ==="
62+ echo " Waiting for service to be ready..."
63+ sleep 10
64+
65+ echo " Testing workload with curl..."
66+ kubectl --context=kind-spin-test port-forward svc/wasm-spin 8888:80 &
67+ FORWARD_PID=$!
68+ sleep 5
69+
70+ MAX_RETRIES=3
71+ RETRY_COUNT=0
72+ SUCCESS=false
73+
74+ while [ $RETRY_COUNT -lt $MAX_RETRIES ] && [ " $SUCCESS " = false ]; do
75+ if curl -s http://localhost:8888/hello | grep -q " Hello world from Spin!" ; then
76+ SUCCESS=true
77+ echo " Workload test successful!"
78+ else
79+ echo " Retrying in 3 seconds..."
80+ sleep 3
81+ RETRY_COUNT=$(( RETRY_COUNT+ 1 ))
82+ fi
83+ done
84+
85+ kill $FORWARD_PID
86+
87+ if [ " $SUCCESS " = true ]; then
88+ echo " === Integration Test Passed! ==="
89+ kind delete cluster --name spin-test
90+ exit 0
91+ else
92+ echo " === Integration Test Failed! ==="
93+ echo " Could not get a successful response from the workload."
94+ kubectl --context=kind-spin-test describe pods
95+ kubectl --context=kind-spin-test logs $( kubectl --context=kind-spin-test get pods -o name | grep wasm-spin)
96+ kind delete cluster --name spin-test
97+ exit 1
98+ fi
0 commit comments