1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

docker_swarm_service: Fix endpoint mode idempotency (#51232)

* Fix endpoint mode idempotency

* Remove newline
This commit is contained in:
Hannes Ljungberg 2019-01-27 15:06:09 +01:00 committed by ansibot
parent 9f5a251e25
commit ee39853426
2 changed files with 27 additions and 38 deletions

View file

@ -117,11 +117,10 @@ options:
- Dictionary of key value pairs. - Dictionary of key value pairs.
- Maps docker service --container-label option. - Maps docker service --container-label option.
endpoint_mode: endpoint_mode:
required: false type: str
description: description:
- Service endpoint mode. - Service endpoint mode.
- Maps docker service --endpoint-mode option. - Maps docker service --endpoint-mode option.
default: vip
choices: choices:
- vip - vip
- dnsrr - dnsrr
@ -542,7 +541,7 @@ class DockerService(DockerBaseClass):
self.image = "" self.image = ""
self.command = None self.command = None
self.args = [] self.args = []
self.endpoint_mode = "vip" self.endpoint_mode = None
self.dns = [] self.dns = []
self.hostname = "" self.hostname = ""
self.tty = False self.tty = False
@ -755,7 +754,7 @@ class DockerService(DockerBaseClass):
differences = DifferenceTracker() differences = DifferenceTracker()
needs_rebuild = False needs_rebuild = False
force_update = False force_update = False
if self.endpoint_mode != os.endpoint_mode: if self.endpoint_mode is not None and self.endpoint_mode != os.endpoint_mode:
differences.add('endpoint_mode', parameter=self.endpoint_mode, active=os.endpoint_mode) differences.add('endpoint_mode', parameter=self.endpoint_mode, active=os.endpoint_mode)
if self.env != os.env: if self.env != os.env:
differences.add('env', parameter=self.env, active=os.env) differences.add('env', parameter=self.env, active=os.env)
@ -1072,17 +1071,15 @@ class DockerServiceManager():
ds.restart_policy_attempts = restart_policy_data.get('MaxAttempts') ds.restart_policy_attempts = restart_policy_data.get('MaxAttempts')
ds.restart_policy_window = restart_policy_data.get('Window') ds.restart_policy_window = restart_policy_data.get('Window')
raw_data_endpoint = raw_data.get('Endpoint', None) raw_data_endpoint_spec = raw_data['Spec'].get('EndpointSpec')
if raw_data_endpoint: if raw_data_endpoint_spec:
raw_data_endpoint_spec = raw_data_endpoint.get('Spec', None) ds.endpoint_mode = raw_data_endpoint_spec.get('Mode')
if raw_data_endpoint_spec: for port in raw_data_endpoint_spec.get('Ports', []):
ds.endpoint_mode = raw_data_endpoint_spec.get('Mode', 'vip') ds.publish.append({
for port in raw_data_endpoint_spec.get('Ports', []): 'protocol': port['Protocol'],
ds.publish.append({ 'mode': port.get('PublishMode', None),
'protocol': port['Protocol'], 'published_port': int(port['PublishedPort']),
'mode': port.get('PublishMode', None), 'target_port': int(port['TargetPort'])})
'published_port': int(port['PublishedPort']),
'target_port': int(port['TargetPort'])})
if 'Resources' in task_template_data.keys(): if 'Resources' in task_template_data.keys():
if 'Limits' in task_template_data['Resources'].keys(): if 'Limits' in task_template_data['Resources'].keys():
@ -1288,7 +1285,7 @@ def main():
container_labels=dict(default={}, type='dict'), container_labels=dict(default={}, type='dict'),
mode=dict(default="replicated"), mode=dict(default="replicated"),
replicas=dict(default=-1, type='int'), replicas=dict(default=-1, type='int'),
endpoint_mode=dict(default='vip', choices=['vip', 'dnsrr']), endpoint_mode=dict(default=None, choices=['vip', 'dnsrr']),
restart_policy=dict(default='none', choices=['none', 'on-failure', 'any']), restart_policy=dict(default='none', choices=['none', 'on-failure', 'any']),
limit_cpu=dict(default=0, type='float'), limit_cpu=dict(default=0, type='float'),
limit_memory=dict(default=0, type='str'), limit_memory=dict(default=0, type='str'),

View file

@ -494,14 +494,6 @@
## endpoint_mode ################################################### ## endpoint_mode ###################################################
#################################################################### ####################################################################
# FIXME: endpoint_mode_2 is not marked as changed
#fatal: [testhost]: FAILED! => {
# "assertion": "endpoint_mode_2 is not changed",
# "changed": false,
# "evaluated_to": false,
# "msg": "Assertion failed"
#}
- name: endpoint_mode - name: endpoint_mode
docker_swarm_service: docker_swarm_service:
name: "{{ service_name }}" name: "{{ service_name }}"
@ -509,19 +501,19 @@
endpoint_mode: "dnsrr" endpoint_mode: "dnsrr"
register: endpoint_mode_1 register: endpoint_mode_1
#- name: endpoint_mode (idempotency) - name: endpoint_mode (idempotency)
# docker_swarm_service: docker_swarm_service:
# name: "{{ service_name }}" name: "{{ service_name }}"
# image: alpine:3.8 image: alpine:3.8
# endpoint_mode: "dnsrr" endpoint_mode: "dnsrr"
# register: endpoint_mode_2 register: endpoint_mode_2
#- name: endpoint_mode (changes) - name: endpoint_mode (changes)
# docker_swarm_service: docker_swarm_service:
# name: "{{ service_name }}" name: "{{ service_name }}"
# image: alpine:3.8 image: alpine:3.8
# endpoint_mode: "vip" endpoint_mode: "vip"
# register: endpoint_mode_3 register: endpoint_mode_3
- name: cleanup - name: cleanup
docker_swarm_service: docker_swarm_service:
@ -532,8 +524,8 @@
- assert: - assert:
that: that:
- endpoint_mode_1 is changed - endpoint_mode_1 is changed
# - endpoint_mode_2 is not changed - endpoint_mode_2 is not changed
# - endpoint_mode_3 is changed - endpoint_mode_3 is changed
#################################################################### ####################################################################
## env ############################################################# ## env #############################################################