From 9860b78ce53f0f067a68f8a24c6bf488a10b0e81 Mon Sep 17 00:00:00 2001 From: Timo Tomasini Date: Mon, 3 Jan 2022 07:24:51 +0100 Subject: [PATCH] Fix podman_pod_lib behavior for ports published to multiple IPs (#359) * Fix podman_pod_lib behavior for ports published to multiple IPs * Fix IPv6 behavior for pods and add tests * Fix bind: cannot assign requested address issue with test container --- plugins/module_utils/podman/podman_pod_lib.py | 21 +++++++++++++------ .../targets/podman_pod/tasks/root-pod.yml | 2 ++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/plugins/module_utils/podman/podman_pod_lib.py b/plugins/module_utils/podman/podman_pod_lib.py index a3fd4ee..c0ced58 100644 --- a/plugins/module_utils/podman/podman_pod_lib.py +++ b/plugins/module_utils/podman/podman_pod_lib.py @@ -377,17 +377,26 @@ class PodmanPodDiff: # TODO(sshnaidm) Need to add port ranges support def diffparam_publish(self): + def compose(p, h): + s = ":".join( + [str(h["hostport"]), p.replace('/tcp', '')] + ).strip(":") + if h['hostip']: + return ":".join([h['hostip'], s]) + return s + if not self.infra_info: return self._diff_update_and_compare('publish', '', '') + ports = self.infra_info['hostconfig']['portbindings'] - before = [":".join([ - j[0]['hostip'], - str(j[0]["hostport"]), - i.replace('/tcp', '') - ]).strip(':') for i, j in ports.items()] + before = [] + for port, hosts in ports.items(): + if hosts: + for h in hosts: + before.append(compose(port, h)) after = self.params['publish'] or [] after = [ - i.replace("/tcp", "").replace("[", "").replace("]", "").strip(":") + i.replace("/tcp", "").replace("[", "").replace("]", "") for i in after] # No support for port ranges yet for ports in after: diff --git a/tests/integration/targets/podman_pod/tasks/root-pod.yml b/tests/integration/targets/podman_pod/tasks/root-pod.yml index 1a33041..015cb5e 100644 --- a/tests/integration/targets/podman_pod/tasks/root-pod.yml +++ b/tests/integration/targets/podman_pod/tasks/root-pod.yml @@ -115,6 +115,7 @@ - "4444:4444/tcp" - "8888:19191/udp" - "127.0.0.1:7671:7676/udp" + - "127.0.0.2:7671:7676/udp" - "127.0.0.1:13122:8871/tcp" - "127.0.0.1:43423:8872" - "[::1]:8743:8745" @@ -133,6 +134,7 @@ - "4444:4444/tcp" - "8888:19191/udp" - "127.0.0.1:7671:7676/udp" + - "127.0.0.2:7671:7676/udp" - "127.0.0.1:13122:8871/tcp" - "127.0.0.1:43423:8872" - "[::1]:8743:8745"