Skip to content

Commit

Permalink
Merge pull request #1952 from aboch/ph
Browse files Browse the repository at this point in the history
Fix portsAllocatedInHostPublishMode
  • Loading branch information
aaronlehmann authored Feb 15, 2017
2 parents b69b46a + 48b7c7f commit 03d5b15
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 1 deletion.
3 changes: 2 additions & 1 deletion manager/allocator/networkallocator/portallocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ func (pa *portAllocator) portsAllocatedInHostPublishMode(s *api.Service) bool {

if s.Spec.Endpoint != nil {
for _, portConfig := range s.Spec.Endpoint.Ports {
if portConfig.PublishMode == api.PublishModeHost {
if portConfig.PublishMode == api.PublishModeHost &&
portConfig.PublishedPort != 0 {
if portStates.delState(portConfig) == nil {
return false
}
Expand Down
115 changes: 115 additions & 0 deletions manager/allocator/networkallocator/portallocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,121 @@ func TestPortsAllocatedInHostPublishMode(t *testing.T) {
},
expect: true,
},
{
// published port not specified
// we are not in charge of allocating one, for us it
// is as allocated, we need to skip the allocation
input: &api.Service{
Spec: api.ServiceSpec{
Endpoint: &api.EndpointSpec{
Ports: []*api.PortConfig{
{
Name: "test4",
Protocol: api.ProtocolUDP,
TargetPort: 99,
PublishMode: api.PublishModeHost,
},
},
},
},
Endpoint: &api.Endpoint{
Ports: []*api.PortConfig{
{
Name: "test4",
Protocol: api.ProtocolUDP,
TargetPort: 99,
PublishMode: api.PublishModeHost,
},
},
},
},
expect: true,
},
{
// one published port not specified, the other specified
// we are still in charge of allocating one
input: &api.Service{
Spec: api.ServiceSpec{
Endpoint: &api.EndpointSpec{
Ports: []*api.PortConfig{
{
Name: "test5",
Protocol: api.ProtocolUDP,
TargetPort: 99,
PublishMode: api.PublishModeHost,
},
{
Name: "test5",
Protocol: api.ProtocolTCP,
TargetPort: 99,
PublishedPort: 30099,
PublishMode: api.PublishModeHost,
},
},
},
},
Endpoint: &api.Endpoint{
Ports: []*api.PortConfig{
{
Name: "test5",
Protocol: api.ProtocolUDP,
TargetPort: 99,
PublishMode: api.PublishModeHost,
},
{
Name: "test5",
Protocol: api.ProtocolTCP,
TargetPort: 99,
PublishMode: api.PublishModeHost,
},
},
},
},
expect: false,
},
{
// one published port not specified, the other specified
// we are still in charge of allocating one and we did.
input: &api.Service{
Spec: api.ServiceSpec{
Endpoint: &api.EndpointSpec{
Ports: []*api.PortConfig{
{
Name: "test6",
Protocol: api.ProtocolUDP,
TargetPort: 99,
PublishMode: api.PublishModeHost,
},
{
Name: "test6",
Protocol: api.ProtocolTCP,
TargetPort: 99,
PublishedPort: 30099,
PublishMode: api.PublishModeHost,
},
},
},
},
Endpoint: &api.Endpoint{
Ports: []*api.PortConfig{
{
Name: "test6",
Protocol: api.ProtocolUDP,
TargetPort: 99,
PublishMode: api.PublishModeHost,
},
{
Name: "test6",
Protocol: api.ProtocolTCP,
TargetPort: 99,
PublishedPort: 30099,
PublishMode: api.PublishModeHost,
},
},
},
},
expect: true,
},
}
for _, singleTest := range testCases {
expect := pa.portsAllocatedInHostPublishMode(singleTest.input)
Expand Down

0 comments on commit 03d5b15

Please sign in to comment.