Skip to content

Commit cdb7864

Browse files
committed
Enhance cleanup_openstack for infrastructure reuse
Enable OpenStack cleanup while preserving cluster infrastructure for faster CI test cycles without full reprovisioning between runs. Fixes critical bugs: - Undefined variables (cifmw_basedir, kubeconfig) - Inconsistent kubeconfig usage across tasks - Missing result checks before accessing module outputs - Dry-run mode bypasses and variable scope issues - Infrastructure operators deletion (preserved for reuse) Adds production features: - Dry-run mode and selective cleanup via tags - Comprehensive cleanup summary and verification - Self-contained role with proper fallback chains New task files: cleanup_crs_direct, cleanup_openstack_api, cleanup_storage, cleanup_namespaces, common. New playbook: cleanup-openstack-for-reuse.yml. Includes documentation and Ansible Galaxy metadata. Assisted-By: claude-4.5-sonnet Closes: OSPRH-21759 Signed-off-by: Roberto Alfieri <[email protected]>
1 parent ff8eb72 commit cdb7864

File tree

14 files changed

+1293
-29
lines changed

14 files changed

+1293
-29
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
# Copyright Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
# This playbook cleans only config drive ISO files to allow infrastructure reuse.
18+
# It does NOT clean libvirt VMs or other resources - only config drives.
19+
# This is needed when reusing infrastructure to avoid conflicts with existing
20+
# ISO files that might be attached to VMs.
21+
22+
- name: Clean config drives for infrastructure reuse
23+
hosts: "{{ cifmw_target_host | default('localhost') }}"
24+
gather_facts: true
25+
tasks:
26+
- name: Cleanup config_drive workdir
27+
ansible.builtin.include_role:
28+
name: config_drive
29+
tasks_from: cleanup.yml
30+
31+
- name: Remove ISO files from workload directory
32+
when: cifmw_libvirt_manager_basedir is defined
33+
ansible.builtin.find:
34+
paths: "{{ cifmw_libvirt_manager_basedir }}/workload"
35+
patterns: "*.iso"
36+
register: _iso_files
37+
failed_when: false
38+
39+
- name: Delete ISO files from workload directory
40+
when:
41+
- cifmw_libvirt_manager_basedir is defined
42+
- _iso_files.files | default([]) | length > 0
43+
ansible.builtin.file:
44+
path: "{{ item.path }}"
45+
state: absent
46+
loop: "{{ _iso_files.files | default([]) }}"
47+
failed_when: false
48+
# Note: This may fail if ISO is attached to a running VM, but that's okay
49+
# The config_drive role will handle the case where ISO doesn't exist

