mirror of https://github.com/docker/cli.git
Merge pull request #404 from thaJeztah/fix-port-presentation
Fix presentation of published "random" host ports
This commit is contained in:
commit
772956b263
|
@ -518,11 +518,11 @@ func (c *serviceContext) Image() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *serviceContext) Ports() string {
|
func (c *serviceContext) Ports() string {
|
||||||
if c.service.Spec.EndpointSpec == nil || c.service.Spec.EndpointSpec.Ports == nil {
|
if c.service.Endpoint.Ports == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
ports := []string{}
|
ports := []string{}
|
||||||
for _, pConfig := range c.service.Spec.EndpointSpec.Ports {
|
for _, pConfig := range c.service.Endpoint.Ports {
|
||||||
if pConfig.PublishMode == swarm.PortConfigPublishModeIngress {
|
if pConfig.PublishMode == swarm.PortConfigPublishModeIngress {
|
||||||
ports = append(ports, fmt.Sprintf("*:%d->%d/%s",
|
ports = append(ports, fmt.Sprintf("*:%d->%d/%s",
|
||||||
pConfig.PublishedPort,
|
pConfig.PublishedPort,
|
||||||
|
|
|
@ -96,14 +96,14 @@ bar
|
||||||
ID: "id_baz",
|
ID: "id_baz",
|
||||||
Spec: swarm.ServiceSpec{
|
Spec: swarm.ServiceSpec{
|
||||||
Annotations: swarm.Annotations{Name: "baz"},
|
Annotations: swarm.Annotations{Name: "baz"},
|
||||||
EndpointSpec: &swarm.EndpointSpec{
|
},
|
||||||
Ports: []swarm.PortConfig{
|
Endpoint: swarm.Endpoint{
|
||||||
{
|
Ports: []swarm.PortConfig{
|
||||||
PublishMode: "ingress",
|
{
|
||||||
PublishedPort: 80,
|
PublishMode: "ingress",
|
||||||
TargetPort: 8080,
|
PublishedPort: 80,
|
||||||
Protocol: "tcp",
|
TargetPort: 8080,
|
||||||
},
|
Protocol: "tcp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -112,14 +112,14 @@ bar
|
||||||
ID: "id_bar",
|
ID: "id_bar",
|
||||||
Spec: swarm.ServiceSpec{
|
Spec: swarm.ServiceSpec{
|
||||||
Annotations: swarm.Annotations{Name: "bar"},
|
Annotations: swarm.Annotations{Name: "bar"},
|
||||||
EndpointSpec: &swarm.EndpointSpec{
|
},
|
||||||
Ports: []swarm.PortConfig{
|
Endpoint: swarm.Endpoint{
|
||||||
{
|
Ports: []swarm.PortConfig{
|
||||||
PublishMode: "ingress",
|
{
|
||||||
PublishedPort: 80,
|
PublishMode: "ingress",
|
||||||
TargetPort: 8080,
|
PublishedPort: 80,
|
||||||
Protocol: "tcp",
|
TargetPort: 8080,
|
||||||
},
|
Protocol: "tcp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -152,14 +152,14 @@ func TestServiceContextWriteJSON(t *testing.T) {
|
||||||
ID: "id_baz",
|
ID: "id_baz",
|
||||||
Spec: swarm.ServiceSpec{
|
Spec: swarm.ServiceSpec{
|
||||||
Annotations: swarm.Annotations{Name: "baz"},
|
Annotations: swarm.Annotations{Name: "baz"},
|
||||||
EndpointSpec: &swarm.EndpointSpec{
|
},
|
||||||
Ports: []swarm.PortConfig{
|
Endpoint: swarm.Endpoint{
|
||||||
{
|
Ports: []swarm.PortConfig{
|
||||||
PublishMode: "ingress",
|
{
|
||||||
PublishedPort: 80,
|
PublishMode: "ingress",
|
||||||
TargetPort: 8080,
|
PublishedPort: 80,
|
||||||
Protocol: "tcp",
|
TargetPort: 8080,
|
||||||
},
|
Protocol: "tcp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -168,14 +168,14 @@ func TestServiceContextWriteJSON(t *testing.T) {
|
||||||
ID: "id_bar",
|
ID: "id_bar",
|
||||||
Spec: swarm.ServiceSpec{
|
Spec: swarm.ServiceSpec{
|
||||||
Annotations: swarm.Annotations{Name: "bar"},
|
Annotations: swarm.Annotations{Name: "bar"},
|
||||||
EndpointSpec: &swarm.EndpointSpec{
|
},
|
||||||
Ports: []swarm.PortConfig{
|
Endpoint: swarm.Endpoint{
|
||||||
{
|
Ports: []swarm.PortConfig{
|
||||||
PublishMode: "ingress",
|
{
|
||||||
PublishedPort: 80,
|
PublishMode: "ingress",
|
||||||
TargetPort: 8080,
|
PublishedPort: 80,
|
||||||
Protocol: "tcp",
|
TargetPort: 8080,
|
||||||
},
|
Protocol: "tcp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
ID NAME MODE REPLICAS IMAGE PORTS
|
ID NAME MODE REPLICAS IMAGE PORTS
|
||||||
id-foo name-foo replicated 0/2 busybox:latest *:0->3232/tcp
|
id-foo name-foo replicated 0/2 busybox:latest *:30000->3232/tcp
|
||||||
|
|
|
@ -64,5 +64,11 @@ func ServiceImage(image string) func(*swarm.Service) {
|
||||||
func ServicePort(port swarm.PortConfig) func(*swarm.Service) {
|
func ServicePort(port swarm.PortConfig) func(*swarm.Service) {
|
||||||
return func(service *swarm.Service) {
|
return func(service *swarm.Service) {
|
||||||
service.Spec.EndpointSpec.Ports = append(service.Spec.EndpointSpec.Ports, port)
|
service.Spec.EndpointSpec.Ports = append(service.Spec.EndpointSpec.Ports, port)
|
||||||
|
|
||||||
|
assignedPort := port
|
||||||
|
if assignedPort.PublishedPort == 0 {
|
||||||
|
assignedPort.PublishedPort = 30000
|
||||||
|
}
|
||||||
|
service.Endpoint.Ports = append(service.Endpoint.Ports, assignedPort)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue