@@ -10,6 +10,7 @@ import (
1010 "strings"
1111
1212 "github.com/docker/go-connections/nat"
13+ "github.com/moby/moby/api/types/container"
1314 "github.com/moby/moby/api/types/swarm"
1415 "github.com/sirupsen/logrus"
1516)
@@ -150,28 +151,31 @@ func (p *PortOpt) Value() []swarm.PortConfig {
150151
151152// ConvertPortToPortConfig converts ports to the swarm type
152153func ConvertPortToPortConfig (
153- port nat. Port ,
154- portBindings map [nat. Port ][]nat .PortBinding ,
154+ portRangeProto container. PortRangeProto ,
155+ portBindings map [container. PortRangeProto ][]container .PortBinding ,
155156) ([]swarm.PortConfig , error ) {
156- ports := []swarm.PortConfig {}
157+ proto , port := nat .SplitProtoPort (string (portRangeProto ))
158+ portInt , _ := strconv .ParseUint (port , 10 , 16 )
159+ proto = strings .ToLower (proto )
157160
158- for _ , binding := range portBindings [port ] {
161+ var ports []swarm.PortConfig
162+ for _ , binding := range portBindings [portRangeProto ] {
159163 if p := net .ParseIP (binding .HostIP ); p != nil && ! p .IsUnspecified () {
160164 // TODO(thaJeztah): use context-logger, so that this output can be suppressed (in tests).
161- logrus .Warnf ("ignoring IP-address (%s:%s) service will listen on '0.0.0.0'" , net .JoinHostPort (binding .HostIP , binding .HostPort ), port )
165+ logrus .Warnf ("ignoring IP-address (%s:%s) service will listen on '0.0.0.0'" , net .JoinHostPort (binding .HostIP , binding .HostPort ), portRangeProto )
162166 }
163167
164168 startHostPort , endHostPort , err := nat .ParsePortRange (binding .HostPort )
165169
166170 if err != nil && binding .HostPort != "" {
167- return nil , fmt .Errorf ("invalid hostport binding (%s) for port (%s)" , binding .HostPort , port . Port () )
171+ return nil , fmt .Errorf ("invalid hostport binding (%s) for port (%s)" , binding .HostPort , port )
168172 }
169173
170174 for i := startHostPort ; i <= endHostPort ; i ++ {
171175 ports = append (ports , swarm.PortConfig {
172176 // TODO Name: ?
173- Protocol : swarm .PortConfigProtocol (strings . ToLower ( port . Proto ()) ),
174- TargetPort : uint32 (port . Int () ),
177+ Protocol : swarm .PortConfigProtocol (proto ),
178+ TargetPort : uint32 (portInt ),
175179 PublishedPort : uint32 (i ),
176180 PublishMode : swarm .PortConfigPublishModeIngress ,
177181 })
0 commit comments