Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add idempotency for mounts and volumes #753

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions plugins/module_utils/podman/podman_container_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,9 @@ def diffparam_health_startup_timeout(self):
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')

Expand Down Expand Up @@ -1308,6 +1311,9 @@ def diffparam_memory_swap(self):
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 = ''
Expand Down Expand Up @@ -1529,32 +1535,22 @@ def clean_volume(x):
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@

- name: check test9
assert:
that: test9 is not changed
that: test9 is changed

- name: Create volumes
shell: |
Expand Down Expand Up @@ -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') }}"
Expand Down Expand Up @@ -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