-
Notifications
You must be signed in to change notification settings - Fork 18
/
cleanup.yaml
158 lines (136 loc) · 4.1 KB
/
cleanup.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
- name: Prepare for cleanup
hosts: osbs_box_host
tags:
- always
tasks:
- name: Try to log in as openshift admin
command: oc login -u system:admin
register: oc_login
changed_when: oc_login.rc == 0
# If login failed, cluster is probably down - that means steps which use
# `oc` must be skipped, but otherwise, cleanup can proceed as usual
ignore_errors: true
- name: Delete koji
hosts: osbs_box_host
gather_facts: false
tags:
- koji
# All tags related to koji PVs (deleting PVs while in use is a bad idea)
- pvs
- koji_pvs
- koji_db_pv
- koji_files_pv
# One tag to rule them all
- everything
tasks:
- name: Delete koji namespace from openshift
command: oc delete namespace "{{ koji_namespace }}"
register: delete_koji_namespace
changed_when: delete_koji_namespace.rc == 0
failed_when: delete_koji_namespace.rc != 0 and
'not found' not in delete_koji_namespace.stderr
when: not oc_login.failed
- name: Delete koji PVs from openshift
command: oc delete pv --selector volume=koji-volume
register: delete_koji_pvs
changed_when: delete_koji_pvs.rc == 0 and
delete_koji_pvs.stdout != 'No resources found'
failed_when: delete_koji_pvs.rc != 0
when: not oc_login.failed
- name: Delete docker registry
hosts: osbs_box_host
gather_facts: false
tags:
- registry
- pvs
- registry_pv
- everything
tasks:
- name: Delete registry namespace from openshift
command: oc delete namespace "{{ registry_namespace }}"
register: delete_registry_namespace
changed_when: delete_registry_namespace.rc == 0
failed_when: delete_registry_namespace.rc != 0 and
'not found' not in delete_registry_namespace.stderr
when: not oc_login.failed
- name: Delete registry PV from openshift
command: oc delete pv registry-data
register: delete_registry_pv
changed_when: delete_registry_pv.rc == 0
failed_when: delete_registry_pv.rc != 0 and
'not found' not in delete_registry_pv.stderr
when: not oc_login.failed
- name: Delete OSBS orchestrator and worker namespaces
hosts: osbs_box_host
gather_facts: false
tags:
- namespaces
- everything
tasks:
- name: Delete orchestrator and worker namespaces from openshift
command: oc delete namespace "{{ item }}"
register: delete_osbs_namespace
changed_when: delete_osbs_namespace.rc == 0
failed_when: delete_osbs_namespace.rc != 0 and
'not found' not in delete_osbs_namespace.stderr
loop:
- "{{ orchestrator_namespace }}"
- "{{ worker_namespace }}"
when: not oc_login.failed
- name: Delete persistent volume data
hosts: osbs_box_host
gather_facts: false
become: true
tags:
- never
- pvs
- everything
tasks:
- name: Delete koji-db-data PV directory
file:
path: "{{ koji_db_data_dir }}"
state: absent
tags:
- koji_pvs
- koji_db_pv
- name: Delete koji-files PV directory
file:
path: "{{ koji_files_dir }}"
state: absent
tags:
- koji_pvs
- koji_files_pv
- name: Delete registry-data PV directory
file:
path: "{{ registry_data_dir }}"
state: absent
tags:
- registry_pv
- name: Delete remaining OSBS-Box data
hosts: osbs_box_host
gather_facts: false
tags:
- never
- everything
tasks:
- name: Delete certificate directories
file:
path: "{{ item }}"
state: absent
loop:
- "{{ koji_certs_dir }}"
- "{{ registry_certs_dir }}"
- "{{ certificates_dir }}"
tags:
- certificates
- name: Delete openshift files directory
file:
path: "{{ openshift_files }}"
state: absent
tags:
- openshift_files
- name: Delete OSBS-Box data directory
# At this point, it should only contain empty directories (if anything)
file:
path: "{{ osbs_box_data_dir }}"
state: absent