Skip to content

Commit f7e1fb7

Browse files
chore: adding pvc mount test (#36)
improved tests so we can validate openebs is working after the deployment. we now create a deployment mounting a pvc and check it rolls out.
1 parent 1cb0a2c commit f7e1fb7

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

e2e/embed_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ func TestEmbedAndInstall(t *testing.T) {
2727
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
2828
t.Fatalf("fail to install embedded ssh in node 0: %v", err)
2929
}
30+
t.Log("creating deployment mounting pvc")
31+
line = []string{"deploy-with-pvc.sh"}
32+
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
33+
t.Fatalf("fail to create deployment with pvc: %v", err)
34+
}
3035
}
3136

3237
func TestInstallSingleNodeAndUpgradeToEmbed(t *testing.T) {
@@ -55,4 +60,9 @@ func TestInstallSingleNodeAndUpgradeToEmbed(t *testing.T) {
5560
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
5661
t.Fatalf("fail to install embed helmvm on node 0: %v", err)
5762
}
63+
t.Log("creating deployment mounting pvc")
64+
line = []string{"deploy-with-pvc.sh"}
65+
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
66+
t.Fatalf("fail to create deployment with pvc: %v", err)
67+
}
5868
}

e2e/install_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ func TestSingleNodeInstallation(t *testing.T) {
6969
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
7070
t.Fatalf("fail to install helmvm on node %s: %v", tc.Nodes[0], err)
7171
}
72+
t.Log("creating deployment mounting pvc")
73+
line = []string{"deploy-with-pvc.sh"}
74+
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
75+
t.Fatalf("fail to create deployment with pvc: %v", err)
76+
}
7277
}
7378

7479
func TestMultiNodeInstallation(t *testing.T) {
@@ -122,6 +127,11 @@ func TestSingleNodeInstallationRockyLinux8(t *testing.T) {
122127
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
123128
t.Fatalf("fail to install helmvm on node %s: %v", tc.Nodes[0], err)
124129
}
130+
t.Log("creating deployment mounting pvc")
131+
line = []string{"deploy-with-pvc.sh"}
132+
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
133+
t.Fatalf("fail to create deployment with pvc: %v", err)
134+
}
125135
}
126136

127137
func TestSingleNodeInstallationDebian12(t *testing.T) {
@@ -145,6 +155,11 @@ func TestSingleNodeInstallationDebian12(t *testing.T) {
145155
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
146156
t.Fatalf("fail to install helmvm on node %s: %v", tc.Nodes[0], err)
147157
}
158+
t.Log("creating deployment mounting pvc")
159+
line = []string{"deploy-with-pvc.sh"}
160+
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
161+
t.Fatalf("fail to create deployment with pvc: %v", err)
162+
}
148163
}
149164

150165
func TestSingleNodeInstallationCentos8Stream(t *testing.T) {
@@ -172,4 +187,9 @@ func TestSingleNodeInstallationCentos8Stream(t *testing.T) {
172187
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
173188
t.Fatalf("fail to install helmvm on node %s: %v", tc.Nodes[0], err)
174189
}
190+
t.Log("creating deployment mounting pvc")
191+
line = []string{"deploy-with-pvc.sh"}
192+
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
193+
t.Fatalf("fail to create deployment with pvc: %v", err)
194+
}
175195
}

e2e/scripts/deploy-with-pvc.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
deploy="
5+
apiVersion: apps/v1
6+
kind: Deployment
7+
metadata:
8+
name: nginx-deployment
9+
labels:
10+
app: nginx
11+
spec:
12+
replicas: 1
13+
selector:
14+
matchLabels:
15+
app: nginx
16+
template:
17+
metadata:
18+
labels:
19+
app: nginx
20+
spec:
21+
volumes:
22+
- name: nginx-persistent-storage
23+
persistentVolumeClaim:
24+
claimName: nginx-pvc
25+
containers:
26+
- name: nginx
27+
image: nginx:1.14.2
28+
ports:
29+
- containerPort: 80
30+
volumeMounts:
31+
- name: nginx-persistent-storage
32+
mountPath: /usr/share/nginx/html
33+
"
34+
35+
pvc="
36+
apiVersion: v1
37+
kind: PersistentVolumeClaim
38+
metadata:
39+
name: nginx-pvc
40+
spec:
41+
accessModes:
42+
- ReadWriteOnce
43+
resources:
44+
requests:
45+
storage: 1Gi
46+
"
47+
48+
create_deployment() {
49+
echo "$deploy" > deploy.yaml
50+
echo "$pvc" > pvc.yaml
51+
if ! kubectl apply -f pvc.yaml 2>&1; then
52+
echo "Failed to create PVC"
53+
return 1
54+
fi
55+
if ! kubectl apply -f deploy.yaml 2>&1; then
56+
echo "Failed to create PVC"
57+
return 1
58+
fi
59+
}
60+
61+
wait_for_nginx_pods() {
62+
running=$(kubectl get pods | grep nginx | grep -c Running || true)
63+
counter=0
64+
while [ "$running" -lt "1" ]; do
65+
if [ "$counter" -gt 30 ]; then
66+
kubectl describe pvc nginx-pvc 2>&1 || true
67+
kubectl describe deploy nginx-deployment 2>&1 || true
68+
return 1
69+
fi
70+
sleep 10
71+
counter=$((counter+1))
72+
echo "Waiting for nginx pods to run"
73+
running=$(kubectl get pods | grep nginx | grep -c Running || true)
74+
kubectl get pods || true
75+
done
76+
return 0
77+
}
78+
79+
main() {
80+
echo "Creating deployment with mounted PVC"
81+
if ! create_deployment; then
82+
echo "Failed to create deployment"
83+
return 1
84+
fi
85+
echo "Waiting for deployment to rollout"
86+
if ! wait_for_nginx_pods; then
87+
kubectl get pods -A 2>&1 || true
88+
echo "Failed to wait for nginx pods"
89+
exit 1
90+
fi
91+
echo "Deployment created successfully"
92+
}
93+
94+
export KUBECONFIG=/root/.helmvm/etc/kubeconfig
95+
export PATH=$PATH:/root/.helmvm/bin
96+
main

0 commit comments

Comments
 (0)