docker_swarm_service: add support for replicated jobs (#1108)

* feat(docker_swarm_service): Add support for replicated jobs

* chore(docker_swarm_plugin): Fixes after review

* chore(docker_swarm_service): Add a check for minimum version

* chore(docker_swarm_service): Add changelog fragment for #1108

* fix(docker_swarm_service): Fix typo in version check

* Apply suggestions from code review

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

---------

Co-authored-by: Tristan Pourcelot <tristan.pourcelot@exatrack.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
tpourcelot
2025-08-03 13:12:29 +02:00
committed by GitHub
parent 920015706b
commit 449448e820
3 changed files with 60 additions and 2 deletions
+13 -2
View File
@@ -237,11 +237,13 @@ options:
- Service replication mode.
- Service will be removed and recreated when changed.
- Corresponds to the C(--mode) option of C(docker service create).
- The value V(replicated-job) was added in community.docker 4.7.0, and requires API version >= 1.41 and Docker SDK for Python >= 6.0.0.
type: str
default: replicated
choices:
- replicated
- global
- replicated-job
mounts:
description:
- List of dictionaries describing the service mounts.
@@ -400,7 +402,7 @@ options:
type: bool
replicas:
description:
- Number of containers instantiated in the service. Valid only if O(mode=replicated).
- Number of containers instantiated in the service. Valid only if O(mode=replicated) or O(mode=replicated-job).
- If set to V(-1), and service is not present, service replicas will be set to V(1).
- If set to V(-1), and service is present, service replicas will be unchanged.
- Corresponds to the C(--replicas) option of C(docker service create).
@@ -2210,6 +2212,9 @@ class DockerServiceManager(object):
ds.replicas = mode['Replicated']['Replicas']
elif 'Global' in mode.keys():
ds.mode = 'global'
elif 'ReplicatedJob' in mode.keys():
ds.mode = to_text('replicated-job', encoding='utf-8')
ds.replicas = mode['ReplicatedJob']['TotalCompletions']
else:
raise Exception('Unknown service mode: %s' % mode)
@@ -2605,7 +2610,7 @@ def main():
mode=dict(
type='str',
default='replicated',
choices=['replicated', 'global']
choices=['replicated', 'global', 'replicated-job']
),
replicas=dict(type='int', default=-1),
endpoint_mode=dict(type='str', choices=['vip', 'dnsrr']),
@@ -2753,6 +2758,12 @@ def main():
) is not None,
usage_msg='set rollback_config.order'
),
mode_replicated_job=dict(
docker_py_version='6.0.0',
docker_api_version='1.41',
detect_usage=lambda c: c.module.params.get('mode') == 'replicated-job',
usage_msg='set mode'
),
)
required_if = [
('state', 'present', ['image'])