Skip to content

Commit

Permalink
Add sysctls option to docker_swarm_service (#836)
Browse files Browse the repository at this point in the history
* add sysctls option to docker_swarm_service

* Add added version number

Co-authored-by: Felix Fontein <[email protected]>

* version added -> 3.10.0

Co-authored-by: Felix Fontein <[email protected]>

* 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 <[email protected]>
  • Loading branch information
NairolfL and felixfontein authored Apr 30, 2024
1 parent f09a254 commit 368d616
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/836-docker_swarm_service-sysctls.yml
Original file line number Diff line number Diff line change
@@ -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).
16 changes: 16 additions & 0 deletions plugins/modules/docker_swarm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
- 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.
Expand Down Expand Up @@ -681,6 +686,7 @@
"engine.labels.operatingsystem == ubuntu 14.04"
],
"container_labels": null,
"sysctls": null,
"dns": null,
"dns_options": null,
"dns_search": null,
Expand Down Expand Up @@ -1226,6 +1232,7 @@ def __init__(self, docker_api_version, docker_py_version):
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
Expand Down Expand Up @@ -1292,6 +1299,7 @@ def get_facts(self):
'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,
Expand Down Expand Up @@ -1539,6 +1547,7 @@ def from_ansible_params(
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']
Expand Down Expand Up @@ -1740,6 +1749,8 @@ def compare(self, os):
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:
Expand Down Expand Up @@ -1934,6 +1945,8 @@ def build_container_spec(self):
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:
Expand Down Expand Up @@ -2163,6 +2176,7 @@ def get_service(self, name):
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:
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ service_expected_output:
user: null
working_dir: null
init: null
sysctls: null

0 comments on commit 368d616

Please sign in to comment.