From 16bbd3441ade6495352faa5ac4442e92b1f633d7 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Fri, 9 Dec 2016 21:17:57 +0100 Subject: [PATCH] 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 --- opts/port.go | 9 +++++++++ opts/port_test.go | 26 +++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/opts/port.go b/opts/port.go index e1c4449a38..020a5d1e1c 100644 --- a/opts/port.go +++ b/opts/port.go @@ -82,6 +82,14 @@ func (p *PortOpt) Set(value string) error { 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) } else { // short syntax @@ -131,6 +139,7 @@ func ConvertPortToPortConfig( Protocol: swarm.PortConfigProtocol(strings.ToLower(port.Proto())), TargetPort: uint32(port.Int()), PublishedPort: uint32(hostPort), + PublishMode: swarm.PortConfigPublishModeIngress, }) } return ports diff --git a/opts/port_test.go b/opts/port_test.go index 8046b4428e..67bcf8f1d9 100644 --- a/opts/port_test.go +++ b/opts/port_test.go @@ -16,8 +16,9 @@ func TestPortOptValidSimpleSyntax(t *testing.T) { value: "80", expected: []swarm.PortConfig{ { - Protocol: "tcp", - TargetPort: 80, + Protocol: "tcp", + TargetPort: 80, + PublishMode: swarm.PortConfigPublishModeIngress, }, }, }, @@ -28,6 +29,7 @@ func TestPortOptValidSimpleSyntax(t *testing.T) { Protocol: "tcp", TargetPort: 8080, PublishedPort: 80, + PublishMode: swarm.PortConfigPublishModeIngress, }, }, }, @@ -38,6 +40,7 @@ func TestPortOptValidSimpleSyntax(t *testing.T) { Protocol: "tcp", TargetPort: 80, PublishedPort: 8080, + PublishMode: swarm.PortConfigPublishModeIngress, }, }, }, @@ -48,6 +51,7 @@ func TestPortOptValidSimpleSyntax(t *testing.T) { Protocol: "udp", TargetPort: 8080, PublishedPort: 80, + PublishMode: swarm.PortConfigPublishModeIngress, }, }, }, @@ -58,11 +62,13 @@ func TestPortOptValidSimpleSyntax(t *testing.T) { Protocol: "tcp", TargetPort: 8080, PublishedPort: 80, + PublishMode: swarm.PortConfigPublishModeIngress, }, { Protocol: "tcp", TargetPort: 8081, PublishedPort: 81, + PublishMode: swarm.PortConfigPublishModeIngress, }, }, }, @@ -73,16 +79,19 @@ func TestPortOptValidSimpleSyntax(t *testing.T) { Protocol: "udp", TargetPort: 8080, PublishedPort: 80, + PublishMode: swarm.PortConfigPublishModeIngress, }, { Protocol: "udp", TargetPort: 8081, PublishedPort: 81, + PublishMode: swarm.PortConfigPublishModeIngress, }, { Protocol: "udp", TargetPort: 8082, PublishedPort: 82, + PublishMode: swarm.PortConfigPublishModeIngress, }, }, }, @@ -106,7 +115,9 @@ func TestPortOptValidComplexSyntax(t *testing.T) { value: "target=80", expected: []swarm.PortConfig{ { - TargetPort: 80, + TargetPort: 80, + Protocol: "tcp", + PublishMode: swarm.PortConfigPublishModeIngress, }, }, }, @@ -114,8 +125,9 @@ func TestPortOptValidComplexSyntax(t *testing.T) { value: "target=80,protocol=tcp", expected: []swarm.PortConfig{ { - Protocol: "tcp", - TargetPort: 80, + Protocol: "tcp", + TargetPort: 80, + PublishMode: swarm.PortConfigPublishModeIngress, }, }, }, @@ -126,6 +138,7 @@ func TestPortOptValidComplexSyntax(t *testing.T) { Protocol: "tcp", TargetPort: 80, PublishedPort: 8080, + PublishMode: swarm.PortConfigPublishModeIngress, }, }, }, @@ -136,6 +149,7 @@ func TestPortOptValidComplexSyntax(t *testing.T) { Protocol: "tcp", TargetPort: 8080, PublishedPort: 80, + PublishMode: swarm.PortConfigPublishModeIngress, }, }, }, @@ -157,6 +171,7 @@ func TestPortOptValidComplexSyntax(t *testing.T) { TargetPort: 80, PublishedPort: 8080, PublishMode: "host", + Protocol: "tcp", }, }, }, @@ -167,6 +182,7 @@ func TestPortOptValidComplexSyntax(t *testing.T) { TargetPort: 80, PublishedPort: 8080, PublishMode: "ingress", + Protocol: "tcp", }, }, },