From 099e55c284d5c36e870914b0d68305e6129e156c Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 31 Mar 2017 23:26:39 -0700 Subject: [PATCH] Rename functions for congruence --- pkg/proxy/iptables/proxier.go | 10 +++++----- pkg/proxy/iptables/proxier_test.go | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index fc00c52003a..0be4dbd62da 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -457,7 +457,7 @@ type healthCheckPort struct { // Accepts a list of Services and the existing service map. Returns the new // service map, a list of healthcheck ports to add to or remove from the health // checking listener service, and a set of stale UDP services. -func buildServiceMap(allServices []*api.Service, oldServiceMap proxyServiceMap) (proxyServiceMap, []healthCheckPort, []healthCheckPort, sets.String) { +func buildNewServiceMap(allServices []*api.Service, oldServiceMap proxyServiceMap) (proxyServiceMap, []healthCheckPort, []healthCheckPort, sets.String) { newServiceMap := make(proxyServiceMap) healthCheckAdd := make([]healthCheckPort, 0) healthCheckDel := make([]healthCheckPort, 0) @@ -537,7 +537,7 @@ func (proxier *Proxier) OnServiceUpdate(allServices []*api.Service) { defer proxier.mu.Unlock() proxier.haveReceivedServiceUpdate = true - newServiceMap, hcAdd, hcDel, staleUDPServices := buildServiceMap(allServices, proxier.serviceMap) + newServiceMap, hcAdd, hcDel, staleUDPServices := buildNewServiceMap(allServices, proxier.serviceMap) for _, hc := range hcAdd { glog.V(4).Infof("Adding health check for %+v, port %v", hc.namespace, hc.nodeport) // Turn on healthcheck responder to listen on the health check nodePort @@ -572,7 +572,7 @@ 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 := updateEndpoints(proxier.allEndpoints, proxier.endpointsMap, proxier.hostname, proxier.healthChecker) + newMap, staleConnections := buildNewEndpointsMap(proxier.allEndpoints, proxier.endpointsMap, proxier.hostname, proxier.healthChecker) if len(newMap) != len(proxier.endpointsMap) || !reflect.DeepEqual(newMap, proxier.endpointsMap) { proxier.endpointsMap = newMap proxier.syncProxyRules() @@ -584,7 +584,7 @@ func (proxier *Proxier) OnEndpointsUpdate(allEndpoints []*api.Endpoints) { } // Convert a slice of api.Endpoints objects into a map of service-port -> endpoints. -func updateEndpoints(allEndpoints []*api.Endpoints, curMap proxyEndpointMap, hostname string, +func buildNewEndpointsMap(allEndpoints []*api.Endpoints, curMap proxyEndpointMap, hostname string, healthChecker healthChecker) (newMap proxyEndpointMap, staleSet map[endpointServicePair]bool) { // return values @@ -638,7 +638,7 @@ func updateEndpoints(allEndpoints []*api.Endpoints, curMap proxyEndpointMap, hos // // TODO: this could be simplified: // - hostPortInfo and endpointsInfo overlap too much -// - the test for this is overlapped by the test for updateEndpoints +// - the test for this is overlapped by the test for buildNewEndpointsMap // - naming is poor and responsibilities are muddled func accumulateEndpointsMap(endpoints *api.Endpoints, hostname string, curEndpoints proxyEndpointMap, diff --git a/pkg/proxy/iptables/proxier_test.go b/pkg/proxy/iptables/proxier_test.go index afcee91ee71..908c6966d96 100644 --- a/pkg/proxy/iptables/proxier_test.go +++ b/pkg/proxy/iptables/proxier_test.go @@ -926,7 +926,7 @@ func TestBuildServiceMapAddRemove(t *testing.T) { }), } - serviceMap, hcAdd, hcDel, staleUDPServices := buildServiceMap(services, make(proxyServiceMap)) + serviceMap, hcAdd, hcDel, staleUDPServices := buildNewServiceMap(services, make(proxyServiceMap)) if len(serviceMap) != 8 { t.Errorf("expected service map length 8, got %v", serviceMap) } @@ -961,7 +961,7 @@ func TestBuildServiceMapAddRemove(t *testing.T) { // Remove some stuff services = []*api.Service{services[0]} services[0].Spec.Ports = []api.ServicePort{services[0].Spec.Ports[1]} - serviceMap, hcAdd, hcDel, staleUDPServices = buildServiceMap(services, serviceMap) + serviceMap, hcAdd, hcDel, staleUDPServices = buildNewServiceMap(services, serviceMap) if len(serviceMap) != 1 { t.Errorf("expected service map length 1, got %v", serviceMap) } @@ -1008,7 +1008,7 @@ func TestBuildServiceMapServiceHeadless(t *testing.T) { } // Headless service should be ignored - serviceMap, hcAdd, hcDel, staleUDPServices := buildServiceMap(services, make(proxyServiceMap)) + serviceMap, hcAdd, hcDel, staleUDPServices := buildNewServiceMap(services, make(proxyServiceMap)) if len(serviceMap) != 0 { t.Errorf("expected service map length 0, got %d", len(serviceMap)) } @@ -1036,7 +1036,7 @@ func TestBuildServiceMapServiceTypeExternalName(t *testing.T) { }), } - serviceMap, hcAdd, hcDel, staleUDPServices := buildServiceMap(services, make(proxyServiceMap)) + serviceMap, hcAdd, hcDel, staleUDPServices := buildNewServiceMap(services, make(proxyServiceMap)) if len(serviceMap) != 0 { t.Errorf("expected service map length 0, got %v", serviceMap) } @@ -1081,7 +1081,7 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) { }), } - serviceMap, hcAdd, hcDel, staleUDPServices := buildServiceMap(first, make(proxyServiceMap)) + serviceMap, hcAdd, hcDel, staleUDPServices := buildNewServiceMap(first, make(proxyServiceMap)) if len(serviceMap) != 2 { t.Errorf("expected service map length 2, got %v", serviceMap) } @@ -1097,7 +1097,7 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) { } // Change service to load-balancer - serviceMap, hcAdd, hcDel, staleUDPServices = buildServiceMap(second, serviceMap) + serviceMap, hcAdd, hcDel, staleUDPServices = buildNewServiceMap(second, serviceMap) if len(serviceMap) != 2 { t.Errorf("expected service map length 2, got %v", serviceMap) } @@ -1113,7 +1113,7 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) { // No change; make sure the service map stays the same and there are // no health-check changes - serviceMap, hcAdd, hcDel, staleUDPServices = buildServiceMap(second, serviceMap) + serviceMap, hcAdd, hcDel, staleUDPServices = buildNewServiceMap(second, serviceMap) if len(serviceMap) != 2 { t.Errorf("expected service map length 2, got %v", serviceMap) } @@ -1128,7 +1128,7 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) { } // And back to ClusterIP - serviceMap, hcAdd, hcDel, staleUDPServices = buildServiceMap(first, serviceMap) + serviceMap, hcAdd, hcDel, staleUDPServices = buildNewServiceMap(first, serviceMap) if len(serviceMap) != 2 { t.Errorf("expected service map length 2, got %v", serviceMap) } @@ -1396,7 +1396,7 @@ func makeServicePortName(ns, name, port string) proxy.ServicePortName { } } -func Test_updateEndpoints(t *testing.T) { +func Test_buildNewEndpointsMap(t *testing.T) { testCases := []struct { newEndpoints []*api.Endpoints oldEndpoints map[proxy.ServicePortName][]*endpointsInfo @@ -1993,7 +1993,7 @@ func Test_updateEndpoints(t *testing.T) { }} for tci, tc := range testCases { - newMap, stale := updateEndpoints(tc.newEndpoints, tc.oldEndpoints, "host", fakeHealthChecker{}) + newMap, stale := buildNewEndpointsMap(tc.newEndpoints, tc.oldEndpoints, "host", fakeHealthChecker{}) if len(newMap) != len(tc.expectedResult) { t.Errorf("[%d] expected %d results, got %d: %v", tci, len(tc.expectedResult), len(newMap), newMap) }