Commit 101a9927 authored by Andrew Butcher's avatar Andrew Butcher

Do not update kubernetes endpoints when endpoint address count is less than or…

Do not update kubernetes endpoints when endpoint address count is less than or equal to master count. checkEndpointSubsetFormat ensures that, 1. the current master's IP is in the list of addresses 2. the number of IPs in the list exactly matches the master count This is problematic while masters are in the process of starting because it causes frequent updates to the kubernetes endpoints until all masters have started and added themselves to the list. checkEndpointSubsetFormat should report success if the current master's IP is found and the count of addresses is less than or equal to the expected count.
parent c1af9dcb
...@@ -296,9 +296,14 @@ func (c *Controller) ReconcileEndpoints(serviceName string, ip net.IP, endpointP ...@@ -296,9 +296,14 @@ func (c *Controller) ReconcileEndpoints(serviceName string, ip net.IP, endpointP
return c.EndpointRegistry.UpdateEndpoints(ctx, e) return c.EndpointRegistry.UpdateEndpoints(ctx, e)
} }
// Determine if the endpoint is in the format ReconcileEndpoints expect (one subset, // Determine if the endpoint is in the format ReconcileEndpoints expects.
// correct ports, N IP addresses); and if the specified IP address is present and //
// the correct number of ip addresses are found. // Return values:
// * formatCorrect is true if exactly one subset is found.
// * ipCorrect is true when current master's IP is found and the number
// of addresses is less than or equal to the master count.
// * portsCorrect is true when endpoint ports exactly match provided ports.
// portsCorrect is only evaluated when reconcilePorts is set to true.
func checkEndpointSubsetFormat(e *api.Endpoints, ip string, ports []api.EndpointPort, count int, reconcilePorts bool) (formatCorrect bool, ipCorrect bool, portsCorrect bool) { func checkEndpointSubsetFormat(e *api.Endpoints, ip string, ports []api.EndpointPort, count int, reconcilePorts bool) (formatCorrect bool, ipCorrect bool, portsCorrect bool) {
if len(e.Subsets) != 1 { if len(e.Subsets) != 1 {
return false, false, false return false, false, false
...@@ -318,7 +323,7 @@ func checkEndpointSubsetFormat(e *api.Endpoints, ip string, ports []api.Endpoint ...@@ -318,7 +323,7 @@ func checkEndpointSubsetFormat(e *api.Endpoints, ip string, ports []api.Endpoint
} }
for _, addr := range sub.Addresses { for _, addr := range sub.Addresses {
if addr.IP == ip { if addr.IP == ip {
ipCorrect = len(sub.Addresses) == count ipCorrect = len(sub.Addresses) <= count
break break
} }
} }
......
...@@ -161,6 +161,54 @@ func TestReconcileEndpoints(t *testing.T) { ...@@ -161,6 +161,54 @@ func TestReconcileEndpoints(t *testing.T) {
}, },
}, },
{ {
testName: "existing endpoints satisfy and endpoint addresses length less than master count",
serviceName: "foo",
ip: "4.3.2.2",
endpointPorts: []api.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
additionalMasters: 3,
endpoints: &api.EndpointsList{
Items: []api.Endpoints{{
ObjectMeta: om("foo"),
Subsets: []api.EndpointSubset{{
Addresses: []api.EndpointAddress{
{IP: "4.3.2.1"},
{IP: "4.3.2.2"},
},
Ports: []api.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
}},
}},
},
expectUpdate: nil,
},
{
testName: "existing endpoints current IP missing and address length less than master count",
serviceName: "foo",
ip: "4.3.2.2",
endpointPorts: []api.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
additionalMasters: 3,
endpoints: &api.EndpointsList{
Items: []api.Endpoints{{
ObjectMeta: om("foo"),
Subsets: []api.EndpointSubset{{
Addresses: []api.EndpointAddress{
{IP: "4.3.2.1"},
},
Ports: []api.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
}},
}},
},
expectUpdate: &api.Endpoints{
ObjectMeta: om("foo"),
Subsets: []api.EndpointSubset{{
Addresses: []api.EndpointAddress{
{IP: "4.3.2.1"},
{IP: "4.3.2.2"},
},
Ports: []api.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
}},
},
},
{
testName: "existing endpoints wrong name", testName: "existing endpoints wrong name",
serviceName: "foo", serviceName: "foo",
ip: "1.2.3.4", ip: "1.2.3.4",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment