mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-02-04 07:11:49 +00:00
Add idempotency for mounts and volumes (#753)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
This commit is contained in:
parent
391e4c54ef
commit
e1e4e7516a
2 changed files with 119 additions and 27 deletions
|
|
@ -1217,6 +1217,9 @@ class PodmanContainerDiff:
|
|||
def diffparam_healthcheck_timeout(self):
|
||||
return self._diff_generic('healthcheck_timeout', '--healthcheck-timeout')
|
||||
|
||||
def diffparam_hooks_dir(self):
|
||||
return self._diff_generic('hooks_dir', '--hooks-dir')
|
||||
|
||||
def diffparam_hostname(self):
|
||||
return self._diff_generic('hostname', '--hostname')
|
||||
|
||||
|
|
@ -1308,6 +1311,9 @@ class PodmanContainerDiff:
|
|||
def diffparam_memory_swappiness(self):
|
||||
return self._diff_generic('memory_swappiness', '--memory-swappiness')
|
||||
|
||||
def diffparam_mount(self):
|
||||
return self._diff_generic('mount', '--mount')
|
||||
|
||||
def diffparam_network(self):
|
||||
net_mode_before = self.info['hostconfig']['networkmode']
|
||||
net_mode_after = ''
|
||||
|
|
@ -1529,32 +1535,22 @@ class PodmanContainerDiff:
|
|||
return "/"
|
||||
return x.replace("//", "/").rstrip("/")
|
||||
|
||||
before = self.info['mounts']
|
||||
before_local_vols = []
|
||||
if before:
|
||||
volumes = []
|
||||
local_vols = []
|
||||
for m in before:
|
||||
if m['type'] != 'volume':
|
||||
volumes.append(
|
||||
[
|
||||
clean_volume(m['source']),
|
||||
clean_volume(m['destination'])
|
||||
])
|
||||
elif m['type'] == 'volume':
|
||||
local_vols.append(
|
||||
[m['name'], clean_volume(m['destination'])])
|
||||
before = [":".join(v) for v in volumes]
|
||||
before_local_vols = [":".join(v) for v in local_vols]
|
||||
if self.params['volume'] is not None:
|
||||
before = self._createcommand('--volume')
|
||||
if before == []:
|
||||
before = None
|
||||
after = self.params['volume']
|
||||
if after is not None:
|
||||
after = [":".join(
|
||||
[clean_volume(i) for i in v.split(":")[:2]]
|
||||
) for v in self.params['volume']]
|
||||
else:
|
||||
after = []
|
||||
if before_local_vols:
|
||||
after = list(set(after).difference(before_local_vols))
|
||||
before, after = sorted(list(set(before))), sorted(list(set(after)))
|
||||
[clean_volume(i) for i in v.split(":")[:2]]) for v in self.params['volume']]
|
||||
if before is not None:
|
||||
before = [":".join([clean_volume(i) for i in v.split(":")[:2]]) for v in before]
|
||||
self.module.log("PODMAN Before: %s and After: %s" % (before, after))
|
||||
if before is None and after is None:
|
||||
return self._diff_update_and_compare('volume', before, after)
|
||||
if after is not None:
|
||||
after = ",".join(sorted([str(i).lower() for i in after]))
|
||||
if before:
|
||||
before = ",".join(sorted([str(i).lower() for i in before]))
|
||||
return self._diff_update_and_compare('volume', before, after)
|
||||
|
||||
def diffparam_volumes_from(self):
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@
|
|||
|
||||
- name: check test9
|
||||
assert:
|
||||
that: test9 is not changed
|
||||
that: test9 is changed
|
||||
|
||||
- name: Create volumes
|
||||
shell: |
|
||||
|
|
@ -190,7 +190,7 @@
|
|||
|
||||
- name: check test13
|
||||
assert:
|
||||
that: test13 is not changed
|
||||
that: test13 is changed
|
||||
|
||||
- containers.podman.podman_container:
|
||||
executable: "{{ test_executable | default('podman') }}"
|
||||
|
|
@ -253,3 +253,99 @@
|
|||
- name: check test17
|
||||
assert:
|
||||
that: test17 is not changed
|
||||
|
||||
- containers.podman.podman_container:
|
||||
executable: "{{ test_executable | default('podman') }}"
|
||||
image: alpine
|
||||
name: idempotency1
|
||||
state: present
|
||||
command: sleep 1h
|
||||
mounts:
|
||||
- "type=bind,source=/tmp,destination=/tmp"
|
||||
register: test18
|
||||
|
||||
- name: check test18
|
||||
assert:
|
||||
that: test18 is changed
|
||||
|
||||
- containers.podman.podman_container:
|
||||
executable: "{{ test_executable | default('podman') }}"
|
||||
image: alpine
|
||||
name: idempotency1
|
||||
state: present
|
||||
command: sleep 1h
|
||||
mounts:
|
||||
- "type=bind,source=/tmp,destination=/tmp"
|
||||
register: test19
|
||||
|
||||
- name: check test19
|
||||
assert:
|
||||
that: test19 is not changed
|
||||
|
||||
- containers.podman.podman_container:
|
||||
executable: "{{ test_executable | default('podman') }}"
|
||||
image: alpine
|
||||
name: idempotency1
|
||||
state: present
|
||||
command: sleep 1h
|
||||
mounts:
|
||||
- "type=bind,source=/tmp,destination=/tmp"
|
||||
- "type=bind,source=/var,destination=/var"
|
||||
volumes:
|
||||
- /opt:/data
|
||||
- "local_volume2:/data2"
|
||||
register: test20
|
||||
|
||||
- name: check test20
|
||||
assert:
|
||||
that: test20 is changed
|
||||
|
||||
- containers.podman.podman_container:
|
||||
executable: "{{ test_executable | default('podman') }}"
|
||||
image: alpine
|
||||
name: idempotency1
|
||||
state: present
|
||||
command: sleep 1h
|
||||
mounts:
|
||||
- "type=bind,source=/tmp,destination=/tmp"
|
||||
- "type=bind,source=/var,destination=/var"
|
||||
volumes:
|
||||
- /opt:/data
|
||||
- "local_volume2:/data2"
|
||||
register: test21
|
||||
|
||||
- name: check test21
|
||||
assert:
|
||||
that: test21 is not changed
|
||||
|
||||
- containers.podman.podman_container:
|
||||
executable: "{{ test_executable | default('podman') }}"
|
||||
image: alpine
|
||||
name: idempotency1
|
||||
state: present
|
||||
command: sleep 1h
|
||||
mounts:
|
||||
- "type=bind,source=/tmp,destination=/tmp"
|
||||
volumes:
|
||||
- /opt:/data
|
||||
register: test22
|
||||
|
||||
- name: check test22
|
||||
assert:
|
||||
that: test22 is changed
|
||||
|
||||
- containers.podman.podman_container:
|
||||
executable: "{{ test_executable | default('podman') }}"
|
||||
image: alpine
|
||||
name: idempotency1
|
||||
state: present
|
||||
command: sleep 1h
|
||||
mounts:
|
||||
- "type=bind,source=/tmp,destination=/tmp"
|
||||
volumes:
|
||||
- /opt:/data
|
||||
register: test23
|
||||
|
||||
- name: check test23
|
||||
assert:
|
||||
that: test23 is not changed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue