Skip to content

Commit

Permalink
fix: fix tmpfs_size and tmpfs_mode not being set
Browse files Browse the repository at this point in the history
  • Loading branch information
kristof-mattei committed Feb 10, 2023
1 parent 54a3dc1 commit 749e3a5
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 5 deletions.
4 changes: 2 additions & 2 deletions plugins/module_utils/module_container/docker_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,8 @@ def _set_values_mounts(module, data, api_version, options, values):
tmpfs_opts['Mode'] = mount.get('tmpfs_mode')
if mount.get('tmpfs_size'):
tmpfs_opts['SizeBytes'] = mount.get('tmpfs_size')
if mount.get('tmpfs_opts'):
mount_res['TmpfsOptions'] = mount.get('tmpfs_opts')
if tmpfs_opts:
mount_res['TmpfsOptions'] = tmpfs_opts
mounts.append(mount_res)
data['HostConfig']['Mounts'] = mounts
if 'volumes' in values:
Expand Down
12 changes: 12 additions & 0 deletions plugins/modules/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,18 @@
# The "NONE" check needs to be specified
test: ["NONE"]
- name: Create a tmpfs with a size and mode
community.docker.docker_container:
name: tmpfs test
image: ubuntu:22.04
state: started
mount
mounts:
- type: tmpfs
target: /cache
tmpfs_mode: "1700" # only readable to the owner
tmpfs_size: "16G"
- name: Start container with block device read limit
community.docker.docker_container:
name: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,127 @@
- mounts_7 is changed
- mounts_8 is not changed

####################################################################
## tmpfs ###########################################################
####################################################################

- name: tmpfs
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
mounts:
- target: /cache1
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
- target: /cache2
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
force_kill: true
register: tmpfs_1

- name: tmpfs (idempotency)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
mounts:
- target: /cache2
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
- target: /cache1
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
force_kill: true
register: tmpfs_2

- name: tmpfs (more mounts)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
mounts:
- target: /cache1
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
force_kill: true
- target: /cache2
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
force_kill: true
- target: /cache3
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
force_kill: true
register: tmpfs_3

- name: tmpfs (less mount)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
mounts:
- target: /cache1
type: tmpfs
tmpfs_mode: "1777"
tmpfs_size: "1GB"
force_kill: true
register: tmpfs_4

- name: tmpfs (change mode)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
mounts:
- target: /cache1
type: tmpfs
tmpfs_mode: "1700"
tmpfs_size: "1GB"
force_kill: true
register: tmpfs_5

- name: tmpfs (change size)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
mounts:
- target: /cache1
type: tmpfs
tmpfs_mode: "1700"
tmpfs_size: "2GB"
force_kill: true
register: tmpfs_5

- name: cleanup
docker_container:
name: "{{ cname }}"
state: absent
force_kill: yes
diff: no

- assert:
that:
- tmpfs_1 is changed
- tmpfs_2 is not changed
- tmpfs_3 is changed
- tmpfs_4 is changed
- tmpfs_5 is changed

####################################################################
## mounts + volumes ################################################
####################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@
type: "tmpfs"
tmpfs_size: "50M"
register: mounts_tmpfs_size_1
ignore_errors: yes

- name: mounts.tmpfs_size (idempotency)
docker_swarm_service:
Expand All @@ -432,7 +431,6 @@
type: "tmpfs"
tmpfs_size: "50M"
register: mounts_tmpfs_size_2
ignore_errors: yes

- name: mounts.tmpfs_size (change)
docker_swarm_service:
Expand All @@ -446,7 +444,6 @@
type: "tmpfs"
tmpfs_size: "25M"
register: mounts_tmpfs_size_3
ignore_errors: yes

- name: cleanup
docker_swarm_service:
Expand Down

0 comments on commit 749e3a5

Please sign in to comment.