Skip to content

Commit 7325246

Browse files
committed
Remove pvcs still bound before deleting pvs
1 parent 6506ba0 commit 7325246

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

roles/ci_local_storage/tasks/cleanup.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,31 @@
2424
- provisioned-by={{ cifmw_cls_storage_provisioner }}
2525
register: _pv_info
2626

27-
- name: Export PVs as facts
27+
- name: Export PVs and Bound PVCs as facts
2828
ansible.builtin.set_fact:
2929
cifmw_cls_pvs: >-
3030
{{ _pv_info.resources |
3131
selectattr("metadata.name", "defined") |
3232
map(attribute="metadata.name")
3333
}}
34+
cifmw_cls_pvcs: >-
35+
{{ _pv_info.resources |
36+
selectattr("status.phase", "equalto", "Bound") |
37+
selectattr("spec.claimRef", "defined") |
38+
map(attribute="spec.claimRef")
39+
}}
40+
41+
- name: Delete all bound pvcs
42+
kubernetes.core.k8s:
43+
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
44+
api_key: "{{ cifmw_openshift_token | default(omit)}}"
45+
context: "{{ cifmw_openshift_context | default(omit)}}"
46+
kind: PersistentVolumeClaim
47+
state: absent
48+
api_version: v1
49+
namespace: "{{ item.namespace }}"
50+
name: "{{ item.name }}"
51+
loop: "{{ cifmw_cls_pvcs }}"
3452

3553
- name: Delete all pvs
3654
kubernetes.core.k8s:

0 commit comments

Comments
 (0)