diff --git a/e2e-tests/experiments/functional/lvm-volume-resize/README.md b/e2e-tests/experiments/functional/lvm-volume-resize/README.md new file mode 100644 index 00000000..a8eeabe9 --- /dev/null +++ b/e2e-tests/experiments/functional/lvm-volume-resize/README.md @@ -0,0 +1,49 @@ +## About this experiment + +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 -n ``` 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. + +for e.g. +``` +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: openebs-lvmsc +allowVolumeExpansion: true +parameters: + volgroup: "lvmvg" +provisioner: local.csi.openebs.io +``` + +## Supported platforms: + +K8S : 1.17+ + +OS : Ubuntu + +LVM version : LVM 2 + +## Entry-criteria + +- K8s cluster should be in healthy state including all the nodes in ready state. +- lvm-controller and csi node-agent daemonset pods should be in running state. +- storage class with `allowVolumeExpansion: true` enable should be present. +- Application should be deployed succesfully consuming the lvm-localpv storage. + +## Exit-criteria + +- Volume should be resized successfully and application should be accessible seamlessly. +- Application should be able to use the new resize volume space. + +## How to run + +- This experiment accepts the parameters in form of kubernetes job environmental variables. +- 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. +``` +kubectl apply -f lvm-localpv/e2e-tests/hack/rbac.yaml +kubectl apply -f lvm-localpv/e2e-tests/hack/crds.yaml +``` +then update the needed test specific values in run_e2e_test.yml file and create the kubernetes job. +``` +kubectl create -f run_e2e_test.yml +``` +All the env variables description is provided with the comments in the same file. \ No newline at end of file diff --git a/e2e-tests/experiments/functional/lvm-volume-resize/run_e2e_test.yml b/e2e-tests/experiments/functional/lvm-volume-resize/run_e2e_test.yml new file mode 100644 index 00000000..b49e424b --- /dev/null +++ b/e2e-tests/experiments/functional/lvm-volume-resize/run_e2e_test.yml @@ -0,0 +1,51 @@ +--- +apiVersion: batch/v1 +kind: Job +metadata: + generateName: lvm-vol-resize- + namespace: e2e +spec: + template: + metadata: + name: lvm-vol-resize + labels: + app: lvm-vol-resize + + spec: + serviceAccountName: e2e + restartPolicy: Never + containers: + - name: ansibletest + image: openebs/lvm-localpv-e2e:ci + imagePullPolicy: IfNotPresent + + env: + - name: ANSIBLE_STDOUT_CALLBACK + value: default + + # This is the namespace where application pod is running + - name: APP_NAMESPACE + value: '' + + # Name of the application pvc + - name: APP_PVC + value: '' + + # Application pod label in `key=value` format + - name: APP_LABEL + value: '' + + # Storage class name used for `APP_PVC` provision + - name: STORAGE_CLASS + value: '' + + # PVC size (for eg. 5Gi) + - name: OLD_PV_CAPACITY + value: '' + + # Resized PVC size (for eg. 10Gi) + - name: NEW_PV_CAPACITY + value: '' + + command: ["/bin/bash"] + args: ["-c", "ansible-playbook ./e2e-tests/experiments/functional/lvm-volume-resize/test.yml -i /etc/ansible/hosts -vv; exit 0"] \ No newline at end of file diff --git a/e2e-tests/experiments/functional/lvm-volume-resize/test.yml b/e2e-tests/experiments/functional/lvm-volume-resize/test.yml new file mode 100644 index 00000000..4061924e --- /dev/null +++ b/e2e-tests/experiments/functional/lvm-volume-resize/test.yml @@ -0,0 +1,149 @@ +--- +- hosts: localhost + connection: local + gather_facts: False + + vars_files: + - test_vars.yml + + tasks: + - block: + + ## Generating the testname for lvm volume resize test + - include_tasks: /e2e-tests/hack/create_testname.yml + + ## Record SOT (start of test) in e2e result e2e-cr (e2e-custom-resource) + - include_tasks: /e2e-tests/hack/update_e2e_result_resource.yml + vars: + status: 'SOT' + + - block: + + - name: Check if the desired PVC is bound + shell: > + kubectl get pvc {{ app_pvc }} -n {{ app_ns }} --no-headers + -o custom-columns=:.status.phase + args: + executable: /bin/bash + register: pvc_status + failed_when: "'Bound' not in pvc_status.stdout" + + - name: Get the application pod name using {{ app_pvc }} pvc + shell: > + kubectl get pod -n {{ app_ns }} -l {{ app_label }} --no-headers + -o custom-columns=:.metadata.name + args: + executable: /bin/bash + register: app_pod + + - name: Obtain the mount path for the application + shell: > + kubectl get pod {{ app_pod.stdout }} -n {{ app_ns }} + -o custom-columns=:.spec.containers[].volumeMounts[].mountPath --no-headers + args: + executable: /bin/bash + register: mount + + - name: Fetch the Storage from PVC using namespace + shell: kubectl get pvc -n {{ app_ns }} -o jsonpath={.items[0].spec.resources.requests.storage} + args: + executable: /bin/bash + register: storage_capacity + + - name: Fetch the alphabet(G,M,m,g) from storage capacity + shell: echo "{{ storage_capacity.stdout }}" | grep -o -E '[0-9]+' + args: + executable: /bin/bash + register: value_str + + - name: Obtain the PVC spec + shell: > + kubectl get pvc {{ app_pvc }} -n {{ app_ns }} + --no-headers -o yaml > pvc.yml + args: + executable: /bin/bash + + - name: Update the desired capacity in PVC spec + replace: + path: pvc.yml + before: 'storageClassName: {{ storage_class }}' + regexp: "storage: {{ vol_size }}" + replace: "storage: {{ desired_vol_size }}" + + - name: Configure PVC with the new capacity + shell: kubectl apply -f pvc.yml + args: + executable: /bin/bash + register: result + failed_when: "result.rc != 0" + + - name: Check if the desired PVC is bound + shell: > + kubectl get pvc {{ app_pvc }} -n {{ app_ns }} --no-headers + -o custom-columns=:.status.phase + args: + executable: /bin/bash + register: pvc_status + failed_when: "'Bound' not in pvc_status.stdout" + + - name: Check if the storage capacity is updated in PVC + shell: > + kubectl get pvc {{ app_pvc }} -n {{ app_ns }} --no-headers + -o custom-columns=:status.capacity.storage + args: + executable: /bin/bash + register: capacity + until: "desired_vol_size in capacity.stdout" + delay: 10 + retries: 50 + + - name: Restart the application pod after resizing the volume + shell: kubectl delete pod {{ app_pod.stdout }} -n {{ app_ns }} + args: + executable: /bin/bash + register: app_pod_status + failed_when: app_pod_status.rc != 0 + + - name: Verify that application pod is deleted successfully. + shell: > + kubectl get pods -n {{ app_ns }} + args: + executable: /bin/bash + register: app_pod_list + until: '"{{ app_pod.stdout }}" not in app_pod_list.stdout' + delay: 2 + retries: 30 + + - name: Get the name of application pod after Restart + shell: > + kubectl get pod -n {{ app_ns }} -l {{ app_label }} --no-headers + -o custom-columns=:.metadata.name + args: + executable: /bin/bash + register: app_pod_name + + ## Here we will dump +1Gi data than to previous pvc size + - set_fact: + value_num: '{{ ( (value_str.stdout | int + 1 | int) * 262144) | int }}' + + - name: Dump some more dummy data in the application mount point for using resized volume + shell: > + kubectl exec -it "{{ app_pod_name.stdout }}" -n "{{ app_ns }}" + -- sh -c "cd {{ mount.stdout }} && dd if=/dev/urandom of=volume.txt bs=4k count={{ value_num }}" + args: + executable: /bin/bash + register: load + failed_when: "load.rc != 0" + + - set_fact: + flag: "Pass" + + rescue: + - set_fact: + flag: "Fail" + + always: + # RECORD END-OF-TEST IN e2e RESULT CR + - include_tasks: /e2e-tests/hack/update_e2e_result_resource.yml + vars: + status: 'EOT' \ No newline at end of file diff --git a/e2e-tests/experiments/functional/lvm-volume-resize/test_vars.yml b/e2e-tests/experiments/functional/lvm-volume-resize/test_vars.yml new file mode 100644 index 00000000..013d8365 --- /dev/null +++ b/e2e-tests/experiments/functional/lvm-volume-resize/test_vars.yml @@ -0,0 +1,14 @@ +--- +test_name: lvm-volume-resize + +app_ns: "{{ lookup('env','APP_NAMESPACE') }}" + +app_label: "{{ lookup('env','APP_LABEL') }}" + +app_pvc: "{{ lookup('env','APP_PVC') }}" + +vol_size: "{{ lookup('env','OLD_PV_CAPACITY') }}" + +desired_vol_size: "{{ lookup('env','NEW_PV_CAPACITY') }}" + +storage_class: "{{ lookup('env','STORAGE_CLASS') }}" \ No newline at end of file