fix: docker_swarm_service does not publish both tcp and udp ports (#60616)
* fix: docker_swarm_service does not publish both tcp and udp ports for same published port * fix the linting problems and add the changelog fragment. * add test * modify test to ensure result rather than return value
This commit is contained in:
parent
48541910bf
commit
064cd63f3d
3 changed files with 34 additions and 11 deletions
2
changelogs/fragments/60616-support-multiple-port.yaml
Normal file
2
changelogs/fragments/60616-support-multiple-port.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "docker_swarm_service - allow the same port to be published both with TCP and UDP."
|
|
@ -2028,19 +2028,16 @@ class DockerService(DockerBaseClass):
|
||||||
def build_endpoint_spec(self):
|
def build_endpoint_spec(self):
|
||||||
endpoint_spec_args = {}
|
endpoint_spec_args = {}
|
||||||
if self.publish is not None:
|
if self.publish is not None:
|
||||||
ports = {}
|
ports = []
|
||||||
for port in self.publish:
|
for port in self.publish:
|
||||||
|
port_spec = {
|
||||||
|
'Protocol': port['protocol'],
|
||||||
|
'PublishedPort': port['published_port'],
|
||||||
|
'TargetPort': port['target_port']
|
||||||
|
}
|
||||||
if port.get('mode'):
|
if port.get('mode'):
|
||||||
ports[port['published_port']] = (
|
port_spec['PublishMode'] = port['mode']
|
||||||
port['target_port'],
|
ports.append(port_spec)
|
||||||
port['protocol'],
|
|
||||||
port['mode'],
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
ports[port['published_port']] = (
|
|
||||||
port['target_port'],
|
|
||||||
port['protocol'],
|
|
||||||
)
|
|
||||||
endpoint_spec_args['ports'] = ports
|
endpoint_spec_args['ports'] = ports
|
||||||
if self.endpoint_mode is not None:
|
if self.endpoint_mode is not None:
|
||||||
endpoint_spec_args['mode'] = self.endpoint_mode
|
endpoint_spec_args['mode'] = self.endpoint_mode
|
||||||
|
|
|
@ -1590,6 +1590,28 @@
|
||||||
register: publish_7
|
register: publish_7
|
||||||
ignore_errors: yes
|
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
|
- name: cleanup
|
||||||
docker_swarm_service:
|
docker_swarm_service:
|
||||||
name: "{{ service_name }}"
|
name: "{{ service_name }}"
|
||||||
|
@ -1605,6 +1627,8 @@
|
||||||
- publish_5 is not changed
|
- publish_5 is not changed
|
||||||
- publish_6 is changed
|
- publish_6 is changed
|
||||||
- publish_7 is not 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', '>=')
|
when: docker_api_version is version('1.25', '>=') and docker_py_version is version('3.0.0', '>=')
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
|
|
Loading…
Reference in a new issue