This fix tries to address the issue raised in docker/docker-29730
where a service with multiple published ports mapping to the same target
port (e.g., `--publish 5000:80 --publish 5001:80`) can't be allocated.
The reason for the issue is that, `getPortConfigKey` is used for both
allocated ports and configured (may or may not be allocated) ports.
However, `getPortConfigKey` will not take into consideration the
`PublishedPort` field, which actually could be different for different
allocated ports.
This fix saves a map of `portKey:portNum:portState`, instead of currently
used `portKey:portState` so that multiple published ports could be processed.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
| ... | ... |
@@ -1572,3 +1572,22 @@ func (s *DockerSwarmSuite) TestSwarmServicePsMultipleServiceIDs(c *check.C) {
|
| 1572 | 1572 |
c.Assert(out, checker.Contains, name2+".2") |
| 1573 | 1573 |
c.Assert(out, checker.Contains, name2+".3") |
| 1574 | 1574 |
} |
| 1575 |
+ |
|
| 1576 |
+func (s *DockerSwarmSuite) TestSwarmPublishDuplicatePorts(c *check.C) {
|
|
| 1577 |
+ d := s.AddDaemon(c, true, true) |
|
| 1578 |
+ |
|
| 1579 |
+ out, err := d.Cmd("service", "create", "--publish", "5000:80", "--publish", "5001:80", "--publish", "80", "--publish", "80", "busybox", "top")
|
|
| 1580 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 1581 |
+ id := strings.TrimSpace(out) |
|
| 1582 |
+ |
|
| 1583 |
+ // make sure task has been deployed. |
|
| 1584 |
+ waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, 1) |
|
| 1585 |
+ |
|
| 1586 |
+ // Total len = 4, with 2 dynamic ports and 2 non-dynamic ports |
|
| 1587 |
+ // Dynamic ports are likely to be 30000 and 30001 but doesn't matter |
|
| 1588 |
+ out, err = d.Cmd("service", "inspect", "--format", "{{.Endpoint.Ports}} len={{len .Endpoint.Ports}}", id)
|
|
| 1589 |
+ c.Assert(err, check.IsNil, check.Commentf(out)) |
|
| 1590 |
+ c.Assert(out, checker.Contains, "len=4") |
|
| 1591 |
+ c.Assert(out, checker.Contains, "{ tcp 80 5000 ingress}")
|
|
| 1592 |
+ c.Assert(out, checker.Contains, "{ tcp 80 5001 ingress}")
|
|
| 1593 |
+} |