|
| 1 | +- name: Get Quota |
| 2 | + k8s_info: |
| 3 | + kind: ResourceQuota |
| 4 | + namespace: "{{ namespace }}" |
| 5 | + register: quota |
| 6 | + retries: 20 |
| 7 | + until: quota.resources | length > 0 |
| 8 | + |
| 9 | +- name: Get Pods |
| 10 | + k8s_info: |
| 11 | + kind: Pod |
| 12 | + namespace: "{{ namespace }}" |
| 13 | + label_selectors: "app={{ app_name }}" |
| 14 | + register: pod |
| 15 | + retries: 20 |
| 16 | + until: pod.resources | length > 0 |
| 17 | + |
| 18 | +#- fail: |
| 19 | +# msg: "There should be only one pod present, before and after the migration." |
| 20 | +# when: pod.resources == 1 |
| 21 | + |
| 22 | +- name: Scale deployment and check that no more pods are allowed |
| 23 | + k8s: |
| 24 | + api_version: "{{ deployment_api }}" |
| 25 | + kind: Deployment |
| 26 | + name: "{{ app_name }}-deployment" |
| 27 | + namespace: "{{ namespace }}" |
| 28 | + definition: |
| 29 | + spec: |
| 30 | + replicas: 2 |
| 31 | + register: scale |
| 32 | + |
| 33 | +- name: Get ReplicaSet |
| 34 | + k8s_info: |
| 35 | + api_version: "{{ deployment_api }}" |
| 36 | + kind: ReplicaSet |
| 37 | + namespace: "{{ namespace }}" |
| 38 | + label_selectors: "app={{ app_name }}" |
| 39 | + register: replica |
| 40 | + until: replica.resources | length > 0 |
| 41 | + |
| 42 | +#- fail: |
| 43 | +# msg: "ReplicaSet should not have created new pods, because resourcequota does not allow it" |
| 44 | +# when: (replica.resources | first ).status.get('conditions', {}) | list | selectattr( 'type', 'equalto', 'ReplicaFailure') | list | length == 0 |
| 45 | + |
| 46 | +- name: Scale down again |
| 47 | + k8s: |
| 48 | + api_version: "{{ deployment_api }}" |
| 49 | + kind: Deployment |
| 50 | + name: "{{ app_name }}-deployment" |
| 51 | + namespace: "{{ namespace }}" |
| 52 | + definition: |
| 53 | + spec: |
| 54 | + replicas: 1 |
| 55 | + |
| 56 | +- name: Get Pods |
| 57 | + k8s_info: |
| 58 | + kind: Pod |
| 59 | + namespace: "{{ namespace }}" |
| 60 | + label_selectors: "app={{ app_name }}" |
| 61 | + register: pod |
| 62 | + retries: 20 |
| 63 | + until: pod.resources | length == 1 |
| 64 | + |
| 65 | +- name: Check that no LoadBalancer can be created |
| 66 | + k8s: |
| 67 | + state : present |
| 68 | + definition: "{{ lookup('template', 'service.yml.j2' ) }}" |
| 69 | + vars: |
| 70 | + service_type: 'LoadBalancer' |
| 71 | + service_app: 'balancersvc' |
| 72 | + register: lbalancer |
| 73 | + ignore_errors: true |
| 74 | + |
| 75 | +- fail: |
| 76 | + msg: "FAILURE. Resource quota should not allow to create more LoadBalancers" |
| 77 | + when: lbalancer.failed != true or lbalancer.error != 403 |
| 78 | + |
| 79 | +- name: Check that no NodePort can be created |
| 80 | + k8s: |
| 81 | + state : present |
| 82 | + definition: "{{ lookup('template', 'service.yml.j2' )}}" |
| 83 | + vars: |
| 84 | + service_type: 'NodePort' |
| 85 | + service_app: 'podeportrsvc' |
| 86 | + register: nodeport |
| 87 | + ignore_errors: true |
| 88 | + |
| 89 | +- fail: |
| 90 | + msg: "FAILURE. Resource quota should not allow to create more NodePort services" |
| 91 | + when: nodeport.failed != true or nodeport.error != 403 |
| 92 | + |
| 93 | +- name: Check that a ClusterIP service can be created. No resourcequota limit reached. |
| 94 | + k8s: |
| 95 | + state : present |
| 96 | + definition: "{{ lookup('template', 'service.yml.j2' )}}" |
| 97 | + vars: |
| 98 | + service_type: 'ClusterIP' |
| 99 | + service_app: 'clustersvc' |
| 100 | + register: clusterip |
| 101 | + |
| 102 | +- name: Remove the created ClusterIP service |
| 103 | + k8s: |
| 104 | + state : absent |
| 105 | + definition: "{{ lookup('template', 'service.yml.j2' )}}" |
| 106 | + vars: |
| 107 | + service_type: 'ClusterIP' |
| 108 | + service_app: 'clustersvc' |
| 109 | + register: clusterip |
| 110 | + |
| 111 | +- name: Check that no more PVCs can be created |
| 112 | + k8s: |
| 113 | + state : present |
| 114 | + definition: "{{ lookup('template', 'persistent-volume-claim.yml.j2' )}}" |
| 115 | + register: pvc |
| 116 | + ignore_errors: true |
| 117 | + |
| 118 | +- fail: |
| 119 | + msg: "FAILURE. Resource quota should not allow to create pvcs" |
| 120 | + when: pvc.failed != true or pvc.error != 403 |
| 121 | + |
| 122 | +- name: Get route |
| 123 | + k8s_facts: |
| 124 | + kind: Route |
| 125 | + namespace: "{{ namespace }}" |
| 126 | + label_selectors: "app={{ app_name }}" |
| 127 | + register: nginx_route |
| 128 | + until: nginx_route.resources | length > 0 |
| 129 | + retries: 30 |
| 130 | + |
| 131 | +- name: Wait for pods running |
| 132 | + k8s_info: |
| 133 | + kind: Pod |
| 134 | + namespace: "{{ namespace }}" |
| 135 | + label_selectors: "app={{ app_name }}" |
| 136 | + field_selectors: |
| 137 | + - status.phase=Running |
| 138 | + register: pod |
| 139 | + retries: 20 |
| 140 | + until: pod.resources | length == 1 |
| 141 | + |
| 142 | +- name: Acces the html file |
| 143 | + uri: |
| 144 | + url: http://{{ nginx_route.resources[0].spec.host }} |
| 145 | + method: GET |
| 146 | + status_code: 200 |
| 147 | + retries: 10 |
| 148 | + register: req |
| 149 | + until: req.status == 200 |
| 150 | + |
0 commit comments