Skip to content

Commit

Permalink
controlapi: Allow multiple randomly assigned published ports on service
Browse files Browse the repository at this point in the history
This fixes a 1.12.2 regression.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
  • Loading branch information
aaronlehmann committed Oct 18, 2016
1 parent ee5b04e commit 33c3a1a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions manager/controlapi/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ func validateEndpointSpec(epSpec *api.EndpointSpec) error {

portSet := make(map[portSpec]struct{})
for _, port := range epSpec.Ports {
if port.PublishedPort == 0 {
continue
}

portSpec := portSpec{publishedPort: port.PublishedPort, protocol: port.Protocol}
if _, ok := portSet[portSpec]; ok {
return grpc.Errorf(codes.InvalidArgument, "EndpointSpec: duplicate published ports provided")
Expand Down
47 changes: 47 additions & 0 deletions manager/controlapi/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,47 @@ func TestValidateEndpointSpec(t *testing.T) {
},
}

// duplicated published port but different protocols, valid
endPointSpec4 := &api.EndpointSpec{
Mode: api.ResolutionModeVirtualIP,
Ports: []*api.PortConfig{
{
Name: "dns",
TargetPort: 53,
PublishedPort: 8002,
Protocol: api.ProtocolTCP,
},
{
Name: "dns",
TargetPort: 53,
PublishedPort: 8002,
Protocol: api.ProtocolUDP,
},
},
}

// multiple randomly assigned published ports
endPointSpec5 := &api.EndpointSpec{
Mode: api.ResolutionModeVirtualIP,
Ports: []*api.PortConfig{
{
Name: "http",
TargetPort: 80,
Protocol: api.ProtocolTCP,
},
{
Name: "dns",
TargetPort: 53,
Protocol: api.ProtocolUDP,
},
{
Name: "dns",
TargetPort: 53,
Protocol: api.ProtocolTCP,
},
},
}

err := validateEndpointSpec(endPointSpec1)
assert.Error(t, err)
assert.Equal(t, codes.InvalidArgument, grpc.Code(err))
Expand All @@ -586,6 +627,12 @@ func TestValidateEndpointSpec(t *testing.T) {
err = validateEndpointSpec(endPointSpec3)
assert.Error(t, err)
assert.Equal(t, codes.InvalidArgument, grpc.Code(err))

err = validateEndpointSpec(endPointSpec4)
assert.NoError(t, err)

err = validateEndpointSpec(endPointSpec5)
assert.NoError(t, err)
}

func TestServiceEndpointSpecUpdate(t *testing.T) {
Expand Down

0 comments on commit 33c3a1a

Please sign in to comment.