From 665d9091722cebd6495ee1951dd71e5739362d02 Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 29 May 2020 13:11:19 +0000 Subject: [PATCH] Add ocp-31309-quotanoattach testcase --- .../ocp-31309-quotanoattach/defaults/main.yml | 15 +++++ .../ocp-31309-quotanoattach/tasks/deploy.yml | 58 +++++++++++++++++++ roles/ocp-31309-quotanoattach/tasks/main.yml | 20 +++++++ .../ocp-31309-quotanoattach/tasks/migrate.yml | 3 + roles/ocp-31309-quotanoattach/tasks/track.yml | 3 + .../tasks/validate.yml | 38 ++++++++++++ .../templates/persistent-volume-claim.yml.j2 | 11 ++++ .../templates/provisioner-pod.yml.j2 | 25 ++++++++ .../templates/resourcequota.yml.j2 | 19 ++++++ .../templates/validator-pod.yml.j2 | 34 +++++++++++ 10 files changed, 226 insertions(+) create mode 100644 roles/ocp-31309-quotanoattach/defaults/main.yml create mode 100644 roles/ocp-31309-quotanoattach/tasks/deploy.yml create mode 100644 roles/ocp-31309-quotanoattach/tasks/main.yml create mode 100644 roles/ocp-31309-quotanoattach/tasks/migrate.yml create mode 100644 roles/ocp-31309-quotanoattach/tasks/track.yml create mode 100644 roles/ocp-31309-quotanoattach/tasks/validate.yml create mode 100644 roles/ocp-31309-quotanoattach/templates/persistent-volume-claim.yml.j2 create mode 100644 roles/ocp-31309-quotanoattach/templates/provisioner-pod.yml.j2 create mode 100644 roles/ocp-31309-quotanoattach/templates/resourcequota.yml.j2 create mode 100644 roles/ocp-31309-quotanoattach/templates/validator-pod.yml.j2 diff --git a/roles/ocp-31309-quotanoattach/defaults/main.yml b/roles/ocp-31309-quotanoattach/defaults/main.yml new file mode 100644 index 0000000..cf415a0 --- /dev/null +++ b/roles/ocp-31309-quotanoattach/defaults/main.yml @@ -0,0 +1,15 @@ +namespace: "ocp-31309-quotanoattach" + +storage_size: 1Mi +access_mode: ReadWriteOnce + +migration_sample_name: "ocp-31309-quotanoattach" +migration_plan_name: "{{ migration_sample_name }}-migplan-{{ ansible_date_time.epoch }}" +migration_name: "{{ migration_sample_name }}-mig-{{ ansible_date_time.epoch }}" + +with_deploy: true +with_migrate: true +with_cleanup: true +with_validate: true +pv: false +quiesce: false diff --git a/roles/ocp-31309-quotanoattach/tasks/deploy.yml b/roles/ocp-31309-quotanoattach/tasks/deploy.yml new file mode 100644 index 0000000..b294fa6 --- /dev/null +++ b/roles/ocp-31309-quotanoattach/tasks/deploy.yml @@ -0,0 +1,58 @@ +- name: Check namespace + k8s_facts: + kind: Namespace + name: "{{ namespace }}" + register: ns + +- name: Create namespace + shell: "{{ oc_binary }} new-project {{ namespace }} --skip-config-write=true" + when: ns.resources | length == 0 + + +- name: Get LimitRange + k8s_info: + kind: LimitRange + namespace: "{{ namespace }}" + register: limitrange + until: limitrange.resources | length > 0 + ignore_errors: true + +- name: Remove LimitRanges so that default limit ranges dont interfere with the test + k8s: + kind: LimitRange + state : absent + namespace: "{{ namespace }}" + name: "{{ item.metadata.name }}" + loop: "{{ limitrange.resources | default([]) }}" + +- name: Create resource quota + k8s: + state : present + definition: "{{ lookup('template', 'resourcequota.yml.j2' )}}" + +- name: Create persistent volume claim + k8s: + state : present + definition: "{{ lookup('template', 'persistent-volume-claim.yml.j2' )}}" + +- name: Provision the volume + k8s: + state : present + definition: "{{ lookup('template', 'provisioner-pod.yml.j2' )}}" + + +- name: Wait until provision is done + k8s_facts: + kind: Pod + namespace: "{{ namespace }}" + label_selectors: "app=provision" + field_selectors: + - status.phase=Succeeded + register: pod + until: pod.resources | length > 0 + retries: 30 + +- name: Remove the provisioner pod + k8s: + state : absent + definition: "{{ lookup('template', 'provisioner-pod.yml.j2' )}}" diff --git a/roles/ocp-31309-quotanoattach/tasks/main.yml b/roles/ocp-31309-quotanoattach/tasks/main.yml new file mode 100644 index 0000000..91c9ee8 --- /dev/null +++ b/roles/ocp-31309-quotanoattach/tasks/main.yml @@ -0,0 +1,20 @@ +- name: Cleanup resources + include_role: + name: migration_cleanup + when: with_cleanup|bool + +- name: Create resources + import_tasks: deploy.yml + when: with_deploy|bool + +- name: Start migration + import_tasks: migrate.yml + when: with_migrate|bool + +- name: Track migration + import_tasks: track.yml + when: with_migrate|bool + +- name: Validate migration + import_tasks: validate.yml + when: with_validate|bool diff --git a/roles/ocp-31309-quotanoattach/tasks/migrate.yml b/roles/ocp-31309-quotanoattach/tasks/migrate.yml new file mode 100644 index 0000000..ac543a0 --- /dev/null +++ b/roles/ocp-31309-quotanoattach/tasks/migrate.yml @@ -0,0 +1,3 @@ +- name: Execute migration + include_role: + name: migration_run diff --git a/roles/ocp-31309-quotanoattach/tasks/track.yml b/roles/ocp-31309-quotanoattach/tasks/track.yml new file mode 100644 index 0000000..8a3cf7c --- /dev/null +++ b/roles/ocp-31309-quotanoattach/tasks/track.yml @@ -0,0 +1,3 @@ +- name: Track migration + include_role: + name: migration_track diff --git a/roles/ocp-31309-quotanoattach/tasks/validate.yml b/roles/ocp-31309-quotanoattach/tasks/validate.yml new file mode 100644 index 0000000..b4d71e6 --- /dev/null +++ b/roles/ocp-31309-quotanoattach/tasks/validate.yml @@ -0,0 +1,38 @@ +- name: Get Quota + k8s_info: + kind: ResourceQuota + namespace: "{{ namespace }}" + register: quota + retries: 20 + until: quota.resources | length > 0 + +- name: Get Persistent Volume + k8s_info: + kind: PersistentVolumeClaim + namespace: "{{ namespace }}" + name: quoatdev-test + register: vol + retries: 10 + until: vol.resources | length > 0 + +- name: Validate the volume + k8s: + state : present + definition: "{{ lookup('template', 'validator-pod.yml.j2' )}}" + + +- name: Wait until validation is done + k8s_facts: + kind: Pod + namespace: "{{ namespace }}" + label_selectors: "app=validation" + field_selectors: + - status.phase=Succeeded + register: pod + until: pod.resources | length > 0 + retries: 30 + +- name: Validate the volume + k8s: + state : absent + definition: "{{ lookup('template', 'validator-pod.yml.j2' )}}" diff --git a/roles/ocp-31309-quotanoattach/templates/persistent-volume-claim.yml.j2 b/roles/ocp-31309-quotanoattach/templates/persistent-volume-claim.yml.j2 new file mode 100644 index 0000000..01ba26b --- /dev/null +++ b/roles/ocp-31309-quotanoattach/templates/persistent-volume-claim.yml.j2 @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: quoatdev-test + namespace: {{ namespace }} +spec: + accessModes: + - {{ access_mode }} + resources: + requests: + storage: {{ storage_size }} diff --git a/roles/ocp-31309-quotanoattach/templates/provisioner-pod.yml.j2 b/roles/ocp-31309-quotanoattach/templates/provisioner-pod.yml.j2 new file mode 100644 index 0000000..cbd1249 --- /dev/null +++ b/roles/ocp-31309-quotanoattach/templates/provisioner-pod.yml.j2 @@ -0,0 +1,25 @@ +apiVersion: v1 +kind: Pod +metadata: + name: provisioner-pod + namespace: {{ namespace }} + labels: + app: provision +spec: + restartPolicy: OnFailure + containers: + - name: provisioner + resources: + limits: + cpu: "0.01" + memory: 128Mi + image: alpine + command: [ "/bin/sh", "-c", "--" ] + args: [ "echo 'data inserted' > /data/vol/data.txt ; dd if=/dev/urandom of=/data/vol/binary.rnd bs=1000000 count=1" ] + volumeMounts: + - name: testvolume + mountPath: /data/vol + volumes: + - name: testvolume + persistentVolumeClaim: + claimName: quoatdev-test diff --git a/roles/ocp-31309-quotanoattach/templates/resourcequota.yml.j2 b/roles/ocp-31309-quotanoattach/templates/resourcequota.yml.j2 new file mode 100644 index 0000000..9d3dd3b --- /dev/null +++ b/roles/ocp-31309-quotanoattach/templates/resourcequota.yml.j2 @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: ResourceQuota +metadata: + name: object-quota + namespace: {{ namespace }} +spec: + hard: + persistentvolumeclaims: "2" + services.loadbalancers: "0" + services.nodeports: "0" + pods: "1" + replicationcontrollers: "1" + secrets: "6" + configmaps: "4" + services: "10" + limits.cpu: "20" + limits.memory: 20Gi + requests.cpu: "10" + requests.memory: 10Gi diff --git a/roles/ocp-31309-quotanoattach/templates/validator-pod.yml.j2 b/roles/ocp-31309-quotanoattach/templates/validator-pod.yml.j2 new file mode 100644 index 0000000..f51a212 --- /dev/null +++ b/roles/ocp-31309-quotanoattach/templates/validator-pod.yml.j2 @@ -0,0 +1,34 @@ +apiVersion: v1 +kind: Pod +metadata: + name: validator-pod + namespace: {{ namespace }} + labels: + app: validation +spec: + restartPolicy: OnFailure + containers: + - name: validator + image: alpine + resources: + limits: + cpu: "0.01" + memory: 128Mi + command: [ "/bin/sh", "-c", "--" ] + args: + - set -e; + echo 'Validating'; + cd /data/vol; + ls data.txt; + ls binary.rnd; + export CONTENT=$(cat data.txt); + [[ "$CONTENT" == 'data inserted' ]] || { echo 'Wrong data content' && exit 1; } ; + export SIZE=$( wc -c binary.rnd | cut -d ' ' -f 1 ); + [[ $SIZE == '1000000' ]] || { echo 'Wrong binary file size' && exit 1; }; + volumeMounts: + - name: testvolume + mountPath: /data/vol + volumes: + - name: testvolume + persistentVolumeClaim: + claimName: quoatdev-test