cleanup-openstack-for-reuse.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
# Copyright Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
# This playbook cleans up OpenStack resources while preserving the OpenShift
18+
# cluster infrastructure for reuse. It removes:
19+
# - All OpenStack CRs (ControlPlane, DataPlane, etc.)
20+
# - Storage resources (PVCs, secrets, ConfigMaps)
21+
# - Optionally: OpenStack API resources (servers, networks, volumes, etc.)
22+
#
23+
# Usage examples:
24+
#
25+
# Basic cleanup (removes OpenStack CRs and storage, keeps cluster):
26+
# ansible-playbook -i inventory.yml cleanup-openstack-for-reuse.yml
27+
#
28+
# Dry-run mode (preview what would be deleted):
29+
# ansible-playbook -i inventory.yml cleanup-openstack-for-reuse.yml \
30+
# -e dry_run=true
31+
#
32+
# Skip API resource cleanup (if needed):
33+
# ansible-playbook -i inventory.yml cleanup-openstack-for-reuse.yml \
34+
# -e cleanup_api_resources=false
35+
#
36+
# Selective cleanup using tags:
37+
# ansible-playbook -i inventory.yml cleanup-openstack-for-reuse.yml \
38+
# --tags cleanup_storage,cleanup_crs_direct
39+
#
40+
# Aggressive cleanup (removes everything including namespaces):
41+
# ansible-playbook -i inventory.yml cleanup-openstack-for-reuse.yml \
42+
# -e cleanup_api_resources=true \
43+
# -e cleanup_namespaces=true \
44+
# -e force_remove_finalizers=true
45+
46+
- name: Clean OpenStack deployment for infrastructure reuse
47+
hosts: "{{ target_host | default('localhost') }}"
48+
gather_facts: true
49+
vars:
50+
# Dry-run mode - preview without making changes
51+
cifmw_cleanup_openstack_dry_run: "{{ dry_run | default(false) }}"
52+
# By default, clean OpenStack CRs, storage, and API resources but keep OpenShift cluster
53+
# Set to false to skip OpenStack API resource cleanup
54+
cifmw_cleanup_openstack_delete_api_resources: "{{ cleanup_api_resources | default(true) }}"
55+
# Set to true to delete namespaces (use with caution)
56+
cifmw_cleanup_openstack_delete_namespaces: "{{ cleanup_namespaces | default(false) }}"
57+
# Set to true to force remove finalizers from stuck CRs
58+
cifmw_cleanup_openstack_force_remove_finalizers: "{{ force_remove_finalizers | default(false) }}"
59+
tasks:
60+
- name: Cleanup OpenStack deployment
61+
ansible.builtin.include_role:
62+
name: cleanup_openstack
63+
64+
- name: Verify cleanup succeeded (if not dry-run)
65+
when: not cifmw_cleanup_openstack_dry_run | bool
66+
block:
67+
- name: Verify OpenStackControlPlane CRs are removed
68+
kubernetes.core.k8s_info:
69+
kubeconfig: "{{ _k8s_kubeconfig | default(omit) }}"
70+
api_key: "{{ cifmw_openshift_token | default(omit) }}"
71+
context: "{{ cifmw_openshift_context | default(omit) }}"
72+
api_version: core.openstack.org/v1beta1
73+
kind: OpenStackControlPlane
74+
namespace: "{{ cifmw_kustomize_deploy_namespace | default('openstack') }}"
75+
register: _verify_controlplane
76+
failed_when: false
77+
78+
- name: Verify OpenStackDataPlaneNodeSet CRs are removed
79+
kubernetes.core.k8s_info:
80+
kubeconfig: "{{ _k8s_kubeconfig | default(omit) }}"
81+
api_key: "{{ cifmw_openshift_token | default(omit) }}"
82+
context: "{{ cifmw_openshift_context | default(omit) }}"
83+
api_version: dataplane.openstack.org/v1beta1
84+
kind: OpenStackDataPlaneNodeSet
85+
namespace: "{{ cifmw_kustomize_deploy_namespace | default('openstack') }}"
86+
register: _verify_nodeset
87+
failed_when: false
88+
89+
- name: Display verification results
90+
ansible.builtin.debug:
91+
msg: |
92+
╔══════════════════════════════════════════════════════════════════╗
93+
║ Cleanup Verification ║
94+
╚══════════════════════════════════════════════════════════════════╝
95+
96+
✓ OpenStackControlPlane CRs: {{ (_verify_controlplane.resources | default([]) | length == 0) | ternary('✓ Removed', '✗ Still present (' + (_verify_controlplane.resources | default([]) | length | string) + ')') }}
97+
✓ OpenStackDataPlaneNodeSet CRs: {{ (_verify_nodeset.resources | default([]) | length == 0) | ternary('✓ Removed', '✗ Still present (' + (_verify_nodeset.resources | default([]) | length | string) + ')') }}
98+
99+
{% if (_verify_controlplane.resources | default([]) | length > 0) or (_verify_nodeset.resources | default([]) | length > 0) %}
100+
⚠ Warning: Some CRs were not fully removed. Consider:
101+
- Running cleanup again
102+
- Using -e force_remove_finalizers=true
103+
- Manually investigating stuck resources
104+
{% else %}
105+
═══════════════════════════════════════════════════════════════════
106+
✓ Cleanup verified successfully! Cluster ready for reuse.
107+
═══════════════════════════════════════════════════════════════════
108+
{% endif %}

docs/dictionary/en-custom.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ buildah
5555
buildpkgs
5656
cacert
5757
cacheable
58+
certmanager
5859
catalogsource
5960
cci
6061
ccitredhat
@@ -138,6 +139,7 @@ deepscrub
138139
delorean
139140
deployer
140141
deprovision
142+
deprovisioned
141143
deps
142144
dest
143145
dev
@@ -185,6 +187,7 @@ extraRPMs
185187
ezzmy
186188
favorit
187189
fbqufbqkfbzxrja
190+
finalizers
188191
fci
189192
fdp
190193
fedoraproject
@@ -299,6 +302,7 @@ kvm
299302
lacp
300303
lajly
301304
LDAP
305+
Lifecycle
302306
ldp
303307
libguestfs
304308
libvirt
@@ -415,8 +419,12 @@ openstack
415419
openstackclient
416420
openstackcontrolplane
417421
openstackdataplane
422+
openstackdataplanedeployment
423+
OpenStackDataPlaneDeployment
418424
openstackdataplanenodeset
419425
openstackdataplanenodesets
426+
openstackdataplaneservice
427+
OpenStackDataPlaneService
420428
openstackprovisioner
421429
openstacksdk
422430
openstackversion
@@ -443,6 +451,8 @@ passwd
443451
passwordless
444452
pastebin
445453
pem
454+
persistentvolumes
455+
PersistentVolumes
446456
pkgs
447457
pki
448458
png
@@ -468,6 +478,7 @@ pubkey
468478
publicdomain
469479
pullsecret
470480
pvs
481+
PVCs
471482
pwd
472483
pxe
473484
py
@@ -491,6 +502,7 @@ readmes
491502
readthedocs
492503
reauthenticate
493504
rebaser
505+
reusability
494506
redfish
495507
redhat
496508
refspec

0 commit comments

Comments
 (0)