Skip to content

Commit b319479

Browse files
committed
Add service cleanup automation
This PR implements the service cleanup functionality with an edpm_cleanup role. - edpm_container_standalone creates a state file to keep track of deployed services on the nodes - Containers for services not in service list of nodeset would be cleaned by adding cleanup service to the nodeset services list or a new deployment with cleanup in 'servicesOverride' - If a service drops a container it would be automatically cleaned up - Service cleanup will also remove containers, startup_config and other config files along with running the specific cleanup tasks provided in cleanup.yaml of a role jira: https://issues.redhat.com/browse/OSPRH-19243 Assisted-by: claude-4-sonnet Signed-off-by: rabi <[email protected]>
1 parent c06fbf5 commit b319479

File tree

35 files changed

+1727
-45
lines changed

35 files changed

+1727
-45
lines changed

docs/source/roles/role-edpm_container_manage.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ overrides the image setting in one-off.
143143
edpm_container_manage_config_patterns: 'haproxy.json'
144144
edpm_container_manage_config: "/var/lib/edpm-config/container-startup-config/step_1"
145145
edpm_container_manage_config_id: "edpm_step1"
146-
edpm_container_manage_clean_orphans: false
147146
edpm_container_manage_config_overrides:
148147
haproxy:
149148
image: quay.io/edpmmastercentos9/centos-binary-haproxy:hotfix
@@ -164,10 +163,11 @@ containers by Ansible.
164163
165164
$ ansible-playbook haproxy.yaml --check --diff
166165
167-
The ``edpm_container_manage_clean_orphans`` parameter is optional
168-
and can be set to `false` to not clean orphaned containers for a
169-
config_id. It can be used to manage a single container without
170-
impacting other running containers with same config_id.
166+
.. warning::
167+
168+
The ``edpm_container_manage_clean_orphans`` parameter is **deprecated** and will be removed in a future release.
169+
While it still functions, users should migrate to using ``edpm_cleanup_orphaned_containers`` in the
170+
``edpm_container_standalone`` role instead, which provides better state-file aware orphan cleanup.
171171

172172
The ``edpm_container_manage_config_overrides`` parameter is optional
173173
and can be used to override a specific container attribute like the image

playbooks/cleanup.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
# Copyright 2025 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+
- name: Cleanup EDPM Services
18+
hosts: "{{ edpm_override_hosts | default('all', true) }}"
19+
strategy: linear
20+
gather_facts: "{{ gather_facts | default(false) }}"
21+
any_errors_fatal: "{{ edpm_any_errors_fatal | default(true) }}"
22+
max_fail_percentage: "{{ edpm_max_fail_percentage | default(0) }}"
23+
environment: "{{ edpm_playbook_environment | default({}) }}"
24+
tasks:
25+
- name: Display cleanup information
26+
ansible.builtin.debug:
27+
msg:
28+
- "=========================================="
29+
- "Services to keep (from edpm_service_types):"
30+
- "{{ edpm_service_types | default([]) | join(', ') }}"
31+
- "=========================================="
32+
- "This will clean up all services NOT in edpm_service_types:"
33+
- " - Stop and disable systemd services"
34+
- " - Remove containers"
35+
- " - Remove configuration directories"
36+
- " - Update state file"
37+
- "=========================================="
38+
39+
- name: Cleanup services
40+
ansible.builtin.include_role:
41+
name: osp.edpm.edpm_cleanup

playbooks/nova.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
- name: Deploy EDPM Nova storage infrastructure
44
ansible.builtin.import_playbook: nova_storage.yml
5+
vars:
6+
edpm_service_name: nova
7+
58
- name: Deploy EDPM Nova
69
hosts: "{{ edpm_override_hosts | default('all', true) }}"
710
strategy: linear

plugins/filter/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def needs_delete(self, container_infos, config, config_id,
4141
:param container_infos: list
4242
:param config: dict
4343
:param config_id: string
44-
:param clean_orphans: bool
44+
:param clean_orphans: bool (DEPRECATED - use edpm_cleanup_orphaned_containers instead)
4545
:param check_config: bool to whether or not check if config changed
4646
:returns: list
4747
"""

plugins/filter/needs_delete.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

plugins/modules/edpm_container_manage.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@
8181
- Number of podman actions to run at the same time
8282
type: int
8383
default: 1
84+
containers:
85+
description:
86+
- List of specific container names to manage
87+
- If empty, all containers matching the pattern will be managed
88+
type: list
89+
elements: str
90+
default: []
8491
debug:
8592
description:
8693
- Enable debug
@@ -127,6 +134,7 @@ def __init__(self, module, results):
127134
self.config_dir = args.get('config_dir')
128135
self.config_patterns = args.get('config_patterns')
129136
self.config_overrides = args['config_overrides']
137+
self.containers = args.get('containers', [])
130138
self.log_base_path = args.get('log_base_path')
131139
self.debug = args.get('debug')
132140

@@ -155,6 +163,11 @@ def _get_configs(self):
155163
self.config_patterns))
156164
for match in matches:
157165
name = os.path.splitext(os.path.basename(match))[0]
166+
# Skip if specific containers list provided and this isn't in it
167+
if self.containers and name not in self.containers:
168+
if self.debug:
169+
self.module.debug(f'Skipping {name} - not in containers list')
170+
continue
158171
with open(match, 'r') as data:
159172
config = json.loads(data.read())
160173
if self.debug:

0 commit comments

Comments
 (0)