Make --publish-rm precedes --publish-add, so that add wins

`--publish-add 8081:81 --publish-add 8082:82 --publish-rm 80
--publish-rm 81/tcp --publish-rm 82/tcp` would thus result in 81 and
82 to be published.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2016-12-09 21:17:57 +01:00
parent 016a56b064
commit 16bbd3441a
2 changed files with 30 additions and 5 deletions

View File

@ -82,6 +82,14 @@ func (p *PortOpt) Set(value string) error {
return fmt.Errorf("missing mandatory field %q", portOptTargetPort) return fmt.Errorf("missing mandatory field %q", portOptTargetPort)
} }
if pConfig.PublishMode == "" {
pConfig.PublishMode = swarm.PortConfigPublishModeIngress
}
if pConfig.Protocol == "" {
pConfig.Protocol = swarm.PortConfigProtocolTCP
}
p.ports = append(p.ports, pConfig) p.ports = append(p.ports, pConfig)
} else { } else {
// short syntax // short syntax
@ -131,6 +139,7 @@ func ConvertPortToPortConfig(
Protocol: swarm.PortConfigProtocol(strings.ToLower(port.Proto())), Protocol: swarm.PortConfigProtocol(strings.ToLower(port.Proto())),
TargetPort: uint32(port.Int()), TargetPort: uint32(port.Int()),
PublishedPort: uint32(hostPort), PublishedPort: uint32(hostPort),
PublishMode: swarm.PortConfigPublishModeIngress,
}) })
} }
return ports return ports

View File

@ -18,6 +18,7 @@ func TestPortOptValidSimpleSyntax(t *testing.T) {
{ {
Protocol: "tcp", Protocol: "tcp",
TargetPort: 80, TargetPort: 80,
PublishMode: swarm.PortConfigPublishModeIngress,
}, },
}, },
}, },
@ -28,6 +29,7 @@ func TestPortOptValidSimpleSyntax(t *testing.T) {
Protocol: "tcp", Protocol: "tcp",
TargetPort: 8080, TargetPort: 8080,
PublishedPort: 80, PublishedPort: 80,
PublishMode: swarm.PortConfigPublishModeIngress,
}, },
}, },
}, },
@ -38,6 +40,7 @@ func TestPortOptValidSimpleSyntax(t *testing.T) {
Protocol: "tcp", Protocol: "tcp",
TargetPort: 80, TargetPort: 80,
PublishedPort: 8080, PublishedPort: 8080,
PublishMode: swarm.PortConfigPublishModeIngress,
}, },
}, },
}, },
@ -48,6 +51,7 @@ func TestPortOptValidSimpleSyntax(t *testing.T) {
Protocol: "udp", Protocol: "udp",
TargetPort: 8080, TargetPort: 8080,
PublishedPort: 80, PublishedPort: 80,
PublishMode: swarm.PortConfigPublishModeIngress,
}, },
}, },
}, },
@ -58,11 +62,13 @@ func TestPortOptValidSimpleSyntax(t *testing.T) {
Protocol: "tcp", Protocol: "tcp",
TargetPort: 8080, TargetPort: 8080,
PublishedPort: 80, PublishedPort: 80,
PublishMode: swarm.PortConfigPublishModeIngress,
}, },
{ {
Protocol: "tcp", Protocol: "tcp",
TargetPort: 8081, TargetPort: 8081,
PublishedPort: 81, PublishedPort: 81,
PublishMode: swarm.PortConfigPublishModeIngress,
}, },
}, },
}, },
@ -73,16 +79,19 @@ func TestPortOptValidSimpleSyntax(t *testing.T) {
Protocol: "udp", Protocol: "udp",
TargetPort: 8080, TargetPort: 8080,
PublishedPort: 80, PublishedPort: 80,
PublishMode: swarm.PortConfigPublishModeIngress,
}, },
{ {
Protocol: "udp", Protocol: "udp",
TargetPort: 8081, TargetPort: 8081,
PublishedPort: 81, PublishedPort: 81,
PublishMode: swarm.PortConfigPublishModeIngress,
}, },
{ {
Protocol: "udp", Protocol: "udp",
TargetPort: 8082, TargetPort: 8082,
PublishedPort: 82, PublishedPort: 82,
PublishMode: swarm.PortConfigPublishModeIngress,
}, },
}, },
}, },
@ -107,6 +116,8 @@ func TestPortOptValidComplexSyntax(t *testing.T) {
expected: []swarm.PortConfig{ expected: []swarm.PortConfig{
{ {
TargetPort: 80, TargetPort: 80,
Protocol: "tcp",
PublishMode: swarm.PortConfigPublishModeIngress,
}, },
}, },
}, },
@ -116,6 +127,7 @@ func TestPortOptValidComplexSyntax(t *testing.T) {
{ {
Protocol: "tcp", Protocol: "tcp",
TargetPort: 80, TargetPort: 80,
PublishMode: swarm.PortConfigPublishModeIngress,
}, },
}, },
}, },
@ -126,6 +138,7 @@ func TestPortOptValidComplexSyntax(t *testing.T) {
Protocol: "tcp", Protocol: "tcp",
TargetPort: 80, TargetPort: 80,
PublishedPort: 8080, PublishedPort: 8080,
PublishMode: swarm.PortConfigPublishModeIngress,
}, },
}, },
}, },
@ -136,6 +149,7 @@ func TestPortOptValidComplexSyntax(t *testing.T) {
Protocol: "tcp", Protocol: "tcp",
TargetPort: 8080, TargetPort: 8080,
PublishedPort: 80, PublishedPort: 80,
PublishMode: swarm.PortConfigPublishModeIngress,
}, },
}, },
}, },
@ -157,6 +171,7 @@ func TestPortOptValidComplexSyntax(t *testing.T) {
TargetPort: 80, TargetPort: 80,
PublishedPort: 8080, PublishedPort: 8080,
PublishMode: "host", PublishMode: "host",
Protocol: "tcp",
}, },
}, },
}, },
@ -167,6 +182,7 @@ func TestPortOptValidComplexSyntax(t *testing.T) {
TargetPort: 80, TargetPort: 80,
PublishedPort: 8080, PublishedPort: 8080,
PublishMode: "ingress", PublishMode: "ingress",
Protocol: "tcp",
}, },
}, },
}, },