Skip to content

Commit a79682a

Browse files
tjmoore4Jonathan S. Katz
authored andcommitted
Preserve cluster-level resources in a multi-Operator environment
Currently, uninstalling an instance of the PostgreSQL Operator from one namespace will remove all Kubernetes/Openshift cluster- level resources as well. This impairs the functionality of any other Operators that may be installed. This update adds a check to see if there are any other PostgreSQL Operators installed on the cluster and, if so, adds a flag to skip the removal of cluster-level resources. Issue: [ch9389]
1 parent 29686f4 commit a79682a

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

installers/ansible/roles/pgo-operator/tasks/cleanup.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66
- uninstall
77
- update
88

9+
- name: Get number of Operator instances in this cluster
10+
shell: |
11+
{{ kubectl_or_oc }} get deployment --field-selector=metadata.name=postgres-operator --selector=vendor=crunchydata --all-namespaces -o name | wc -l
12+
register: num_operators
13+
tags:
14+
- uninstall
15+
- update
16+
17+
- name: Set boolean for multi-operator environment
18+
set_fact: multi_operator_env="{{ 'true' if num_operators.stdout | int > 1 else 'false' }}"
19+
tags:
20+
- uninstall
21+
- update
22+
923
- name: Find watched namespaces
1024
shell: |
1125
{{ kubectl_or_oc }} get namespaces -o json --selector=vendor=crunchydata,pgo-installation-name={{ pgo_installation_name }}
@@ -152,7 +166,8 @@
152166
tags:
153167
- uninstall
154168
- update
155-
when: create_rbac|bool
169+
when: not multi_operator_env|bool and
170+
create_rbac|bool
156171

157172
- name: Delete cluster-admin Cluster Role Binding for PGO Service Account
158173
command: "{{ kubectl_or_oc }} delete clusterrolebinding pgo-cluster-admin"
@@ -161,7 +176,8 @@
161176
tags:
162177
- uninstall
163178
- update
164-
when: create_rbac|bool
179+
when: not multi_operator_env|bool and
180+
create_rbac|bool
165181

166182
- name: Delete existing Cluster Roles
167183
shell: |
@@ -173,7 +189,8 @@
173189
tags:
174190
- uninstall
175191
- update
176-
when: create_rbac|bool
192+
when: not multi_operator_env|bool and
193+
create_rbac|bool
177194

178195
- name: Delete existing PGO Role Bindings (Watched Namespaces)
179196
shell: |
@@ -233,6 +250,7 @@
233250
pgpolicies.crunchydata.com pgreplicas.crunchydata.com pgtasks.crunchydata.com
234251
ignore_errors: yes
235252
no_log: false
253+
when: not multi_operator_env|bool
236254
tags: uninstall
237255

238256
- name: Remove Labels from Watched Namespaces
@@ -276,7 +294,8 @@
276294
file:
277295
state: absent
278296
path: "/usr/local/bin/pgo"
279-
when: pgo_client_install == "true"
297+
when: pgo_client_install == "true" and
298+
not multi_operator_env|bool
280299
ignore_errors: yes
281300
no_log: false
282301
tags: uninstall

0 commit comments

Comments
 (0)