diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index 5a9ba66c918..bc9d1d86e25 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -546,7 +546,13 @@ func (proxier *Proxier) OnEndpointsUpdate(allEndpoints []*api.Endpoints) { proxier.allEndpoints = allEndpoints // 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) { proxier.endpointsMap = newMap 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. -func buildNewEndpointsMap(allEndpoints []*api.Endpoints, curMap proxyEndpointMap, hostname string, - healthChecker healthcheck.Server) (newMap proxyEndpointMap, staleSet map[endpointServicePair]bool) { +func buildNewEndpointsMap(allEndpoints []*api.Endpoints, curMap proxyEndpointMap, hostname string) (newMap proxyEndpointMap, hcEndpoints map[types.NamespacedName]int, staleSet map[endpointServicePair]bool) { // return values newMap = make(proxyEndpointMap) + hcEndpoints = make(map[types.NamespacedName]int) staleSet = make(map[endpointServicePair]bool) // Update endpoints for services. @@ -607,16 +613,11 @@ func buildNewEndpointsMap(allEndpoints []*api.Endpoints, curMap proxyEndpointMap } } // produce a count per service - localEndpointCounts := map[types.NamespacedName]int{} for nsn, ips := range localIPs { - localEndpointCounts[nsn] = len(ips) - } - // update healthcheck endpoints - if err := healthChecker.SyncEndpoints(localEndpointCounts); err != nil { - glog.Errorf("Error syncing healthcheck endoints: %v", err) + hcEndpoints[nsn] = len(ips) } - return newMap, staleSet + return newMap, hcEndpoints, staleSet } // Gather information about all the endpoint state for a given api.Endpoints. diff --git a/pkg/proxy/iptables/proxier_test.go b/pkg/proxy/iptables/proxier_test.go index c938a2c6d37..8a637519616 100644 --- a/pkg/proxy/iptables/proxier_test.go +++ b/pkg/proxy/iptables/proxier_test.go @@ -2010,8 +2010,7 @@ func Test_buildNewEndpointsMap(t *testing.T) { }} for tci, tc := range testCases { - hc := newFakeHealthChecker() - newMap, stale := buildNewEndpointsMap(tc.newEndpoints, tc.oldEndpoints, nodeName, hc) + newMap, hcEndpoints, stale := buildNewEndpointsMap(tc.newEndpoints, tc.oldEndpoints, nodeName) if len(newMap) != len(tc.expectedResult) { 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) } } - if !reflect.DeepEqual(hc.endpoints, tc.expectedHealthchecks) { - t.Errorf("[%d] expected healthchecks %v, got %v", tci, tc.expectedHealthchecks, hc.endpoints) + if !reflect.DeepEqual(hcEndpoints, tc.expectedHealthchecks) { + t.Errorf("[%d] expected healthchecks %v, got %v", tci, tc.expectedHealthchecks, hcEndpoints) } } }