Ports could be in reverse order or otherwise.

This commit is contained in:
Andrew Butcher 2015-10-12 14:45:29 -04:00
parent efd8e3c9c7
commit a2c97c7b0e
2 changed files with 32 additions and 4 deletions

View File

@ -274,7 +274,7 @@ func (c *Controller) SetEndpoints(serviceName string, ip net.IP, endpointPorts [
}
// Determine if the endpoint is in the format SetEndpoints expect (one subset,
// one port, N IP addresses); and if the specified IP address is present and
// correct ports, N IP addresses); and if the specified IP address is present and
// the correct number of ip addresses are found.
func checkEndpointSubsetFormat(e *api.Endpoints, ip string, ports []api.EndpointPort, count int) (formatCorrect, ipCorrect bool) {
if len(e.Subsets) != 1 {
@ -284,9 +284,14 @@ func checkEndpointSubsetFormat(e *api.Endpoints, ip string, ports []api.Endpoint
if len(sub.Ports) != len(ports) {
return false, false
}
for i, p := range ports {
ep := &sub.Ports[i]
if p.Port != ep.Port || p.Protocol != ep.Protocol || p.Name != ep.Name {
for _, port := range ports {
contains := false
for _, subPort := range sub.Ports {
if port == subPort {
contains = true
}
}
if !contains {
return false, false
}
}

View File

@ -291,6 +291,29 @@ func TestSetEndpoints(t *testing.T) {
}},
},
},
{
testName: "existing endpoints extra un-ordered service ports satisfy",
serviceName: "foo",
ip: "1.2.3.4",
endpointPorts: []api.EndpointPort{
{Name: "baz", Port: 1010, Protocol: "TCP"},
{Name: "foo", Port: 8080, Protocol: "TCP"},
{Name: "bar", Port: 1000, Protocol: "TCP"},
},
endpoints: &api.EndpointsList{
Items: []api.Endpoints{{
ObjectMeta: om("foo"),
Subsets: []api.EndpointSubset{{
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
Ports: []api.EndpointPort{
{Name: "bar", Port: 1000, Protocol: "TCP"},
{Name: "foo", Port: 8080, Protocol: "TCP"},
{Name: "baz", Port: 1010, Protocol: "TCP"},
},
}},
}},
},
},
{
testName: "existing endpoints extra service ports missing port",
serviceName: "foo",