Skip to content

Commit f786a36

Browse files
mnietojiclaude
authored andcommitted
[cleanup_openstack] Fix namespace stuck on cleanup by separating deletion phases
Split CRs deletion into two phases to prevent namespace getting stuck during cleanup: - Phase 1: Delete application resources (DataPlane, ControlPlane, BMH, etc.) - Phase 2: Delete operators (NMState, MetalLB, OpenStack operators, OLM) - Wait between phases to ensure Phase 1 resources are fully deleted Each resource type (DataPlaneDeployment, DataPlaneNodeSet, ControlPlane, RabbitmqCluster) is waited on individually in dependency order. If a resource gets stuck, its finalizers are force-removed before moving to the next type. This replaces the previous RabbitmqCluster-specific workaround with a generic mechanism. This prevents race condition where operator controller is deleted before it can process finalizers from application resources, which causes the namespace to hang indefinitely. Signed-off-by: Miguel Angel Nieto Jimenez <mnietoji@redhat.com> Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 07ed6cb commit f786a36

2 files changed

Lines changed: 62 additions & 35 deletions

File tree

roles/cleanup_openstack/tasks/main.yaml

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,7 @@
5151
ansible.builtin.import_tasks: detach_bmh.yaml
5252
when: cifmw_cleanup_openstack_detach_bmh
5353

54-
- name: Work around for stale rabbit cluster deletion
55-
block:
56-
- name: Check if rabbitmq-cell1 exists
57-
kubernetes.core.k8s_info:
58-
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
59-
api_key: "{{ cifmw_openshift_token | default(omit) }}"
60-
context: "{{ cifmw_openshift_context | default(omit) }}"
61-
namespace: "{{ cifmw_openstack_namespace }}"
62-
kind: RabbitmqCluster
63-
name: rabbitmq-cell1
64-
register: rabbitmq_cell1_info
65-
failed_when: false
66-
67-
- name: Patch rabbitmq-cell1 finalizers
68-
kubernetes.core.k8s_json_patch:
69-
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
70-
api_key: "{{ cifmw_openshift_token | default(omit) }}"
71-
context: "{{ cifmw_openshift_context | default(omit) }}"
72-
namespace: "{{ cifmw_openstack_namespace }}"
73-
kind: RabbitmqCluster
74-
name: rabbitmq-cell1
75-
patch:
76-
- op: replace
77-
path: /metadata/finalizers
78-
value: []
79-
when: rabbitmq_cell1_info.resources | default([]) | length > 0
80-
81-
- name: Delete deployment CRs
54+
- name: Delete deployment CRs (Phase 1 - Application Resources)
8255
vars:
8356
_stages_crs: >-
8457
{{
@@ -99,11 +72,6 @@
9972
_external_dns_crs:
10073
- "{{ cifmw_manifests_dir }}/cifmw_external_dns/ceph-local-dns.yml"
10174
- "{{ cifmw_manifests_dir }}/cifmw_external_dns/ceph-local-cert.yml"
102-
_operators_crs:
103-
- "{{ cifmw_kustomize_deploy_nmstate_dest_file }}"
104-
- "{{ cifmw_kustomize_deploy_metallb_dest_file }}"
105-
- "{{ cifmw_kustomize_deploy_kustomizations_dest_dir }}/openstack.yaml"
106-
- "{{ cifmw_kustomize_deploy_olm_dest_file }}"
10775
_bmh_crs: >-
10876
{{
10977
bmh_crs.files |
@@ -121,11 +89,37 @@
12189
_external_dns_crs +
12290
_stages_crs_path +
12391
_bmh_crs +
124-
_bmh_secrets_crs +
125-
_operators_crs
92+
_bmh_secrets_crs
12693
}}
12794
ansible.builtin.import_tasks: cleanup_crs.yaml
12895

96+
- name: Ensure Phase 1 resources are removed before deleting operators
97+
ansible.builtin.include_tasks: wait_and_cleanup_resource.yaml
98+
loop:
99+
- kind: OpenStackDataPlaneDeployment
100+
api_version: dataplane.openstack.org/v1beta1
101+
- kind: OpenStackDataPlaneNodeSet
102+
api_version: dataplane.openstack.org/v1beta1
103+
- kind: OpenStackControlPlane
104+
api_version: core.openstack.org/v1beta1
105+
- kind: RabbitmqCluster
106+
api_version: rabbitmq.com/v1beta1
107+
loop_control:
108+
loop_var: cifmw_cleanup_resource
109+
vars:
110+
cifmw_cleanup_resource_kind: "{{ cifmw_cleanup_resource.kind }}"
111+
cifmw_cleanup_resource_api_version: "{{ cifmw_cleanup_resource.api_version }}"
112+
113+
- name: Delete deployment CRs (Phase 2 - Operators)
114+
vars:
115+
_operators_crs:
116+
- "{{ cifmw_kustomize_deploy_nmstate_dest_file }}"
117+
- "{{ cifmw_kustomize_deploy_metallb_dest_file }}"
118+
- "{{ cifmw_kustomize_deploy_kustomizations_dest_dir }}/openstack.yaml"
119+
- "{{ cifmw_kustomize_deploy_olm_dest_file }}"
120+
_crs_to_delete: "{{ _operators_crs }}"
121+
ansible.builtin.import_tasks: cleanup_crs.yaml
122+
129123
- name: Get artifacts scripts
130124
ansible.builtin.find:
131125
path: "{{ cifmw_kustomize_deploy_basedir }}/artifacts"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
- name: "Ensure resources are removed - {{ cifmw_cleanup_resource_kind }}"
3+
block:
4+
- name: "Wait for resource to be deleted - {{ cifmw_cleanup_resource_kind }}"
5+
kubernetes.core.k8s_info:
6+
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
7+
api_key: "{{ cifmw_openshift_token | default(omit) }}"
8+
context: "{{ cifmw_openshift_context | default(omit) }}"
9+
namespace: "{{ cifmw_openstack_namespace }}"
10+
kind: "{{ cifmw_cleanup_resource_kind }}"
11+
api_version: "{{ cifmw_cleanup_resource_api_version }}"
12+
register: cifmw_cleanup_resource_result
13+
until: cifmw_cleanup_resource_result.resources | default([]) | length == 0
14+
retries: 60
15+
delay: 10
16+
rescue:
17+
- name: "Force-remove finalizers from stuck resource - {{ cifmw_cleanup_resource_kind }}"
18+
kubernetes.core.k8s_json_patch:
19+
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
20+
api_key: "{{ cifmw_openshift_token | default(omit) }}"
21+
context: "{{ cifmw_openshift_context | default(omit) }}"
22+
namespace: "{{ cifmw_openstack_namespace }}"
23+
kind: "{{ cifmw_cleanup_resource_kind }}"
24+
api_version: "{{ cifmw_cleanup_resource_api_version }}"
25+
name: "{{ item.metadata.name }}"
26+
patch:
27+
- op: replace
28+
path: /metadata/finalizers
29+
value: []
30+
loop: "{{ cifmw_cleanup_resource_result.resources | default([]) }}"
31+
loop_control:
32+
label: "{{ item.metadata.name }}"
33+
failed_when: false

0 commit comments

Comments
 (0)