mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-16 03:52:05 +00:00
Replicas max per node (#92)
* Adding 'replicas_max_per_node' placement parameter * Adding 'replicas_max_per_node' placement parameter * Adding 'replicas_max_per_node' integration tests * Adding 'replicas_max_per_node' feature * 'replicas_max_per_node' documentation update * 'replicas_max_per_node' unit test fix * Documentation and changelog updates * Update changelogs/fragments/92-replicas-max-per-node.yml Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: WojciechowskiPiotr <devel@it-playground.pl> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
f5d68755c4
commit
3ddd75ac68
2
changelogs/fragments/92-replicas-max-per-node.yml
Normal file
2
changelogs/fragments/92-replicas-max-per-node.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
minor_changes:
|
||||||
|
- "docker_swarm_service - adding support for maximum number of tasks per node (``replicas_max_per_node``) when running swarm service in replicated mode. Introduced in API 1.40 (https://github.com/ansible-collections/community.docker/issues/7, https://github.com/ansible-collections/community.docker/pull/92)."
|
||||||
@ -13,6 +13,7 @@ author:
|
|||||||
- "Dario Zanzico (@dariko)"
|
- "Dario Zanzico (@dariko)"
|
||||||
- "Jason Witkowski (@jwitko)"
|
- "Jason Witkowski (@jwitko)"
|
||||||
- "Hannes Ljungberg (@hannseman)"
|
- "Hannes Ljungberg (@hannseman)"
|
||||||
|
- "Piotr Wojciechowski (@wojciechowskipiotr)"
|
||||||
short_description: docker swarm service
|
short_description: docker swarm service
|
||||||
description:
|
description:
|
||||||
- Manages docker services via a swarm manager node.
|
- Manages docker services via a swarm manager node.
|
||||||
@ -344,6 +345,13 @@ options:
|
|||||||
- Requires API version >= 1.27.
|
- Requires API version >= 1.27.
|
||||||
type: list
|
type: list
|
||||||
elements: dict
|
elements: dict
|
||||||
|
replicas_max_per_node:
|
||||||
|
description:
|
||||||
|
- Maximum number of tasks per node.
|
||||||
|
- Corresponds to the C(--replicas_max_per_node) option of C(docker service create).
|
||||||
|
- Requires API version >= 1.40
|
||||||
|
type: int
|
||||||
|
version_added: 1.3.0
|
||||||
type: dict
|
type: dict
|
||||||
publish:
|
publish:
|
||||||
description:
|
description:
|
||||||
@ -718,6 +726,7 @@ swarm_service:
|
|||||||
"publish": null,
|
"publish": null,
|
||||||
"read_only": null,
|
"read_only": null,
|
||||||
"replicas": 1,
|
"replicas": 1,
|
||||||
|
"replicas_max_per_node": 1,
|
||||||
"reserve_cpu": 0.25,
|
"reserve_cpu": 0.25,
|
||||||
"reserve_memory": 20971520,
|
"reserve_memory": 20971520,
|
||||||
"restart_policy": "on-failure",
|
"restart_policy": "on-failure",
|
||||||
@ -840,6 +849,7 @@ EXAMPLES = '''
|
|||||||
constraints:
|
constraints:
|
||||||
- node.role == manager
|
- node.role == manager
|
||||||
- engine.labels.operatingsystem == ubuntu 14.04
|
- engine.labels.operatingsystem == ubuntu 14.04
|
||||||
|
replicas_max_per_node: 2
|
||||||
|
|
||||||
- name: Set configs
|
- name: Set configs
|
||||||
community.docker.docker_swarm_service:
|
community.docker.docker_swarm_service:
|
||||||
@ -1208,6 +1218,7 @@ class DockerService(DockerBaseClass):
|
|||||||
self.configs = None
|
self.configs = None
|
||||||
self.secrets = None
|
self.secrets = None
|
||||||
self.constraints = None
|
self.constraints = None
|
||||||
|
self.replicas_max_per_node = None
|
||||||
self.networks = None
|
self.networks = None
|
||||||
self.stop_grace_period = None
|
self.stop_grace_period = None
|
||||||
self.stop_signal = None
|
self.stop_signal = None
|
||||||
@ -1257,6 +1268,7 @@ class DockerService(DockerBaseClass):
|
|||||||
'log_driver_options': self.log_driver_options,
|
'log_driver_options': self.log_driver_options,
|
||||||
'publish': self.publish,
|
'publish': self.publish,
|
||||||
'constraints': self.constraints,
|
'constraints': self.constraints,
|
||||||
|
'replicas_max_per_node': self.replicas_max_per_node,
|
||||||
'placement_preferences': self.placement_preferences,
|
'placement_preferences': self.placement_preferences,
|
||||||
'labels': self.labels,
|
'labels': self.labels,
|
||||||
'container_labels': self.container_labels,
|
'container_labels': self.container_labels,
|
||||||
@ -1472,9 +1484,15 @@ class DockerService(DockerBaseClass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
preferences = placement.get('preferences')
|
preferences = placement.get('preferences')
|
||||||
|
replicas_max_per_node = get_value(
|
||||||
|
'replicas_max_per_node',
|
||||||
|
placement
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'constraints': constraints,
|
'constraints': constraints,
|
||||||
'placement_preferences': preferences,
|
'placement_preferences': preferences,
|
||||||
|
'replicas_max_per_node': replicas_max_per_node,
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -1683,6 +1701,8 @@ class DockerService(DockerBaseClass):
|
|||||||
differences.add('args', parameter=self.args, active=os.args)
|
differences.add('args', parameter=self.args, active=os.args)
|
||||||
if has_list_changed(self.constraints, os.constraints):
|
if has_list_changed(self.constraints, os.constraints):
|
||||||
differences.add('constraints', parameter=self.constraints, active=os.constraints)
|
differences.add('constraints', parameter=self.constraints, active=os.constraints)
|
||||||
|
if self.replicas_max_per_node is not None and self.replicas_max_per_node != os.replicas_max_per_node:
|
||||||
|
differences.add('replicas_max_per_node', parameter=self.replicas_max_per_node, active=os.replicas_max_per_node)
|
||||||
if has_list_changed(self.placement_preferences, os.placement_preferences, sort_lists=False):
|
if has_list_changed(self.placement_preferences, os.placement_preferences, sort_lists=False):
|
||||||
differences.add('placement_preferences', parameter=self.placement_preferences, active=os.placement_preferences)
|
differences.add('placement_preferences', parameter=self.placement_preferences, active=os.placement_preferences)
|
||||||
if has_list_changed(self.groups, os.groups):
|
if has_list_changed(self.groups, os.groups):
|
||||||
@ -1923,6 +1943,8 @@ class DockerService(DockerBaseClass):
|
|||||||
placement_args = {}
|
placement_args = {}
|
||||||
if self.constraints is not None:
|
if self.constraints is not None:
|
||||||
placement_args['constraints'] = self.constraints
|
placement_args['constraints'] = self.constraints
|
||||||
|
if self.replicas_max_per_node is not None:
|
||||||
|
placement_args['maxreplicas'] = self.replicas_max_per_node
|
||||||
if self.placement_preferences is not None:
|
if self.placement_preferences is not None:
|
||||||
placement_args['preferences'] = [
|
placement_args['preferences'] = [
|
||||||
{key.title(): {'SpreadDescriptor': value}}
|
{key.title(): {'SpreadDescriptor': value}}
|
||||||
@ -2164,6 +2186,7 @@ class DockerServiceManager(object):
|
|||||||
placement = task_template_data.get('Placement')
|
placement = task_template_data.get('Placement')
|
||||||
if placement:
|
if placement:
|
||||||
ds.constraints = placement.get('Constraints')
|
ds.constraints = placement.get('Constraints')
|
||||||
|
ds.replicas_max_per_node = placement.get('MaxReplicas')
|
||||||
placement_preferences = []
|
placement_preferences = []
|
||||||
for preference in placement.get('Preferences', []):
|
for preference in placement.get('Preferences', []):
|
||||||
placement_preferences.append(
|
placement_preferences.append(
|
||||||
@ -2603,6 +2626,7 @@ def main():
|
|||||||
placement=dict(type='dict', options=dict(
|
placement=dict(type='dict', options=dict(
|
||||||
constraints=dict(type='list', elements='str'),
|
constraints=dict(type='list', elements='str'),
|
||||||
preferences=dict(type='list', elements='dict'),
|
preferences=dict(type='list', elements='dict'),
|
||||||
|
replicas_max_per_node=dict(type='int'),
|
||||||
)),
|
)),
|
||||||
tty=dict(type='bool'),
|
tty=dict(type='bool'),
|
||||||
dns=dict(type='list', elements='str'),
|
dns=dict(type='list', elements='str'),
|
||||||
@ -2748,6 +2772,14 @@ def main():
|
|||||||
) is not None,
|
) is not None,
|
||||||
usage_msg='set placement.constraints'
|
usage_msg='set placement.constraints'
|
||||||
),
|
),
|
||||||
|
placement_config_replicas_max_per_node=dict(
|
||||||
|
docker_py_version='4.4.3',
|
||||||
|
docker_api_version='1.40',
|
||||||
|
detect_usage=lambda c: (c.module.params['placement'] or {}).get(
|
||||||
|
'replicas_max_per_node'
|
||||||
|
) is not None,
|
||||||
|
usage_msg='set placement.replicas_max_per_node'
|
||||||
|
),
|
||||||
mounts_tmpfs=dict(
|
mounts_tmpfs=dict(
|
||||||
docker_py_version='2.6.0',
|
docker_py_version='2.6.0',
|
||||||
detect_usage=_detect_mount_tmpfs_usage,
|
detect_usage=_detect_mount_tmpfs_usage,
|
||||||
|
|||||||
@ -200,3 +200,59 @@
|
|||||||
- constraints_1 is failed
|
- constraints_1 is failed
|
||||||
- "'Minimum version required' in constraints_1.msg"
|
- "'Minimum version required' in constraints_1.msg"
|
||||||
when: docker_api_version is version('1.27', '<') or docker_py_version is version('2.4.0', '<')
|
when: docker_api_version is version('1.27', '<') or docker_py_version is version('2.4.0', '<')
|
||||||
|
|
||||||
|
####################################################################
|
||||||
|
## placement.replicas_max_per_node #####################################################
|
||||||
|
####################################################################
|
||||||
|
|
||||||
|
- name: placement.replicas_max_per_node
|
||||||
|
docker_swarm_service:
|
||||||
|
name: "{{ service_name }}"
|
||||||
|
image: "{{ docker_test_image_alpine }}"
|
||||||
|
resolve_image: no
|
||||||
|
command: '/bin/sh -v -c "sleep 10m"'
|
||||||
|
placement:
|
||||||
|
replicas_max_per_node: 1
|
||||||
|
register: replicas_max_per_node_1
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: placement.replicas_max_per_node (idempotency)
|
||||||
|
docker_swarm_service:
|
||||||
|
name: "{{ service_name }}"
|
||||||
|
image: "{{ docker_test_image_alpine }}"
|
||||||
|
resolve_image: no
|
||||||
|
command: '/bin/sh -v -c "sleep 10m"'
|
||||||
|
placement:
|
||||||
|
replicas_max_per_node: 1
|
||||||
|
register: replicas_max_per_node_2
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: placement.replicas_max_per_node (change)
|
||||||
|
docker_swarm_service:
|
||||||
|
name: "{{ service_name }}"
|
||||||
|
image: "{{ docker_test_image_alpine }}"
|
||||||
|
resolve_image: no
|
||||||
|
command: '/bin/sh -v -c "sleep 10m"'
|
||||||
|
placement:
|
||||||
|
replicas_max_per_node: 2
|
||||||
|
register: replicas_max_per_node_3
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
|
||||||
|
- name: cleanup
|
||||||
|
docker_swarm_service:
|
||||||
|
name: "{{ service_name }}"
|
||||||
|
state: absent
|
||||||
|
diff: no
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- replicas_max_per_node_1 is changed
|
||||||
|
- replicas_max_per_node_2 is not changed
|
||||||
|
- replicas_max_per_node_3 is changed
|
||||||
|
when: docker_api_version is version('1.40', '>=') and docker_py_version is version('4.4.3', '>=')
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- replicas_max_per_node_1 is failed
|
||||||
|
- "'Minimum version required' in replicas_max_per_node_1.msg"
|
||||||
|
when: docker_api_version is version('1.40', '<') or docker_py_version is version('4.4.3', '<')
|
||||||
|
|||||||
@ -35,6 +35,7 @@ service_expected_output:
|
|||||||
- {mode: null, protocol: udp, published_port: 60001, target_port: 60001}
|
- {mode: null, protocol: udp, published_port: 60001, target_port: 60001}
|
||||||
read_only: null
|
read_only: null
|
||||||
replicas: null
|
replicas: null
|
||||||
|
replicas_max_per_node: null
|
||||||
reserve_cpu: null
|
reserve_cpu: null
|
||||||
reserve_memory: null
|
reserve_memory: null
|
||||||
restart_policy: null
|
restart_policy: null
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user