From 651a6a8ede9a1e1760cda9f988910013953c644e Mon Sep 17 00:00:00 2001 From: guppy0130 Date: Wed, 18 Sep 2024 18:42:36 -0500 Subject: [PATCH 1/2] implement reset for podman driver * when the podman driver runs the `create` playbook, we'll add a `owner=molecule` label to the containers we create * in `reset`, we'll delete containers (eventually everything?) that has the label `owner=molecule` --- src/molecule_plugins/podman/driver.py | 6 +++++- src/molecule_plugins/podman/playbooks/create.yml | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/molecule_plugins/podman/driver.py b/src/molecule_plugins/podman/driver.py index 99c39090..0091c6f6 100644 --- a/src/molecule_plugins/podman/driver.py +++ b/src/molecule_plugins/podman/driver.py @@ -30,7 +30,7 @@ from molecule import logger, util from molecule.api import Driver, MoleculeRuntimeWarning from molecule.constants import RC_SETUP_ERROR -from molecule.util import sysexit_with_message +from molecule.util import run_command, sysexit_with_message log = logger.get_logger(__name__) @@ -243,3 +243,7 @@ def sanity_checks(self): def required_collections(self) -> dict[str, str]: """Return collections dict containing names and versions required.""" return {"containers.podman": "1.7.0", "ansible.posix": "1.3.0"} + + def reset(self): + # keep `--filter` in sync with playbooks/create.yml + run_command(["podman", "rm", "--force", "--filter=owner=molecule"]) diff --git a/src/molecule_plugins/podman/playbooks/create.yml b/src/molecule_plugins/podman/playbooks/create.yml index 5bc92cd9..7d667ab8 100644 --- a/src/molecule_plugins/podman/playbooks/create.yml +++ b/src/molecule_plugins/podman/playbooks/create.yml @@ -149,6 +149,8 @@ hostname: "{{ item.hostname | default(omit) }}" image: "{{ item.pre_build_image | default(false) | ternary('', 'molecule_local/') }}{{ item.image }}" ip: "{{ item.ip | default(omit) }}" + labels: + owner: "molecule" # keep in sync with ../driver.py:Podman.reset() network: "{{ item.network | default(omit) }}" pid: "{{ item.pid_mode | default(omit) }}" privileged: "{{ item.privileged | default(omit) }}" From a51afd1e64d9ea5f93c8dbfdfaae7c576a4b1319 Mon Sep 17 00:00:00 2001 From: guppy0130 Date: Mon, 30 Sep 2024 19:53:44 -0500 Subject: [PATCH 2/2] address PR feedback * hotfix filter/labels typo * use `label` instead of alias `labels` --- src/molecule_plugins/podman/driver.py | 2 +- src/molecule_plugins/podman/playbooks/create.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/molecule_plugins/podman/driver.py b/src/molecule_plugins/podman/driver.py index 0091c6f6..5f7621c6 100644 --- a/src/molecule_plugins/podman/driver.py +++ b/src/molecule_plugins/podman/driver.py @@ -246,4 +246,4 @@ def required_collections(self) -> dict[str, str]: def reset(self): # keep `--filter` in sync with playbooks/create.yml - run_command(["podman", "rm", "--force", "--filter=owner=molecule"]) + run_command(["podman", "rm", "--force", "--filter=label=owner=molecule"]) diff --git a/src/molecule_plugins/podman/playbooks/create.yml b/src/molecule_plugins/podman/playbooks/create.yml index 7d667ab8..57eab266 100644 --- a/src/molecule_plugins/podman/playbooks/create.yml +++ b/src/molecule_plugins/podman/playbooks/create.yml @@ -149,7 +149,7 @@ hostname: "{{ item.hostname | default(omit) }}" image: "{{ item.pre_build_image | default(false) | ternary('', 'molecule_local/') }}{{ item.image }}" ip: "{{ item.ip | default(omit) }}" - labels: + label: owner: "molecule" # keep in sync with ../driver.py:Podman.reset() network: "{{ item.network | default(omit) }}" pid: "{{ item.pid_mode | default(omit) }}"