From 51cd9c991bab0473c5a0519995de7badb855f7aa Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 28 Jan 2019 19:10:50 +0100 Subject: [PATCH] [2.7] docker_swarm_service: Fix endpoint mode idempotency (#51370) * docker_swarm_service: Fix endpoint mode idempotency (#51232) * Fix endpoint mode idempotency * Remove newline (cherry picked from commit ee398534262972d90b2f8e6e8524daf31b84c8e1) * Add changelog. --- ...32-docker_swarm_service-endpoint_mode.yaml | 2 ++ .../cloud/docker/docker_swarm_service.py | 29 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) create mode 100644 changelogs/fragments/51232-docker_swarm_service-endpoint_mode.yaml diff --git a/changelogs/fragments/51232-docker_swarm_service-endpoint_mode.yaml b/changelogs/fragments/51232-docker_swarm_service-endpoint_mode.yaml new file mode 100644 index 00000000000..fb711647c33 --- /dev/null +++ b/changelogs/fragments/51232-docker_swarm_service-endpoint_mode.yaml @@ -0,0 +1,2 @@ +bugfixes: +- "docker_swarm_service - fix ``endpoint_mode`` and ``publish`` idempotency." diff --git a/lib/ansible/modules/cloud/docker/docker_swarm_service.py b/lib/ansible/modules/cloud/docker/docker_swarm_service.py index 0946c226bd3..4292689351f 100644 --- a/lib/ansible/modules/cloud/docker/docker_swarm_service.py +++ b/lib/ansible/modules/cloud/docker/docker_swarm_service.py @@ -104,11 +104,10 @@ options: - Dictionary of key value pairs. - Maps docker service --container-label option. endpoint_mode: - required: false + type: str description: - Service endpoint mode. - Maps docker service --endpoint-mode option. - default: vip choices: - vip - dnsrr @@ -494,7 +493,7 @@ class DockerService(DockerBaseClass): self.constraints = [] self.image = "" self.args = [] - self.endpoint_mode = "vip" + self.endpoint_mode = None self.dns = [] self.hostname = "" self.tty = False @@ -671,7 +670,7 @@ class DockerService(DockerBaseClass): differences = [] needs_rebuild = 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.append('endpoint_mode') if self.env != os.env: differences.append('env') @@ -931,17 +930,15 @@ class DockerServiceManager(): ds.restart_policy_attempts = restart_policy_data.get('MaxAttempts') ds.restart_policy_window = restart_policy_data.get('Window') - raw_data_endpoint = raw_data.get('Endpoint', None) - if raw_data_endpoint: - raw_data_endpoint_spec = raw_data_endpoint.get('Spec', None) - if raw_data_endpoint_spec: - ds.endpoint_mode = raw_data_endpoint_spec.get('Mode', 'vip') - for port in raw_data_endpoint_spec.get('Ports', []): - ds.publish.append({ - 'protocol': port['Protocol'], - 'mode': port.get('PublishMode', 'ingress'), - 'published_port': int(port['PublishedPort']), - 'target_port': int(port['TargetPort'])}) + raw_data_endpoint_spec = raw_data['Spec'].get('EndpointSpec') + if raw_data_endpoint_spec: + ds.endpoint_mode = raw_data_endpoint_spec.get('Mode') + for port in raw_data_endpoint_spec.get('Ports', []): + ds.publish.append({ + 'protocol': port['Protocol'], + 'mode': port.get('PublishMode', None), + 'published_port': int(port['PublishedPort']), + 'target_port': int(port['TargetPort'])}) if 'Resources' in task_template_data.keys(): if 'Limits' in task_template_data['Resources'].keys(): @@ -1162,7 +1159,7 @@ def main(): container_labels=dict(default={}, type='dict'), mode=dict(default="replicated"), 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']), limit_cpu=dict(default=0, type='float'), limit_memory=dict(default=0, type='str'),