Skip to content

Commit d00f040

Browse files
committed
node-installer: add integration test
- introduce a script to integration test the node-installer image - add a KWasm node installer job file for the integration test - modified the README to include instructions for building the image locally and running the integration tests Signed-off-by: Jiaxiao (mossaka) Zhou <[email protected]>
1 parent 7539493 commit d00f040

File tree

5 files changed

+156
-2
lines changed

5 files changed

+156
-2
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
name: spin-test
4+
nodes:
5+
- role: control-plane
6+
extraPortMappings:
7+
- containerPort: 80
8+
hostPort: 8080
9+
protocol: TCP

node-installer/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ ARCH ?= x86_64
55
TARGET ?= $(ARCH)-unknown-linux-musl
66

77
compile-musl:
8-
make build-spin-cross-$(TARGET) -C ../
8+
make build-cross-$(TARGET) -C ../
99

1010
move-musl-to-tmp: compile-musl
1111
mkdir -p ./.tmp
12-
cp ../../containerd-shim-spin/target/$(TARGET)/release/containerd-shim-spin-$(SPIN_VERSION) ./.tmp/
12+
cp ../target/$(TARGET)/release/containerd-shim-spin-$(SPIN_VERSION) ./.tmp/$(PLATFORM)/
1313

1414
build-multi-installer-image: move-musl-to-tmp
1515
docker buildx build -t $(IMAGE_NAME) --platform linux/amd64,linux/arm64 .
1616

1717
build-dev-installer-image: move-musl-to-tmp
1818
docker buildx build -t $(IMAGE_NAME) --load --platform $(PLATFORM) .
19+
20+
test:
21+
./integration-test.sh

node-installer/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,20 @@ which also bundles other shims.
77

88
The intention is for the [spinkube/runtime-class-manager](https://github.com/spinkube/runtime-class-manager)
99
project to handle this concern in the future.
10+
11+
## Integration Test
12+
13+
The `integration-test.sh` script is used to test the node-installer image.
14+
It creates a kind cluster, applies the KWasm node installer job, and then tests
15+
the workload.
16+
17+
```bash
18+
./integration-test.sh
19+
```
20+
21+
## Build the Image Locally
22+
23+
```bash
24+
make build-dev-installer-image
25+
```
26+

node-installer/integration-test.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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

node-installer/kwasm-job.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
labels:
5+
job-name: spin-test-control-plane-provision-kwasm
6+
name: spin-test-control-plane-provision-kwasm-dev
7+
namespace: kwasm
8+
spec:
9+
containers:
10+
- env:
11+
- name: NODE_ROOT
12+
value: /mnt/node-root
13+
image: ghcr.io/spinkube/containerd-shim-spin/node-installer:dev
14+
imagePullPolicy: IfNotPresent
15+
name: kwasm-provision
16+
securityContext:
17+
privileged: true
18+
volumeMounts:
19+
- mountPath: /mnt/node-root
20+
name: root-mount
21+
hostPID: true
22+
nodeName: spin-test-control-plane
23+
restartPolicy: Never
24+
volumes:
25+
- hostPath:
26+
path: /
27+
name: root-mount

0 commit comments

Comments
 (0)