-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup role for tripleo services #649
Merged
openshift-merge-bot
merged 1 commit into
openstack-k8s-operators:main
from
jpodivin:cleanup-role
May 23, 2024
+317
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
========================== | ||
Playbook - tripleo_cleanup | ||
========================== | ||
|
||
Stops and disables all tripleo services running on target hosts. | ||
Heuristic based on systemd unit name pattern matching is used to determine | ||
which services should be stopped and disabled. | ||
|
||
.. literalinclude:: ../../../playbooks/tripleo_cleanup.yml | ||
:language: YAML |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
================================ | ||
Role - edpm_tripleo_cleanup | ||
================================ | ||
|
||
Role stops and disables all systemd units enumerated to it. | ||
If the role doesn't recieve list of services, it will instead stop and disable | ||
all units containing string "tripleo" in their name. | ||
|
||
This way we can effectivelly prevent any leftovers of original tripleo based | ||
deployment from interfering with post-adoption setup. | ||
|
||
.. include:: | ||
../collections/osp/edpm/edpm_tripleo_cleanup_role.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
# Copyright 2024 Red Hat, Inc. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
|
||
- name: Cleanup Tripleo services | ||
hosts: "{{ edpm_override_hosts | default('all', true) }}" | ||
strategy: linear | ||
gather_facts: true | ||
any_errors_fatal: "{{ edpm_any_errors_fatal | default(true) }}" | ||
max_fail_percentage: "{{ edpm_max_fail_percentage | default(0) }}" | ||
tasks: | ||
- name: Stop and disable Tripleo services | ||
ansible.builtin.import_role: | ||
name: osp.edpm.edpm_tripleo_cleanup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
# Copyright 2024 Red Hat, Inc. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
|
||
# All variables intended for modification should be placed in this file. | ||
|
||
edpm_old_tripleo_services: [] | ||
|
||
# Remove unit files | ||
edpm_remove_tripleo_unit_files: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
# Copyright 2024 Red Hat, Inc. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
argument_specs: | ||
# roles/edpm_tripleo_cleanup/tasks/main.yml entry point | ||
main: | ||
short_description: The main entry point for the edpm_tripleo_cleanup role. | ||
options: | ||
edpm_old_tripleo_services: | ||
type: "list" | ||
description: | | ||
List of tripleo services to be disabled and stopped. | ||
If the list is empty, all services containing string 'tripleo' | ||
in their names will be disabled, stopped and masked. | ||
default: [] | ||
edpm_remove_tripleo_unit_files: | ||
type: "bool" | ||
description: | | ||
Remove unit files after disabling services. | ||
This operation is irreversible. Furthermore, issues may occur, | ||
if the unit files are managed by package manager. | ||
default: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
# Copyright 2024 Red Hat, Inc. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
|
||
galaxy_info: | ||
namespace: openstack | ||
author: OpenStack | ||
description: EDPM OpenStack Role -- edpm_tripleo_cleanup | ||
company: Red Hat | ||
license: Apache-2.0 | ||
min_ansible_version: '2.9' | ||
# | ||
# Provide a list of supported platforms, and for each platform a list of versions. | ||
# If you don't wish to enumerate all versions for a particular platform, use 'all'. | ||
# To view available platforms and versions (or releases), visit: | ||
# https://galaxy.ansible.com/api/v1/platforms/ | ||
# | ||
platforms: | ||
- name: 'EL' | ||
versions: | ||
- '8' | ||
- '9' | ||
|
||
galaxy_tags: | ||
- edpm | ||
|
||
|
||
# List your role dependencies here, one per line. Be sure to remove the '[]' above, | ||
# if you add dependencies to this list. | ||
dependencies: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
collections: | ||
- name: community.general |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
roles: | ||
- role: "osp.edpm.edpm_tripleo_cleanup" | ||
vars: | ||
edpm_old_tripleo_services: | ||
- fake-tripleo-service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
dependency: | ||
name: galaxy | ||
driver: | ||
name: delegated | ||
options: | ||
managed: false | ||
ansible_connection_options: | ||
ansible_connection: local | ||
platforms: | ||
- name: compute-1 | ||
groups: | ||
- compute | ||
provisioner: | ||
name: ansible | ||
inventory: | ||
hosts: | ||
all: | ||
hosts: | ||
compute-1: | ||
ctlplane_ip: 10.0.0.3 | ||
canonical_hostname: edpm-0.localdomain | ||
verifier: | ||
name: ansible | ||
scenario: | ||
test_sequence: | ||
- destroy | ||
- create | ||
- prepare | ||
- converge | ||
- verify | ||
- destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
# Copyright 2024 Red Hat, Inc. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
- name: Prepare test_deps | ||
hosts: all | ||
roles: | ||
- role: ../../../../molecule/common/test_deps | ||
test_deps_extra_packages: | ||
- podman | ||
tasks: | ||
- name: Create mock service | ||
become: true | ||
ansible.builtin.copy: | ||
src: "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}/test-data/fake-tripleo-service.service" | ||
dest: /usr/lib/systemd/system/fake-tripleo-service.service | ||
mode: '0644' | ||
|
||
- name: Enable mock service | ||
become: true | ||
ansible.builtin.systemd_service: | ||
name: fake-tripleo-service | ||
enabled: true | ||
|
||
- name: Start mock service | ||
become: true | ||
ansible.builtin.systemd_service: | ||
name: fake-tripleo-service | ||
state: started |
8 changes: 8 additions & 0 deletions
8
roles/edpm_tripleo_cleanup/molecule/default/test-data/fake-tripleo-service.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[Unit] | ||
Description=Fake tripleo service | ||
|
||
[Service] | ||
ExecStart=/usr/bin/true | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
- name: Verify | ||
hosts: all | ||
tasks: | ||
- name: Check if unit file exists and fail if it does | ||
ansible.builtin.file: | ||
path: /usr/lib/systemd/system/fake-tripleo-service.service | ||
state: absent | ||
check_mode: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
# Copyright 2024 Red Hat, Inc. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
- name: Reload units to check for new changes | ||
tags: | ||
- adoption | ||
become: true | ||
ansible.builtin.systemd_service: | ||
daemon_reload: true | ||
|
||
- name: Set list of tripleo services | ||
tags: | ||
- adoption | ||
ansible.builtin.set_fact: | ||
tripleo_services: "{{ edpm_old_tripleo_services }}" | ||
|
||
- name: Discover tripleo services | ||
tags: | ||
- adoption | ||
when: tripleo_services | length == 0 | ||
block: | ||
- name: Get all services | ||
ansible.builtin.service_facts: | ||
- name: Filter for tripleo services | ||
ansible.builtin.set_fact: | ||
tripleo_services: "{{ ansible_facts.services.keys() | select('contains', 'tripleo') }}" | ||
|
||
- name: Stop and disable tripleo services | ||
tags: | ||
- adoption | ||
become: true | ||
ansible.builtin.systemd_service: | ||
name: "{{ item }}" | ||
state: stopped | ||
enabled: false | ||
masked: true | ||
loop: "{{ tripleo_services }}" | ||
jpodivin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: Remove unit files | ||
tags: | ||
- adoption | ||
become: true | ||
ansible.builtin.file: | ||
path: /usr/lib/systemd/system/{{ item }}.service | ||
state: absent | ||
loop: "{{ tripleo_services }}" | ||
when: edpm_remove_tripleo_unit_files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in two minds about this one. where do we draw the cleanup line? It is one thing to stop the service it is another to cleanup files/packages etc. (yes I realise you're not removing packages here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point I don't really care much either way. The cleanup procedure can be adjusted, or left with defaults. One way or another, given the number of files involving tripleo, we are going to miss something. After all, we have been adopting without cleanup up until now.
What is critical, is that no tripleo processes are running, or can spontaneously start up after adoption. As that could cause damage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think when we start doing operations on the data plane we are already beyond "point of no return" in terms of rollback so i don't think we'd be reinstating the old services. But i think it's nice that there is a variable to control the removal, thanks.