mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-04-16 17:26:28 +00:00
feat(docker_swarm_service): Add support for replicated jobs
This commit is contained in:
parent
920015706b
commit
07a4b615d2
@ -242,6 +242,7 @@ options:
|
||||
choices:
|
||||
- replicated
|
||||
- global
|
||||
- replicated-job
|
||||
mounts:
|
||||
description:
|
||||
- List of dictionaries describing the service mounts.
|
||||
@ -400,7 +401,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 +2211,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 +2609,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']),
|
||||
|
||||
@ -1307,11 +1307,51 @@
|
||||
state: absent
|
||||
diff: false
|
||||
|
||||
- name: mode
|
||||
docker_swarm_service:
|
||||
name: "{{ service_name }}"
|
||||
image: "{{ docker_test_image_alpine }}"
|
||||
resolve_image: false
|
||||
command: '/bin/sh -v -c "sleep 10m"'
|
||||
mode: "replicated-job"
|
||||
replicas: 1
|
||||
register: mode_4
|
||||
|
||||
- name: mode (idempotency)
|
||||
docker_swarm_service:
|
||||
name: "{{ service_name }}"
|
||||
image: "{{ docker_test_image_alpine }}"
|
||||
resolve_image: false
|
||||
command: '/bin/sh -v -c "sleep 10m"'
|
||||
mode: "replicated-job"
|
||||
replicas: 1
|
||||
register: mode_5
|
||||
|
||||
- name: mode (change)
|
||||
docker_swarm_service:
|
||||
name: "{{ service_name }}"
|
||||
image: "{{ docker_test_image_alpine }}"
|
||||
resolve_image: false
|
||||
command: '/bin/sh -v -c "sleep 10m"'
|
||||
mode: "replicated"
|
||||
replicas: 1
|
||||
register: mode_6
|
||||
|
||||
- name: cleanup
|
||||
docker_swarm_service:
|
||||
name: "{{ service_name }}"
|
||||
state: absent
|
||||
diff: false
|
||||
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- mode_1 is changed
|
||||
- mode_2 is not changed
|
||||
- mode_3 is changed
|
||||
- mode_4 is changed
|
||||
- mode_5 is not changed
|
||||
- mode_6 is changed
|
||||
|
||||
####################################################################
|
||||
## stop_grace_period ###############################################
|
||||
|
||||
Loading…
Reference in New Issue
Block a user