Skip to content

Commit

Permalink
implement reset for podman driver
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
guppy0130 committed Sep 19, 2024
1 parent 9943538 commit 3901ff8
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 sysexit_with_message, run_command

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=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) }}"
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) }}"
Expand Down

0 comments on commit 3901ff8

Please sign in to comment.