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:
@@ -458,7 +458,8 @@ options:
|
||||
type: str
|
||||
memory_swap:
|
||||
description:
|
||||
- "Total memory limit (memory + swap) in format C(<number>[<unit>]).
|
||||
- "Total memory limit (memory + swap) in format C(<number>[<unit>]), or
|
||||
the special values C(unlimited) or C(-1) for unlimited swap usage.
|
||||
Number is a positive integer. Unit can be C(B) (byte), C(K) (kibibyte, 1024B),
|
||||
C(M) (mebibyte), C(G) (gibibyte), C(T) (tebibyte), or C(P) (pebibyte)."
|
||||
- Omitting the unit defaults to bytes.
|
||||
@@ -1413,10 +1414,13 @@ class TaskParameters(DockerBaseClass):
|
||||
|
||||
for param_name in REQUIRES_CONVERSION_TO_BYTES:
|
||||
if client.module.params.get(param_name):
|
||||
try:
|
||||
setattr(self, param_name, human_to_bytes(client.module.params.get(param_name)))
|
||||
except ValueError as exc:
|
||||
self.fail("Failed to convert %s to bytes: %s" % (param_name, to_native(exc)))
|
||||
if param_name == 'memory_swap' and client.module.params.get(param_name) in ['unlimited', '-1']:
|
||||
setattr(self, param_name, -1)
|
||||
else:
|
||||
try:
|
||||
setattr(self, param_name, human_to_bytes(client.module.params.get(param_name)))
|
||||
except ValueError as exc:
|
||||
self.fail("Failed to convert %s to bytes: %s" % (param_name, to_native(exc)))
|
||||
|
||||
self.publish_all_ports = False
|
||||
self.published_ports = self._parse_publish_ports()
|
||||
|
||||
Reference in New Issue
Block a user