1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-02-04 07:11:49 +00:00

Add simple actions for start/stop etc for Podman Pod

In case of existing pod make possible just to start, restart, stop
and pause/unpause without recreating the pod.

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
This commit is contained in:
Sagi Shnaidman 2024-05-27 18:15:25 +03:00
parent 47fc4cc119
commit 20fda04fc3
2 changed files with 131 additions and 6 deletions

View file

@ -905,11 +905,11 @@ class PodmanPodManager:
process_action()
return self.results
def _create_or_recreate_pod(self):
def _create_or_recreate_pod(self, ignore_diff=False):
"""Ensure pod exists and is exactly as it should be by input params."""
changed = False
if self.pod.exists:
if self.pod.different or self.recreate:
if (self.pod.different and not ignore_diff) or self.recreate:
self.pod.recreate()
self.results['actions'].append('recreated %s' % self.pod.name)
changed = True
@ -929,14 +929,14 @@ class PodmanPodManager:
def make_killed(self):
"""Run actions if desired state is 'killed'."""
self._create_or_recreate_pod()
self._create_or_recreate_pod(ignore_diff=True)
self.pod.kill()
self.results['actions'].append('killed %s' % self.pod.name)
self.update_pod_result()
def make_paused(self):
"""Run actions if desired state is 'paused'."""
changed = self._create_or_recreate_pod()
changed = self._create_or_recreate_pod(ignore_diff=True)
if self.pod.paused:
self.update_pod_result(changed=changed)
return
@ -946,7 +946,7 @@ class PodmanPodManager:
def make_unpaused(self):
"""Run actions if desired state is 'unpaused'."""
changed = self._create_or_recreate_pod()
changed = self._create_or_recreate_pod(ignore_diff=True)
if not self.pod.paused:
self.update_pod_result(changed=changed)
return
@ -956,7 +956,7 @@ class PodmanPodManager:
def make_started(self):
"""Run actions if desired state is 'started'."""
changed = self._create_or_recreate_pod()
changed = self._create_or_recreate_pod(ignore_diff=True)
if not changed and self.pod.running:
self.update_pod_result(changed=changed)
return

View file

@ -262,6 +262,131 @@
that:
- podidem2_info4 is not changed
# Test new Pod logic
- name: Create pod with multiple options and containers
containers.testpodman.podman_pod:
executable: "{{ test_executable | default('podman') }}"
name: podidem3
state: created
infra: true
network: host
share: net
userns: auto
security_opt:
- seccomp=unconfined
- apparmor=unconfined
hostname: mypod3
dns:
- 1.1.1.1
volumes:
- /tmp:/tmp/:ro
label:
key: cval
otherkey: kddkdk
somekey: someval
add_host:
- "google:5.5.5.5"
register: podidem3_info
- name: Check info
assert:
that:
- podidem3_info is changed
- name: Create containers
containers.testpodman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: "container1"
image: alpine
state: present
command: sleep 1h
pod: podidem3
- name: Create containers
containers.testpodman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: "container2"
image: alpine
state: present
command: sleep 1h
pod: podidem3
- name: Start the pod with containers
containers.testpodman.podman_pod:
executable: "{{ test_executable | default('podman') }}"
name: podidem3
state: started
register: podidem3_info2
- name: Check info
assert:
that:
- podidem3_info2 is changed
- name: Create pod with multiple options and containers - again
containers.testpodman.podman_pod:
executable: "{{ test_executable | default('podman') }}"
name: podidem3
state: created
infra: true
network: host
share: net
userns: auto
security_opt:
- seccomp=unconfined
- apparmor=unconfined
hostname: mypod3
dns:
- 1.1.1.1
volumes:
- /tmp:/tmp/:ro
label:
key: cval
otherkey: kddkdk
somekey: someval
add_host:
- "google:5.5.5.5"
register: podidem3_info
- name: Check info
assert:
that:
- podidem3_info is not changed
- name: Create containers
containers.testpodman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: "container1"
image: alpine
state: present
command: sleep 1h
pod: podidem3
register: container1_info
- name: Create containers
containers.testpodman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: "container2"
image: alpine
state: present
command: sleep 1h
pod: podidem3
register: container2_info
- name: Start the pod with containers
containers.testpodman.podman_pod:
executable: "{{ test_executable | default('podman') }}"
name: podidem3
state: started
register: podidem3_info2
- name: Check info
assert:
that:
- podidem3_info2 is not changed
- container1_info is not changed
- container2_info is not changed
always:
- name: Delete all pods leftovers from tests