From a2c97c7b0ebe9cd07edc5eb7240cb4b714da56ed Mon Sep 17 00:00:00 2001 From: Andrew Butcher Date: Mon, 12 Oct 2015 14:45:29 -0400 Subject: [PATCH] Ports could be in reverse order or otherwise. --- pkg/master/controller.go | 13 +++++++++---- pkg/master/controller_test.go | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/pkg/master/controller.go b/pkg/master/controller.go index 38e871d489b..4c57b76f350 100644 --- a/pkg/master/controller.go +++ b/pkg/master/controller.go @@ -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 } } diff --git a/pkg/master/controller_test.go b/pkg/master/controller_test.go index fc826a85ff3..34db2eabfa1 100644 --- a/pkg/master/controller_test.go +++ b/pkg/master/controller_test.go @@ -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",