|
| 1 | +--- |
| 2 | +# Purge leftover bogus-* MachineSets/Machines before openstack_test. |
| 3 | +# Pairs with openstack-test bz_2073398 cleanup; suite-level hygiene if that It left |
| 4 | +# stuck objects that poison later Machine / MachineSet / ProviderSpec specs. |
| 5 | +# After delete, wait until gone; fail if leftovers remain so openstack_test does not start dirty. |
| 6 | +- name: List bogus MachineSets in openshift-machine-api |
| 7 | + ansible.builtin.shell: | |
| 8 | + set -o pipefail |
| 9 | + oc get machineset -n openshift-machine-api -o name 2>/dev/null \ |
| 10 | + | grep -E 'bogus-' || true |
| 11 | + environment: |
| 12 | + KUBECONFIG: "{{ kubeconfig }}" |
| 13 | + register: bogus_machinesets_cmd |
| 14 | + changed_when: false |
| 15 | + failed_when: false |
| 16 | + |
| 17 | +- name: List bogus Machines in openshift-machine-api |
| 18 | + ansible.builtin.shell: | |
| 19 | + set -o pipefail |
| 20 | + oc get machine -n openshift-machine-api -o name 2>/dev/null \ |
| 21 | + | grep -E 'bogus-' || true |
| 22 | + environment: |
| 23 | + KUBECONFIG: "{{ kubeconfig }}" |
| 24 | + register: bogus_machines_cmd |
| 25 | + changed_when: false |
| 26 | + failed_when: false |
| 27 | + |
| 28 | +- name: Delete leftover bogus MachineSets |
| 29 | + ansible.builtin.command: |
| 30 | + argv: |
| 31 | + - oc |
| 32 | + - delete |
| 33 | + - "{{ item }}" |
| 34 | + - -n |
| 35 | + - openshift-machine-api |
| 36 | + - --wait=false |
| 37 | + environment: |
| 38 | + KUBECONFIG: "{{ kubeconfig }}" |
| 39 | + loop: "{{ bogus_machinesets_cmd.stdout_lines | default([]) }}" |
| 40 | + loop_control: |
| 41 | + label: "{{ item }}" |
| 42 | + register: bogus_ms_delete |
| 43 | + changed_when: bogus_ms_delete.rc == 0 |
| 44 | + failed_when: false |
| 45 | + when: bogus_machinesets_cmd.stdout_lines | default([]) | length > 0 |
| 46 | + |
| 47 | +- name: Delete leftover bogus Machines |
| 48 | + ansible.builtin.command: |
| 49 | + argv: |
| 50 | + - oc |
| 51 | + - delete |
| 52 | + - "{{ item }}" |
| 53 | + - -n |
| 54 | + - openshift-machine-api |
| 55 | + - --wait=false |
| 56 | + environment: |
| 57 | + KUBECONFIG: "{{ kubeconfig }}" |
| 58 | + loop: "{{ bogus_machines_cmd.stdout_lines | default([]) }}" |
| 59 | + loop_control: |
| 60 | + label: "{{ item }}" |
| 61 | + register: bogus_machine_delete |
| 62 | + changed_when: bogus_machine_delete.rc == 0 |
| 63 | + failed_when: false |
| 64 | + when: bogus_machines_cmd.stdout_lines | default([]) | length > 0 |
| 65 | + |
| 66 | +# Deletes used --wait=false; poll until matching objects are gone so openstack_test |
| 67 | +# does not start while bogus-* resources are still terminating. Bounded timeout. |
| 68 | +# Fail when leftovers remain after the timeout so openstack_test cannot start dirty. |
| 69 | +- name: Wait until bogus Machines and MachineSets are gone |
| 70 | + ansible.builtin.shell: | |
| 71 | + set -o pipefail |
| 72 | + ms=$(oc get machineset -n openshift-machine-api -o name 2>/dev/null | grep -E 'bogus-' || true) |
| 73 | + m=$(oc get machine -n openshift-machine-api -o name 2>/dev/null | grep -E 'bogus-' || true) |
| 74 | + if [ -n "$ms" ] || [ -n "$m" ]; then |
| 75 | + echo "bogus leftovers still present:" |
| 76 | + printf '%s\n' "$ms" "$m" | sed '/^$/d' |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | + echo "no bogus Machines or MachineSets remain" |
| 80 | + exit 0 |
| 81 | + environment: |
| 82 | + KUBECONFIG: "{{ kubeconfig }}" |
| 83 | + register: bogus_gone |
| 84 | + until: bogus_gone.rc == 0 |
| 85 | + retries: 30 |
| 86 | + delay: 10 |
| 87 | + changed_when: false |
| 88 | + when: >- |
| 89 | + (bogus_machinesets_cmd.stdout_lines | default([]) | length > 0) |
| 90 | + or (bogus_machines_cmd.stdout_lines | default([]) | length > 0) |
0 commit comments