mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 11:55:04 +00:00
feat: allow unlimited memory_swap in docker_container (#138)
* feat: allow unlimited memory_swap in docker_container summary: in docker_container, allow `memory_swap: values `unlimited` and `-1` for unlimited container swap usage. `--memory-swap=-1` is a valid docker run value allowing unlimited swap usage. `docker_container` should allow setting this value via `memory_swap` values `unlimited` and `-1` as it sometimes must explicitly be set to prevent docker from attempting to limit swap usage to double the `--memory` value by default. In rootless docker environments, attempting to set `memory-swap` usage limits will result in an error if the user doesn't have the ability to do so. Allowing explicit unlimited swap usage via docker_container will prevent these errors. https://docs.docker.com/config/containers/resource_constraints/#--memory-swap-details * Update tests/integration/targets/docker_container/tasks/tests/options.yml * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
@@ -2520,6 +2520,32 @@ avoid such warnings, please quote the value.' in log_options_2.warnings"
|
||||
debug: yes
|
||||
register: memory_swap_3
|
||||
|
||||
- name: memory_swap (unlimited)
|
||||
docker_container:
|
||||
image: "{{ docker_test_image_alpine }}"
|
||||
command: '/bin/sh -c "sleep 10m"'
|
||||
name: "{{ cname }}"
|
||||
# Docker daemon does not accept memory_swap if memory is not specified
|
||||
memory: 32M
|
||||
memory_swap: unlimited
|
||||
state: started
|
||||
force_kill: yes
|
||||
debug: yes
|
||||
register: memory_swap_4
|
||||
|
||||
- name: memory_swap (unlimited via -1)
|
||||
docker_container:
|
||||
image: "{{ docker_test_image_alpine }}"
|
||||
command: '/bin/sh -c "sleep 10m"'
|
||||
name: "{{ cname }}"
|
||||
# Docker daemon does not accept memory_swap if memory is not specified
|
||||
memory: 32M
|
||||
memory_swap: -1
|
||||
state: started
|
||||
force_kill: yes
|
||||
debug: yes
|
||||
register: memory_swap_5
|
||||
|
||||
- name: cleanup
|
||||
docker_container:
|
||||
name: "{{ cname }}"
|
||||
@@ -2534,6 +2560,11 @@ avoid such warnings, please quote the value.' in log_options_2.warnings"
|
||||
# on a proper VM), memory_swap cannot be set and will be -1 afterwards.
|
||||
- memory_swap_2 is not changed or memory_swap_2.container.HostConfig.MemorySwap == -1
|
||||
- memory_swap_3 is changed
|
||||
# Unlimited memory_swap (using 'unlimited') should be allowed
|
||||
# (If the value was already -1 because of the above reasons, it won't change)
|
||||
- (memory_swap_4 is changed or memory_swap_3.container.HostConfig.MemorySwap == -1) and memory_swap_4.container.HostConfig.MemorySwap == -1
|
||||
# Unlimited memory_swap (using '-1') should be allowed
|
||||
- memory_swap_5 is not changed and memory_swap_5.container.HostConfig.MemorySwap == -1
|
||||
|
||||
- debug: var=memory_swap_1
|
||||
when: memory_swap_2 is changed
|
||||
|
||||
Reference in New Issue
Block a user