Skip to content

Commit 7a9aba6

Browse files
committed
tests, Makefile, scripts: Added k3s tests and moved k3d to it's own test folder
Signed-off-by: Jiaxiao (mossaka) Zhou <duibao55328@gmail.com>
1 parent cd4975e commit 7a9aba6

File tree

8 files changed

+360
-7
lines changed

8 files changed

+360
-7
lines changed

Makefile

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ integration-spin-registry-push-tests:
6767
tests/collect-debug-logs:
6868
./scripts/collect-debug-logs.sh 2>&1
6969

70+
# test/k3s
71+
72+
.PHONY: install-k3s, build-and-push-images
73+
install-k3s:
74+
./tests/k3s/install-k3s.sh
75+
build-and-push-images:
76+
./tests/k3s/build-and-push-images.sh
77+
78+
.PHONY: test/k3s
79+
test/k3s: install-k3s build-and-push-images
80+
kubectl apply -f tests/workloads-common
81+
kubectl apply -f tests/k3s/workloads-pushed-using-spin-registry-push
82+
make pod-terminates-test
83+
SPIN_TEST_PORT=80 cargo test -p containerd-shim-spin-tests -- --nocapture
84+
make teardown-workloads-k3s
85+
7086
# fmt
7187

7288
.PHONY: fmt fix
@@ -113,7 +129,7 @@ run-%: install load
113129

114130
# deploy
115131

116-
./PHONY: up move-bins deploy-workloads-pushed-using-docker-build-push deploy-workloads-pushed-using-spin-registry-push pod-terminates-test prepare-cluster-and-images
132+
.PHONY: up move-bins deploy-workloads-pushed-using-docker-build-push deploy-workloads-pushed-using-spin-registry-push pod-terminates-test prepare-cluster-and-images
117133

118134
up:
119135
./scripts/up.sh
@@ -134,9 +150,12 @@ prepare-cluster-and-images: check-bins move-bins up free-disk pod-status-check
134150

135151
# clean
136152

137-
./PHONY: teardown-workloads tests/clean
138-
teardown-workloads:
139-
./scripts/teardown-workloads.sh
153+
.PHONY: teardown-workloads-k3d teardown-workloads-k3s tests/clean
154+
teardown-workloads-k3d:
155+
./scripts/teardown-workloads.sh "k3d"
156+
teardown-workloads-k3s:
157+
./scripts/teardown-workloads.sh "k3s"
158+
docker container stop test-registry && docker container rm test-registry
140159

141160
tests/clean:
142161
./scripts/down.sh

scripts/teardown-workloads.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22

33
set -euo pipefail
44

5-
kubectl delete -f tests/workloads-common --wait --timeout 60s --ignore-not-found=true
6-
kubectl delete -f tests/workloads-pushed-using-docker-build-push --wait --timeout 60s --ignore-not-found=true
7-
kubectl delete -f tests/workloads-pushed-using-spin-registry-push --wait --timeout 60s --ignore-not-found=true
5+
case "$1" in
6+
k3d)
7+
TESTS_PATH="tests/k3d"
8+
;;
9+
k3s)
10+
TESTS_PATH="tests/k3s"
11+
;;
12+
*)
13+
echo "Invalid argument. Use 'k3d' or 'k3s'."
14+
exit 1
15+
;;
16+
esac
17+
18+
kubectl delete -f "tests/workloads-common" --wait --timeout 60s --ignore-not-found=true
19+
kubectl delete -f "tests/workloads-pushed-using-docker-build-push" --wait --timeout 60s --ignore-not-found=true
20+
kubectl delete -f "$TESTS_PATH/workloads-pushed-using-spin-registry-push" --wait --timeout 60s --ignore-not-found=true
821
kubectl wait pod --for=delete -l app=wasm-spin -l app=spin-keyvalue -l app=spin-outbound-redis -l app=spin-multi-trigger-app --timeout 60s
File renamed without changes.

tests/workloads-pushed-using-spin-registry-push/README.md renamed to tests/k3d/workloads-pushed-using-spin-registry-push/README.md

File renamed without changes.

tests/workloads-pushed-using-spin-registry-push/workloads.yaml renamed to tests/k3d/workloads-pushed-using-spin-registry-push/workloads.yaml

File renamed without changes.

