summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-07-29 16:10:08 -0400
committerGitHub <noreply@github.com>2020-07-29 16:10:08 -0400
commitd5ce1cd647a50f879d59e2bebc9299e95e4e06e7 (patch)
treee14594c554ae677494eca4a0b7ce78c34cca4c56
parenteaa2f524c25e5022f9c6697dd97a889048dc2d58 (diff)
parentecefdab3d98c1a3b75a8ba39052d897a36bf191d (diff)
downloadpodman-d5ce1cd647a50f879d59e2bebc9299e95e4e06e7.tar.gz
podman-d5ce1cd647a50f879d59e2bebc9299e95e4e06e7.tar.bz2
podman-d5ce1cd647a50f879d59e2bebc9299e95e4e06e7.zip
Merge pull request #7074 from mheon/multi_ctrport_ok
Binding the same container port to >1 host port is OK
-rw-r--r--pkg/specgen/generate/ports.go15
-rw-r--r--test/e2e/run_networking_test.go16
2 files changed, 24 insertions, 7 deletions
diff --git a/pkg/specgen/generate/ports.go b/pkg/specgen/generate/ports.go
index 1ad7e6f4d..7dd50ac0d 100644
--- a/pkg/specgen/generate/ports.go
+++ b/pkg/specgen/generate/ports.go
@@ -123,19 +123,20 @@ func parsePortMapping(portMappings []specgen.PortMapping) ([]ocicni.PortMapping,
postAssignHostPort = true
}
} else {
- testCPort := ctrPortMap[cPort]
- if testCPort != 0 && testCPort != hPort {
- // This is an attempt to redefine a port
- return nil, nil, nil, errors.Errorf("conflicting port mappings for container port %d (protocol %s)", cPort, p)
- }
- ctrPortMap[cPort] = hPort
-
testHPort := hostPortMap[hPort]
if testHPort != 0 && testHPort != cPort {
return nil, nil, nil, errors.Errorf("conflicting port mappings for host port %d (protocol %s)", hPort, p)
}
hostPortMap[hPort] = cPort
+ // Mapping a container port to multiple
+ // host ports is allowed.
+ // We only store the latest of these in
+ // the container port map - we don't
+ // need to know all of them, just one.
+ testCPort := ctrPortMap[cPort]
+ ctrPortMap[cPort] = hPort
+
// If we have an exact duplicate, just continue
if testCPort == hPort && testHPort == cPort {
continue
diff --git a/test/e2e/run_networking_test.go b/test/e2e/run_networking_test.go
index bf96db197..87b74052a 100644
--- a/test/e2e/run_networking_test.go
+++ b/test/e2e/run_networking_test.go
@@ -220,6 +220,22 @@ var _ = Describe("Podman run networking", func() {
Expect(inspectOut[0].NetworkSettings.Ports["8080/tcp"][0].HostIP).To(Equal(""))
})
+ It("podman run -p 8080:8080 -p 8081:8080", func() {
+ name := "testctr"
+ session := podmanTest.Podman([]string{"create", "-t", "-p", "4000:8080", "-p", "8000:8080", "--name", name, ALPINE, "/bin/sh"})
+ session.WaitWithDefaultTimeout()
+ inspectOut := podmanTest.InspectContainer(name)
+ Expect(len(inspectOut)).To(Equal(1))
+ Expect(len(inspectOut[0].NetworkSettings.Ports)).To(Equal(1))
+ Expect(len(inspectOut[0].NetworkSettings.Ports["8080/tcp"])).To(Equal(2))
+
+ hp1 := inspectOut[0].NetworkSettings.Ports["8080/tcp"][0].HostPort
+ hp2 := inspectOut[0].NetworkSettings.Ports["8080/tcp"][1].HostPort
+
+ // We can't guarantee order
+ Expect((hp1 == "4000" && hp2 == "8000") || (hp1 == "8000" && hp2 == "4000")).To(BeTrue())
+ })
+
It("podman run network expose host port 80 to container port 8000", func() {
SkipIfRootless()
session := podmanTest.Podman([]string{"run", "-dt", "-p", "80:8000", ALPINE, "/bin/sh"})