Add sysctls option to docker_swarm_service (#836)

* add sysctls option to docker_swarm_service

* Add added version number

Co-authored-by: Felix Fontein <felix@fontein.de>

* version added -> 3.10.0

Co-authored-by: Felix Fontein <felix@fontein.de>

* changelog fragment for docker_swarm_service sysctls

* add minimal docker_py / docker_api versions to use for sysctls

* set expected sysctls to null on integration test

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Florian 2024-04-30 22:44:25 +02:00 committed by GitHub
parent f09a2540aa
commit 368d616229
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,2 @@
minor_changes:
- docker_swarm_service - adds ``sysctls`` to support sysctl settings on swarm services (https://github.com/ansible-collections/community.docker/issues/190).

View File

@ -83,6 +83,11 @@ options:
- Dictionary of key value pairs.
- Corresponds to the C(--container-label) option of C(docker service create).
type: dict
sysctls:
description:
- Dictionary of key, value pairs.
version_added: 3.10.0
type: dict
dns:
description:
- List of custom DNS servers.
@ -681,6 +686,7 @@ swarm_service:
"engine.labels.operatingsystem == ubuntu 14.04"
],
"container_labels": null,
"sysctls": null,
"dns": null,
"dns_options": null,
"dns_search": null,
@ -1226,6 +1232,7 @@ class DockerService(DockerBaseClass):
self.log_driver_options = None
self.labels = None
self.container_labels = None
self.sysctls = None
self.limit_cpu = None
self.limit_memory = None
self.reserve_cpu = None
@ -1292,6 +1299,7 @@ class DockerService(DockerBaseClass):
'placement_preferences': self.placement_preferences,
'labels': self.labels,
'container_labels': self.container_labels,
'sysctls': self.sysctls,
'mode': self.mode,
'replicas': self.replicas,
'endpoint_mode': self.endpoint_mode,
@ -1539,6 +1547,7 @@ class DockerService(DockerBaseClass):
s.tty = ap['tty']
s.labels = ap['labels']
s.container_labels = ap['container_labels']
s.sysctls = ap['sysctls']
s.mode = ap['mode']
s.stop_signal = ap['stop_signal']
s.user = ap['user']
@ -1740,6 +1749,8 @@ class DockerService(DockerBaseClass):
differences.add('reserve_memory', parameter=self.reserve_memory, active=os.reserve_memory)
if self.container_labels is not None and self.container_labels != (os.container_labels or {}):
differences.add('container_labels', parameter=self.container_labels, active=os.container_labels)
if self.sysctls is not None and self.sysctls != (os.sysctls or {}):
differences.add('sysctls', parameter=self.sysctls, active=os.sysctls)
if self.stop_signal is not None and self.stop_signal != os.stop_signal:
differences.add('stop_signal', parameter=self.stop_signal, active=os.stop_signal)
if self.stop_grace_period is not None and self.stop_grace_period != os.stop_grace_period:
@ -1934,6 +1945,8 @@ class DockerService(DockerBaseClass):
container_spec_args['user'] = self.user
if self.container_labels is not None:
container_spec_args['labels'] = self.container_labels
if self.sysctls is not None:
container_spec_args['sysctls'] = self.sysctls
if self.healthcheck is not None:
container_spec_args['healthcheck'] = types.Healthcheck(**self.healthcheck)
elif self.healthcheck_disabled:
@ -2163,6 +2176,7 @@ class DockerServiceManager(object):
ds.read_only = task_template_data['ContainerSpec'].get('ReadOnly')
ds.cap_add = task_template_data['ContainerSpec'].get('CapabilityAdd')
ds.cap_drop = task_template_data['ContainerSpec'].get('CapabilityDrop')
ds.sysctls = task_template_data['ContainerSpec'].get('Sysctls')
healthcheck_data = task_template_data['ContainerSpec'].get('Healthcheck')
if healthcheck_data:
@ -2676,6 +2690,7 @@ def main():
hosts=dict(type='dict'),
labels=dict(type='dict'),
container_labels=dict(type='dict'),
sysctls=dict(type='dict'),
mode=dict(
type='str',
default='replicated',
@ -2751,6 +2766,7 @@ def main():
init=dict(docker_py_version='4.0.0', docker_api_version='1.37'),
cap_add=dict(docker_py_version='5.0.3', docker_api_version='1.41'),
cap_drop=dict(docker_py_version='5.0.3', docker_api_version='1.41'),
sysctls=dict(docker_py_version='6.0.0', docker_api_version='1.40'),
# specials
publish_mode=dict(
docker_py_version='3.0.0',

View File

@ -58,3 +58,4 @@ service_expected_output:
user: null
working_dir: null
init: null
sysctls: null