tests/k3s/install-k3s.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Install k3s
6+
# Since the latest k3s already bakes in the Spin shim, we don't need to reconfigure it.
7+
# We will just need to make sure that containerd-shim-spin-v2 binary is in PATH
8+
# and that the k3s service is running.
9+
10+
curl -sfL https://get.k3s.io | sh -
11+
sudo systemctl start k3s
12+
sudo k3s kubectl get nodes
13+
14+
sudo chmod 644 /etc/rancher/k3s/k3s.yaml
15+
sudo cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/k3s.yaml
16+
export KUBECONFIG=$HOME/.kube/k3s.yaml
17+
kubectl get nodes
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This folder has yaml file to apply workloads which are built using `spin build` and pushed to a registry, managed with k3d in CI, using `spin registry push` command.
Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: wasm-spin
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: wasm-spin
10+
template:
11+
metadata:
12+
labels:
13+
app: wasm-spin
14+
spec:
15+
runtimeClassName: wasmtime-spin
16+
containers:
17+
- name: testwasm
18+
image: localhost:5000/spin-registry-push/spin-hello-world:latest
19+
imagePullPolicy: IfNotPresent
20+
command: ["/"]
21+
resources: # limit the resources to 128Mi of memory and 100m of CPU
22+
limits:
23+
cpu: 100m
24+
memory: 128Mi
25+
requests:
26+
cpu: 100m
27+
memory: 128Mi
28+
---
29+
apiVersion: v1
30+
kind: Service
31+
metadata:
32+
name: wasm-spin
33+
spec:
34+
ports:
35+
- protocol: TCP
36+
port: 80
37+
targetPort: 80
38+
selector:
39+
app: wasm-spin
40+
---
41+
apiVersion: apps/v1
42+
kind: Deployment
43+
metadata:
44+
name: spin-keyvalue
45+
spec:
46+
replicas: 1
47+
selector:
48+
matchLabels:
49+
app: spin-keyvalue
50+
template:
51+
metadata:
52+
labels:
53+
app: spin-keyvalue
54+
spec:
55+
runtimeClassName: wasmtime-spin
56+
containers:
57+
- name: keyvalue
58+
image: localhost:5000/spin-registry-push/spin-keyvalue:latest
59+
command: ["/"]
60+
imagePullPolicy: IfNotPresent
61+
volumeMounts:
62+
- name: config-volume
63+
mountPath: /runtime-config.toml
64+
subPath: runtime-config.toml
65+
readOnly: true
66+
volumes:
67+
- name: config-volume
68+
configMap:
69+
name: spin-runtime-config
70+
---
71+
apiVersion: v1
72+
kind: Service
73+
metadata:
74+
name: spin-keyvalue
75+
spec:
76+
type: LoadBalancer
77+
ports:
78+
- protocol: TCP
79+
port: 80
80+
targetPort: 80
81+
selector:
82+
app: spin-keyvalue
83+
---
84+
apiVersion: apps/v1
85+
kind: Deployment
86+
metadata:
87+
name: spin-outbound-redis
88+
spec:
89+
replicas: 1
90+
selector:
91+
matchLabels:
92+
app: spin-outbound-redis
93+
template:
94+
metadata:
95+
labels:
96+
app: spin-outbound-redis
97+
spec:
98+
runtimeClassName: wasmtime-spin
99+
containers:
100+
- name: outbound-redis
101+
image: localhost:5000/spin-registry-push/spin-outbound-redis:latest
102+
command: ["/"]
103+
imagePullPolicy: IfNotPresent
104+
env:
105+
- name: SPIN_VARIABLE_REDIS_ADDRESS
106+
value: redis://redis-service.default.svc.cluster.local:6379
107+
- name: SPIN_VARIABLE_REDIS_CHANNEL
108+
value: test
109+
---
110+
apiVersion: v1
111+
kind: Service
112+
metadata:
113+
name: spin-outbound-redis
114+
spec:
115+
type: LoadBalancer
116+
ports:
117+
- protocol: TCP
118+
port: 80
119+
targetPort: 80
120+
selector:
121+
app: spin-outbound-redis
122+
---
123+
# Middleware
124+
# Strip prefix /spin
125+
apiVersion: traefik.containo.us/v1alpha1
126+
kind: Middleware
127+
metadata:
128+
name: strip-prefix
129+
spec:
130+
stripPrefix:
131+
forceSlash: false
132+
prefixes:
133+
- /spin
134+
- /outboundredis
135+
- /keyvalue
136+
- /static-assets
137+
---
138+
apiVersion: networking.k8s.io/v1
139+
kind: Ingress
140+
metadata:
141+
name: wasm-ingress
142+
annotations:
143+
ingress.kubernetes.io/ssl-redirect: "false"
144+
traefik.ingress.kubernetes.io/router.middlewares: default-strip-prefix@kubernetescrd
145+
spec:
146+
ingressClassName: traefik
147+
rules:
148+
- http:
149+
paths:
150+
- path: /spin
151+
pathType: Prefix
152+
backend:
153+
service:
154+
name: wasm-spin
155+
port:
156+
number: 80
157+
- path: /keyvalue
158+
pathType: Prefix
159+
backend:
160+
service:
161+
name: spin-keyvalue
162+
port:
163+
number: 80
164+
- path: /outboundredis
165+
pathType: Prefix
166+
backend:
167+
service:
168+
name: spin-outbound-redis
169+
port:
170+
number: 80
171+
- path: /multi-trigger-app
172+
pathType: Prefix
173+
backend:
174+
service:
175+
name: spin-multi-trigger-app
176+
port:
177+
number: 80
178+
- path: /static-assets
179+
pathType: Prefix
180+
backend:
181+
service:
182+
name: spin-static-assets
183+
port:
184+
number: 80
185+
---
186+
apiVersion: apps/v1
187+
kind: Deployment
188+
metadata:
189+
name: spin-multi-trigger-app
190+
spec:
191+
replicas: 1
192+
selector:
193+
matchLabels:
194+
app: spin-multi-trigger-app
195+
template:
196+
metadata:
197+
labels:
198+
app: spin-multi-trigger-app
199+
spec:
200+
runtimeClassName: wasmtime-spin
201+
containers:
202+
- name: spin-multi-trigger-app
203+
image: localhost:5000/spin-registry-push/spin-multi-trigger-app:latest
204+
imagePullPolicy: IfNotPresent
205+
command: ["/"]
206+
ports:
207+
- containerPort: 80
208+
env:
209+
- name: SPIN_VARIABLE_REDIS_ADDRESS
210+
value: redis://redis-service.default.svc.cluster.local:6379
211+
- name: SPIN_VARIABLE_REDIS_CHANNEL
212+
value: testchannel
213+
---
214+
apiVersion: v1
215+
kind: Service
216+
metadata:
217+
name: spin-multi-trigger-app
218+
spec:
219+
type: LoadBalancer
220+
ports:
221+
- protocol: TCP
222+
port: 80
223+
targetPort: 80
224+
selector:
225+
app: spin-multi-trigger-app
226+
---
227+
apiVersion: apps/v1
228+
kind: Deployment
229+
metadata:
230+
name: spin-static-assets
231+
spec:
232+
replicas: 1
233+
selector:
234+
matchLabels:
235+
app: spin-static-assets
236+
template:
237+
metadata:
238+
labels:
239+
app: spin-static-assets
240+
spec:
241+
runtimeClassName: wasmtime-spin
242+
containers:
243+
- name: spin-static-assets
244+
image: localhost:5000/spin-registry-push/spin-static-assets:latest
245+
imagePullPolicy: IfNotPresent
246+
command: ["/"]
247+
ports:
248+
- containerPort: 80
249+
---
250+
apiVersion: v1
251+
kind: Service
252+
metadata:
253+
name: spin-static-assets
254+
spec:
255+
type: LoadBalancer
256+
ports:
257+
- protocol: TCP
258+
port: 80
259+
targetPort: 80
260+
selector:
261+
app: spin-static-assets
262+
---
263+
apiVersion: apps/v1
264+
kind: Deployment
265+
metadata:
266+
name: spin-mqtt-message-logger
267+
spec:
268+
replicas: 1
269+
selector:
270+
matchLabels:
271+
app: spin-mqtt-message-logger
272+
template:
273+
metadata:
274+
labels:
275+
app: spin-mqtt-message-logger
276+
spec:
277+
runtimeClassName: wasmtime-spin
278+
containers:
279+
- name: spin-mqtt-message-logger
280+
image: localhost:5000/spin-registry-push/spin-mqtt-message-logger:latest
281+
imagePullPolicy: IfNotPresent
282+
command: ["/"]
283+
ports:
284+
- containerPort: 80
285+
env:
286+
- name: SPIN_VARIABLE_MQTT_TOPIC
287+
value: containerd-shim-spin/mqtt-test-17h24d
288+
# The MQTT trigger cannot do DNS resolution, so we need to use the IP address of the MQTT broker
289+
- name: SPIN_VARIABLE_MQTT_BROKER_URI
290+
value: "mqtt://test.mosquitto.org"
291+
---
292+
apiVersion: v1
293+
kind: Service
294+
metadata:
295+
name: spin-mqtt-message-logger
296+
spec:
297+
type: LoadBalancer
298+
ports:
299+
- protocol: TCP
300+
port: 80
301+
targetPort: 80
302+
selector:
303+
app: spin-mqtt-message-logger

0 commit comments

Comments
 (0)