Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: docker_swarm_service does not publish both tcp and udp ports #60616

Merged
merged 4 commits into from Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/60616-support-multiple-port.yaml
@@ -0,0 +1,2 @@
bugfixes:
- "docker_swarm_service - allow the same port to be published both with TCP and UDP."
19 changes: 8 additions & 11 deletions lib/ansible/modules/cloud/docker/docker_swarm_service.py
Expand Up @@ -2028,19 +2028,16 @@ def build_networks(self, docker_networks):
def build_endpoint_spec(self):
endpoint_spec_args = {}
if self.publish is not None:
ports = {}
ports = []
for port in self.publish:
port_spec = {
'Protocol': port['protocol'],
'PublishedPort': port['published_port'],
'TargetPort': port['target_port']
}
if port.get('mode'):
ports[port['published_port']] = (
port['target_port'],
port['protocol'],
port['mode'],
)
else:
ports[port['published_port']] = (
port['target_port'],
port['protocol'],
)
port_spec['PublishMode'] = port['mode']
ports.append(port_spec)
endpoint_spec_args['ports'] = ports
if self.endpoint_mode is not None:
endpoint_spec_args['mode'] = self.endpoint_mode
Expand Down
Expand Up @@ -1590,6 +1590,28 @@
register: publish_7
ignore_errors: yes

- name: publish (publishes the same port with both protocols)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
resolve_image: no
command: '/bin/sh -v -c "sleep 10m"'
publish:
- protocol: udp
published_port: 60001
target_port: 60001
mode: host
- protocol: tcp
published_port: 60001
target_port: 60001
mode: host
register: publish_8
ignore_errors: yes
- name: gather service info
docker_swarm_service_info:
name: "{{ service_name }}"
register: publish_8_info

- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
Expand All @@ -1605,6 +1627,8 @@
- publish_5 is not changed
- publish_6 is changed
- publish_7 is not changed
- publish_8 is changed
- (publish_8_info.service.Endpoint.Ports | length) == 2
when: docker_api_version is version('1.25', '>=') and docker_py_version is version('3.0.0', '>=')
- assert:
that:
Expand Down