Return healthcheck info from buildNewEndpointsMap

This commit is contained in:
Tim Hockin 2017-04-02 21:44:07 -07:00
parent 87d3f2c622
commit 5e43c14098
2 changed files with 14 additions and 14 deletions

View File

@ -546,7 +546,13 @@ func (proxier *Proxier) OnEndpointsUpdate(allEndpoints []*api.Endpoints) {
proxier.allEndpoints = allEndpoints proxier.allEndpoints = allEndpoints
// TODO: once service has made this same transform, move this into proxier.syncProxyRules() // TODO: once service has made this same transform, move this into proxier.syncProxyRules()
newMap, staleConnections := buildNewEndpointsMap(proxier.allEndpoints, proxier.endpointsMap, proxier.hostname, proxier.healthChecker) newMap, hcEndpoints, staleConnections := buildNewEndpointsMap(proxier.allEndpoints, proxier.endpointsMap, proxier.hostname)
// update healthcheck endpoints
if err := proxier.healthChecker.SyncEndpoints(hcEndpoints); err != nil {
glog.Errorf("Error syncing healthcheck endoints: %v", err)
}
if len(newMap) != len(proxier.endpointsMap) || !reflect.DeepEqual(newMap, proxier.endpointsMap) { if len(newMap) != len(proxier.endpointsMap) || !reflect.DeepEqual(newMap, proxier.endpointsMap) {
proxier.endpointsMap = newMap proxier.endpointsMap = newMap
proxier.syncProxyRules(syncReasonEndpoints) proxier.syncProxyRules(syncReasonEndpoints)
@ -558,11 +564,11 @@ func (proxier *Proxier) OnEndpointsUpdate(allEndpoints []*api.Endpoints) {
} }
// Convert a slice of api.Endpoints objects into a map of service-port -> endpoints. // Convert a slice of api.Endpoints objects into a map of service-port -> endpoints.
func buildNewEndpointsMap(allEndpoints []*api.Endpoints, curMap proxyEndpointMap, hostname string, func buildNewEndpointsMap(allEndpoints []*api.Endpoints, curMap proxyEndpointMap, hostname string) (newMap proxyEndpointMap, hcEndpoints map[types.NamespacedName]int, staleSet map[endpointServicePair]bool) {
healthChecker healthcheck.Server) (newMap proxyEndpointMap, staleSet map[endpointServicePair]bool) {
// return values // return values
newMap = make(proxyEndpointMap) newMap = make(proxyEndpointMap)
hcEndpoints = make(map[types.NamespacedName]int)
staleSet = make(map[endpointServicePair]bool) staleSet = make(map[endpointServicePair]bool)
// Update endpoints for services. // Update endpoints for services.
@ -607,16 +613,11 @@ func buildNewEndpointsMap(allEndpoints []*api.Endpoints, curMap proxyEndpointMap
} }
} }
// produce a count per service // produce a count per service
localEndpointCounts := map[types.NamespacedName]int{}
for nsn, ips := range localIPs { for nsn, ips := range localIPs {
localEndpointCounts[nsn] = len(ips) hcEndpoints[nsn] = len(ips)
}
// update healthcheck endpoints
if err := healthChecker.SyncEndpoints(localEndpointCounts); err != nil {
glog.Errorf("Error syncing healthcheck endoints: %v", err)
} }
return newMap, staleSet return newMap, hcEndpoints, staleSet
} }
// Gather information about all the endpoint state for a given api.Endpoints. // Gather information about all the endpoint state for a given api.Endpoints.

View File

@ -2010,8 +2010,7 @@ func Test_buildNewEndpointsMap(t *testing.T) {
}} }}
for tci, tc := range testCases { for tci, tc := range testCases {
hc := newFakeHealthChecker() newMap, hcEndpoints, stale := buildNewEndpointsMap(tc.newEndpoints, tc.oldEndpoints, nodeName)
newMap, stale := buildNewEndpointsMap(tc.newEndpoints, tc.oldEndpoints, nodeName, hc)
if len(newMap) != len(tc.expectedResult) { if len(newMap) != len(tc.expectedResult) {
t.Errorf("[%d] expected %d results, got %d: %v", tci, len(tc.expectedResult), len(newMap), newMap) t.Errorf("[%d] expected %d results, got %d: %v", tci, len(tc.expectedResult), len(newMap), newMap)
} }
@ -2034,8 +2033,8 @@ func Test_buildNewEndpointsMap(t *testing.T) {
t.Errorf("[%d] expected stale[%v], but didn't find it: %v", tci, x, stale) t.Errorf("[%d] expected stale[%v], but didn't find it: %v", tci, x, stale)
} }
} }
if !reflect.DeepEqual(hc.endpoints, tc.expectedHealthchecks) { if !reflect.DeepEqual(hcEndpoints, tc.expectedHealthchecks) {
t.Errorf("[%d] expected healthchecks %v, got %v", tci, tc.expectedHealthchecks, hc.endpoints) t.Errorf("[%d] expected healthchecks %v, got %v", tci, tc.expectedHealthchecks, hcEndpoints)
} }
} }
} }