|
104 | 104 | dest: "{{ capi_cluster_kubeconfig_path }}" |
105 | 105 | mode: u=rw,g=,o= |
106 | 106 |
|
107 | | -- name: Including token-based kubeconfig tasks to generate token-based kubeconfig |
108 | | - when: capi_cluster_service_account_enabled |
109 | | - environment: |
110 | | - KUBECONFIG: "{{ capi_cluster_kubeconfig_path }}" |
111 | | - block: |
112 | | - - name: Include token-based kubeconfig task file |
113 | | - ansible.builtin.include_tasks: capi-cluster-service-account.yml |
| 107 | + - name: Including token-based kubeconfig tasks to generate token-based kubeconfig |
| 108 | + when: capi_cluster_service_account_enabled |
| 109 | + environment: |
| 110 | + KUBECONFIG: "{{ capi_cluster_kubeconfig_path }}" |
| 111 | + block: |
| 112 | + - name: Include token-based kubeconfig task file |
| 113 | + ansible.builtin.include_tasks: capi-cluster-service-account.yml |
114 | 114 |
|
| 115 | +- name: Check that the cluster exists |
| 116 | + ansible.builtin.command: >- |
| 117 | + kubectl get |
| 118 | + openstackclusters.infrastructure.cluster.x-k8s.io |
| 119 | + -n {{ capi_cluster_release_namespace }} |
| 120 | + {{ capi_cluster_release_name }} |
| 121 | + --ignore-not-found true |
| 122 | + -o json |
| 123 | + changed_when: false |
| 124 | + register: cluster_check |
| 125 | + when: capi_cluster_release_state == 'absent' |
115 | 126 |
|
116 | | -- name: Delete CAPI cluster |
| 127 | +- name: Set fact from cluster check |
| 128 | + ansible.builtin.set_fact: |
| 129 | + cluster_details: "{{ cluster_check.stdout | from_json if cluster_check.stdout != '' else {} }}" |
| 130 | + changed_when: false |
117 | 131 | when: capi_cluster_release_state == 'absent' |
| 132 | + |
| 133 | +- name: Delete CAPI cluster |
| 134 | + when: |
| 135 | + - capi_cluster_release_state == 'absent' |
| 136 | + - cluster_details != {} |
| 137 | + - cluster_details['items'] | length == 1 |
118 | 138 | block: |
119 | 139 | # Before deleting the cluster, update the annotation that indicates if volumes should be kept |
120 | 140 | - name: Set volumes policy annotation |
|
0 commit comments