Skip to content

Commit

Permalink
implement reset for podman driver (#269)
Browse files Browse the repository at this point in the history
* 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`

* address PR feedback

* hotfix filter/labels typo
* use `label` instead of alias `labels`
  • Loading branch information
guppy0130 authored Oct 1, 2024
1 parent fdc748f commit 78f0441
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/molecule_plugins/podman/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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=label=owner=molecule"])
2 changes: 2 additions & 0 deletions src/molecule_plugins/podman/playbooks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}"
label:
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) }}"
Expand Down

0 comments on commit 78f0441

Please sign in to comment.