feat(e2e-test): Add e2e-tests for zfs-localpv (#298)

Signed-off-by: w3aman <aman.gupta@mayadata.io>
This commit is contained in:
Aman Gupta 2021-06-09 21:21:39 +05:30 committed by GitHub
parent 53f872fcf1
commit 4e73638b5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
137 changed files with 8745 additions and 0 deletions

View file

@ -0,0 +1,16 @@
---
- name: Obtain list of existing namespaces
shell: >
kubectl get ns --no-headers -o custom-columns=:metadata.name
args:
executable: /bin/bash
register: ns_list
- name: Create test specific namespace.
shell: kubectl create ns {{ app_ns }}
args:
executable: /bin/bash
when: app_ns != 'e2e' and app_ns not in ns_list.stdout_lines
# Check status of namespace
- include_tasks: /e2e-tests/utils/k8s/status_testns.yml

View file

@ -0,0 +1,12 @@
---
#Deploying application on k8's cluster and cross checking whether the
#application is deployed successfully.
- name: Deploying {{ application_name }}
k8s:
state: present
src: "{{ application }}"
namespace: "{{ app_ns }}"
merge_type: merge
register: result
- include_tasks: /e2e-tests/utils/k8s/status_app_pod.yml

View file

@ -0,0 +1,106 @@
---
# This Utility task file can delete the application and its underlying resources such as pvc and service from K8s cluster
# This accepts application namespace, application label and application manifest file as input parameters.
# The parameters used are
# - app_deployer ( Deployment spec yaml file )
# - app_ns ( application namespace )
# - app_label ( application label)
#
- block:
- name: Check if the application to be deleted is available.
k8s_facts:
kind: Pod
label_selectors:
- "{{ app_label }}"
namespace: "{{ app_ns }}"
register: po_name
until: "{{ po_name | json_query('resources[*].status.phase') | unique | length==1}}"
delay: 5
retries: 60
- name: Obtaining the PVC name using application label.
set_fact:
pvc_name: "{{ po_name.resources.0.spec.volumes.0.persistentVolumeClaim.claimName }}"
pod_name: "{{ po_name.resources.0.metadata.name }}"
- name: Obtaining the PV name from PVC name.
k8s_facts:
kind: PersistentVolumeClaim
namespace: "{{ app_ns }}"
name: "{{ pvc_name }}"
register: pv_name
- set_fact:
pvname: "{{ pv_name | json_query('resources[0].spec.volumeName') }}"
## Replacing the item names in the respective deployer spec file.
- name: Replace the PVC name in application deployer spec.
replace:
path: "{{ app_deployer }}"
regexp: "testclaim"
replace: "{{ lookup('env','APP_PVC') }}"
when: app_pvc is defined
- name: Replace the storageclass placeholder with provider
replace:
path: "{{ app_deployer }}"
regexp: "testclass"
replace: "{{ lookup('env','PROVIDER_STORAGE_CLASS') }}"
when: storage_class is defined
- block:
- name: Get the application label values from env
set_fact:
app_lkey: "{{ app_label.split('=')[0] }}"
app_lvalue: "{{ app_label.split('=')[1] }}"
- name: Replace the application label placeholder
replace:
path: "{{ app_deployer }}"
regexp: "lkey: lvalue"
replace: "{{ app_lkey }}: {{ app_lvalue }}"
when: app_label is defined
- name: Delete the application deployment.
shell: kubectl delete -f {{ app_deployer }} -n {{ app_ns }}
args:
executable: /bin/bash
ignore_errors: true
- name: Check if the PVC is deleted.
k8s_facts:
kind: PersistentVolumeClaim
namespace: "{{ app_ns }}"
label_selectors:
- "{{ app_label }}"
register: resource_list
until: resource_list.resources | length < 1
delay: 5
retries: 120
- name: Check if the pods are deleted in the namespaces
shell: >
kubectl get pods -n {{ app_ns }}
args:
executable: /bin/bash
register: result
until: "pod_name not in result.stdout"
delay: 5
retries: 60
- name: Delete the namespace.
k8s:
state: absent
kind: Namespace
name: "{{ app_ns }}"
- name: Check if the PV is deleted.
k8s_facts:
kind: PersistentVolume
name: "{{ pvname }}"
label_selectors:
- "{{ app_label }}"
register: pv_result
failed_when: "pv_result.resources | length > 1"

View file

@ -0,0 +1,72 @@
---
- block:
- name: Check if the statefulset application exists.
shell: kubectl get pods -n {{ app_ns }} -l {{ app_label }}
register: pods
failed_when: "'No resources found' in pods.stdout"
- name: Obtaining PVCs related to the application.
shell: kubectl get pvc -n {{ app_ns }} -l {{ app_label }} --no-headers -o custom-columns=:.metadata.name
register: pvc_list
- name: Obtaining the PV names.
shell: kubectl get pvc -l {{ app_label }} -n {{ app_ns }} --no-headers -o custom-columns=:.spec.volumeName
register: pv_list
## Replacing the item names in the respective deployer spec file.
- name: Replace the PVC name in application deployer spec.
replace:
path: "{{ app_deployer }}"
regexp: "testclaim"
replace: "{{ lookup('env','APP_PVC') }}"
when: app_pvc is defined
- name: Replace the storageclass placeholder with provider
replace:
path: "{{ app_deployer }}"
regexp: "testclass"
replace: "{{ lookup('env','PROVIDER_STORAGE_CLASS') }}"
when: storage_class is defined
- block:
- name: Get the application label values from env
set_fact:
app_lkey: "{{ app_label.split('=')[0] }}"
app_lvalue: "{{ app_label.split('=')[1] }}"
- name: Replace the application label placeholder
replace:
path: "{{ app_deployer }}"
regexp: "lkey: lvalue"
replace: "{{ app_lkey }}: {{ app_lvalue }}"
when: app_label is defined
- name: Delete the application and its related service.
shell: kubectl delete -f {{ app_deployer }} -n {{ app_ns }}
register: app_status
until: 'app_status.rc == 0'
delay: 5
retries: 60
- name: Deleting the PVC
shell: kubectl delete pvc {{ item }} -n {{ app_ns }}
args:
executable: /bin/bash
with_items:
- "{{ pvc_list.stdout_lines }}"
- name: Check if the PVCs are deleted
shell: kubectl get pvc -n {{ app_ns }}
register: list_pvc
until: "'No resources found' in list_pvc.stderr"
delay: 30
retries: 15
- name: Delete the namespace.
shell: kubectl delete ns {{ app_ns }}
args:
executable: /bin/bash

View file

@ -0,0 +1,13 @@
---
#Fetching the details of the application pod
- name: Getting the {{ application_name }} POD name
k8s_facts:
kind: Pod
namespace: "{{ app_ns }}"
label_selectors:
- "{{ app_label }}"
register: pod_name
- debug:
msg: "{{ pod_name | json_query('resources[*].metadata.name') }}"

View file

@ -0,0 +1,40 @@
---
- block:
- name: Check whether the provider storageclass is present
shell: kubectl get sc "{{ lookup('env','STORAGE_CLASS') }}"
args:
executable: /bin/bash
register: result
failed_when: "result.rc != 0"
- name: Replace the storageclass placeholder with test specific value
replace:
path: "{{ application }}"
regexp: "testclass"
replace: "{{ lookup('env','STORAGE_CLASS') }}"
- name: Replace the application pvc placeholder with test specific value
replace:
path: "{{ application }}"
regexp: "testclaim"
replace: "{{ lookup('env','APP_PVC') }}"
- name: Replace the persistent volume capcity placeholder with test specific value
replace:
path: "{{ application }}"
regexp: "teststorage"
replace: "{{ lookup('env','PV_CAPACITY') }}"
- name: Get the application label value from env
set_fact:
app_lkey: "{{ app_label.split('=')[0] }}"
app_lvalue: "{{ app_label.split('=')[1] }}"
- name: Replace the application label placeholder in deployment spec
replace:
path: "{{ application }}"
regexp: "lkey: lvalue"
replace: "{{ app_lkey }}: {{ app_lvalue }}"
# Create test specific namespace
- include_tasks: /e2e-tests/utils/k8s/create_ns.yml

View file

@ -0,0 +1,18 @@
---
- name: Checking {{ application_name }} pod is in running state
shell: kubectl get pods -n {{ app_ns }} -o jsonpath='{.items[?(@.metadata.labels.{{app_lkey}}=="{{app_lvalue}}")].status.phase}'
register: result
until: "((result.stdout.split()|unique)|length) == 1 and 'Running' in result.stdout"
delay: 3
retries: 60
- name: Get the container status of application.
shell: >
kubectl get pod -n {{ app_ns }} -l {{app_lkey}}="{{app_lvalue}}"
-o custom-columns=:..containerStatuses[].state --no-headers | grep -w "running"
args:
executable: /bin/bash
register: containerStatus
until: "'running' in containerStatus.stdout"
delay: 3
retries: 60

View file

@ -0,0 +1,9 @@
---
- name: Checking the status of test specific namespace.
k8s_facts:
kind: Namespace
name: "{{ app_ns }}"
register: npstatus
until: "'Active' in npstatus.resources.0.status.phase"
delay: 30
retries: 10