Skip to content

Commit 7c9d1e3

Browse files
feat(e2e-test): Add e2e-test for lvm volume resize support
feat(e2e-test): Add e2e-test for lvm volume resize support
2 parents e96aa86 + 513218c commit 7c9d1e3

File tree

4 files changed

+263
-0
lines changed

4 files changed

+263
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## About this experiment
2+
3+
This experiment verifies the volume resize feature of lvm-localpv. For resize the volume we just need to update the pvc yaml with desired size and apply it. We can directly edit the pvc by ```kubectl edit pvc <pvc_name> -n <namespace>``` command and update the spec.resources.requests.storage field with desired volume size. One thing need to be noted that volume resize can only be done from lower pvc size to higher pvc size. We can not resize the volume from higher pvc size to lower one, in-short volume shrink is not possible. lvm driver supports online volume expansion, so that for using the resized volume, application pod restart is not required. For resize, storage-class which will provision the pvc should have `allowVolumeExpansion: true` field.
4+
5+
for e.g.
6+
```
7+
apiVersion: storage.k8s.io/v1
8+
kind: StorageClass
9+
metadata:
10+
name: openebs-lvmsc
11+
allowVolumeExpansion: true
12+
parameters:
13+
volgroup: "lvmvg"
14+
provisioner: local.csi.openebs.io
15+
```
16+
17+
## Supported platforms:
18+
19+
K8S : 1.17+
20+
21+
OS : Ubuntu
22+
23+
LVM version : LVM 2
24+
25+
## Entry-criteria
26+
27+
- K8s cluster should be in healthy state including all the nodes in ready state.
28+
- lvm-controller and csi node-agent daemonset pods should be in running state.
29+
- storage class with `allowVolumeExpansion: true` enable should be present.
30+
- Application should be deployed succesfully consuming the lvm-localpv storage.
31+
32+
## Exit-criteria
33+
34+
- Volume should be resized successfully and application should be accessible seamlessly.
35+
- Application should be able to use the new resize volume space.
36+
37+
## How to run
38+
39+
- This experiment accepts the parameters in form of kubernetes job environmental variables.
40+
- For running this experiment of lvm volume resize, clone openens/lvm-localpv[https://github.com/openebs/lvm-localpv] repo and then first apply rbac and crds for e2e-framework.
41+
```
42+
kubectl apply -f lvm-localpv/e2e-tests/hack/rbac.yaml
43+
kubectl apply -f lvm-localpv/e2e-tests/hack/crds.yaml
44+
```
45+
then update the needed test specific values in run_e2e_test.yml file and create the kubernetes job.
46+
```
47+
kubectl create -f run_e2e_test.yml
48+
```
49+
All the env variables description is provided with the comments in the same file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
generateName: lvm-vol-resize-
6+
namespace: e2e
7+
spec:
8+
template:
9+
metadata:
10+
name: lvm-vol-resize
11+
labels:
12+
app: lvm-vol-resize
13+
14+
spec:
15+
serviceAccountName: e2e
16+
restartPolicy: Never
17+
containers:
18+
- name: ansibletest
19+
image: openebs/lvm-localpv-e2e:ci
20+
imagePullPolicy: IfNotPresent
21+
22+
env:
23+
- name: ANSIBLE_STDOUT_CALLBACK
24+
value: default
25+
26+
# This is the namespace where application pod is running
27+
- name: APP_NAMESPACE
28+
value: ''
29+
30+
# Name of the application pvc
31+
- name: APP_PVC
32+
value: ''
33+
34+
# Application pod label in `key=value` format
35+
- name: APP_LABEL
36+
value: ''
37+
38+
# Storage class name used for `APP_PVC` provision
39+
- name: STORAGE_CLASS
40+
value: ''
41+
42+
# PVC size (for eg. 5Gi)
43+
- name: OLD_PV_CAPACITY
44+
value: ''
45+
46+
# Resized PVC size (for eg. 10Gi)
47+
- name: NEW_PV_CAPACITY
48+
value: ''
49+
50+
command: ["/bin/bash"]
51+
args: ["-c", "ansible-playbook ./e2e-tests/experiments/functional/lvm-volume-resize/test.yml -i /etc/ansible/hosts -vv; exit 0"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
- hosts: localhost
3+
connection: local
4+
gather_facts: False
5+
6+
vars_files:
7+
- test_vars.yml
8+
9+
tasks:
10+
- block:
11+
12+
## Generating the testname for lvm volume resize test
13+
- include_tasks: /e2e-tests/hack/create_testname.yml
14+
15+
## Record SOT (start of test) in e2e result e2e-cr (e2e-custom-resource)
16+
- include_tasks: /e2e-tests/hack/update_e2e_result_resource.yml
17+
vars:
18+
status: 'SOT'
19+
20+
- block:
21+
22+
- name: Check if the desired PVC is bound
23+
shell: >
24+
kubectl get pvc {{ app_pvc }} -n {{ app_ns }} --no-headers
25+
-o custom-columns=:.status.phase
26+
args:
27+
executable: /bin/bash
28+
register: pvc_status
29+
failed_when: "'Bound' not in pvc_status.stdout"
30+
31+
- name: Get the application pod name using {{ app_pvc }} pvc
32+
shell: >
33+
kubectl get pod -n {{ app_ns }} -l {{ app_label }} --no-headers
34+
-o custom-columns=:.metadata.name
35+
args:
36+
executable: /bin/bash
37+
register: app_pod
38+
39+
- name: Obtain the mount path for the application
40+
shell: >
41+
kubectl get pod {{ app_pod.stdout }} -n {{ app_ns }}
42+
-o custom-columns=:.spec.containers[].volumeMounts[].mountPath --no-headers
43+
args:
44+
executable: /bin/bash
45+
register: mount
46+
47+
- name: Fetch the Storage from PVC using namespace
48+
shell: kubectl get pvc -n {{ app_ns }} -o jsonpath={.items[0].spec.resources.requests.storage}
49+
args:
50+
executable: /bin/bash
51+
register: storage_capacity
52+
53+
- name: Fetch the alphabet(G,M,m,g) from storage capacity
54+
shell: echo "{{ storage_capacity.stdout }}" | grep -o -E '[0-9]+'
55+
args:
56+
executable: /bin/bash
57+
register: value_str
58+
59+
- name: Obtain the PVC spec
60+
shell: >
61+
kubectl get pvc {{ app_pvc }} -n {{ app_ns }}
62+
--no-headers -o yaml > pvc.yml
63+
args:
64+
executable: /bin/bash
65+
66+
- name: Update the desired capacity in PVC spec
67+
replace:
68+
path: pvc.yml
69+
before: 'storageClassName: {{ storage_class }}'
70+
regexp: "storage: {{ vol_size }}"
71+
replace: "storage: {{ desired_vol_size }}"
72+
73+
- name: Configure PVC with the new capacity
74+
shell: kubectl apply -f pvc.yml
75+
args:
76+
executable: /bin/bash
77+
register: result
78+
failed_when: "result.rc != 0"
79+
80+
- name: Check if the desired PVC is bound
81+
shell: >
82+
kubectl get pvc {{ app_pvc }} -n {{ app_ns }} --no-headers
83+
-o custom-columns=:.status.phase
84+
args:
85+
executable: /bin/bash
86+
register: pvc_status
87+
failed_when: "'Bound' not in pvc_status.stdout"
88+
89+
- name: Check if the storage capacity is updated in PVC
90+
shell: >
91+
kubectl get pvc {{ app_pvc }} -n {{ app_ns }} --no-headers
92+
-o custom-columns=:status.capacity.storage
93+
args:
94+
executable: /bin/bash
95+
register: capacity
96+
until: "desired_vol_size in capacity.stdout"
97+
delay: 10
98+
retries: 50
99+
100+
- name: Restart the application pod after resizing the volume
101+
shell: kubectl delete pod {{ app_pod.stdout }} -n {{ app_ns }}
102+
args:
103+
executable: /bin/bash
104+
register: app_pod_status
105+
failed_when: app_pod_status.rc != 0
106+
107+
- name: Verify that application pod is deleted successfully.
108+
shell: >
109+
kubectl get pods -n {{ app_ns }}
110+
args:
111+
executable: /bin/bash
112+
register: app_pod_list
113+
until: '"{{ app_pod.stdout }}" not in app_pod_list.stdout'
114+
delay: 2
115+
retries: 30
116+
117+
- name: Get the name of application pod after Restart
118+
shell: >
119+
kubectl get pod -n {{ app_ns }} -l {{ app_label }} --no-headers
120+
-o custom-columns=:.metadata.name
121+
args:
122+
executable: /bin/bash
123+
register: app_pod_name
124+
125+
## Here we will dump +1Gi data than to previous pvc size
126+
- set_fact:
127+
value_num: '{{ ( (value_str.stdout | int + 1 | int) * 262144) | int }}'
128+
129+
- name: Dump some more dummy data in the application mount point for using resized volume
130+
shell: >
131+
kubectl exec -it "{{ app_pod_name.stdout }}" -n "{{ app_ns }}"
132+
-- sh -c "cd {{ mount.stdout }} && dd if=/dev/urandom of=volume.txt bs=4k count={{ value_num }}"
133+
args:
134+
executable: /bin/bash
135+
register: load
136+
failed_when: "load.rc != 0"
137+
138+
- set_fact:
139+
flag: "Pass"
140+
141+
rescue:
142+
- set_fact:
143+
flag: "Fail"
144+
145+
always:
146+
# RECORD END-OF-TEST IN e2e RESULT CR
147+
- include_tasks: /e2e-tests/hack/update_e2e_result_resource.yml
148+
vars:
149+
status: 'EOT'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
test_name: lvm-volume-resize
3+
4+
app_ns: "{{ lookup('env','APP_NAMESPACE') }}"
5+
6+
app_label: "{{ lookup('env','APP_LABEL') }}"
7+
8+
app_pvc: "{{ lookup('env','APP_PVC') }}"
9+
10+
vol_size: "{{ lookup('env','OLD_PV_CAPACITY') }}"
11+
12+
desired_vol_size: "{{ lookup('env','NEW_PV_CAPACITY') }}"
13+
14+
storage_class: "{{ lookup('env','STORAGE_CLASS') }}"

0 commit comments

Comments
 (0)