Skip to content

Commit

Permalink
Add idempotency for existing local volumes (containers#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
sshnaidm authored Jun 5, 2020
1 parent d2bfe79 commit 80b2ae6
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 13 deletions.
7 changes: 7 additions & 0 deletions plugins/modules/podman_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1731,16 +1731,23 @@ def diffparam_uts(self):

def diffparam_volume(self):
before = self.info['mounts']
before_local_vols = []
if before:
volumes = []
local_vols = []
for m in before:
if m['type'] != 'volume':
volumes.append([m['source'], m['destination']])
elif m['type'] == 'volume':
local_vols.append([m['name'], 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:
after = [":".join(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)))
return self._diff_update_and_compare('volume', before, after)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN chmod a+rwx /start
EXPOSE 80
EXPOSE 8080/tcp

VOLUME ["/data"]
VOLUME ["/data", "/data2"]
USER user
WORKDIR /work
STOPSIGNAL 9
Expand Down
84 changes: 72 additions & 12 deletions tests/integration/targets/podman_container/tasks/idem_volumes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,66 @@
assert:
that: test9 is not changed

- name: Create volumes
shell: |
podman volume inspect local_volume1 || podman volume create local_volume1
podman volume inspect local_volume2 || podman volume create local_volume2
- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
command: 1h
volumes:
- "/opt:/anotherdir"
- "local_volume1:/data"
register: test10

- name: check test10
assert:
that: test10 is changed

- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
command: 1h
volumes:
- "/opt:/anotherdir"
- "local_volume1:/data"
register: test11

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

- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
command: 1h
volumes:
- "/opt:/anotherdir"
- "local_volume2:/data"
register: test12

- name: check test12
assert:
that: test12 is changed

- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
command: 1h
volumes:
- "/opt:/anotherdir"
register: test13

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

- containers.podman.podman_container:
name: idempotency1
state: absent
Expand All @@ -132,11 +192,11 @@
name: idempotency1
state: present
command: sleep 1h
register: test10
register: test14

- name: check test10
- name: check test14
assert:
that: test10 is not changed
that: test14 is not changed

- containers.podman.podman_container:
image: alpine
Expand All @@ -145,30 +205,30 @@
volumes:
- /opt:/data
command: sleep 1h
register: test11
register: test15

- name: check test11
- name: check test15
assert:
that: test11 is changed
that: test15 is changed

- containers.podman.podman_container:
image: alpine
name: idempotency1
state: present
command: sleep 1h
register: test12
register: test16

- name: check test12
- name: check test16
assert:
that: test12 is changed
that: test16 is changed

- containers.podman.podman_container:
image: alpine
name: idempotency1
state: present
command: sleep 1h
register: test13
register: test17

- name: check test13
- name: check test17
assert:
that: test13 is not changed
that: test17 is not changed

0 comments on commit 80b2ae6

Please sign in to comment.