Rename functions for congruence
This commit is contained in:
parent
4d8ffb23ef
commit
099e55c284
@ -457,7 +457,7 @@ type healthCheckPort struct {
|
|||||||
// Accepts a list of Services and the existing service map. Returns the new
|
// 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
|
// 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.
|
// 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)
|
newServiceMap := make(proxyServiceMap)
|
||||||
healthCheckAdd := make([]healthCheckPort, 0)
|
healthCheckAdd := make([]healthCheckPort, 0)
|
||||||
healthCheckDel := make([]healthCheckPort, 0)
|
healthCheckDel := make([]healthCheckPort, 0)
|
||||||
@ -537,7 +537,7 @@ func (proxier *Proxier) OnServiceUpdate(allServices []*api.Service) {
|
|||||||
defer proxier.mu.Unlock()
|
defer proxier.mu.Unlock()
|
||||||
proxier.haveReceivedServiceUpdate = true
|
proxier.haveReceivedServiceUpdate = true
|
||||||
|
|
||||||
newServiceMap, hcAdd, hcDel, staleUDPServices := buildServiceMap(allServices, proxier.serviceMap)
|
newServiceMap, hcAdd, hcDel, staleUDPServices := buildNewServiceMap(allServices, proxier.serviceMap)
|
||||||
for _, hc := range hcAdd {
|
for _, hc := range hcAdd {
|
||||||
glog.V(4).Infof("Adding health check for %+v, port %v", hc.namespace, hc.nodeport)
|
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
|
// 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
|
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 := 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) {
|
if len(newMap) != len(proxier.endpointsMap) || !reflect.DeepEqual(newMap, proxier.endpointsMap) {
|
||||||
proxier.endpointsMap = newMap
|
proxier.endpointsMap = newMap
|
||||||
proxier.syncProxyRules()
|
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.
|
// 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) {
|
healthChecker healthChecker) (newMap proxyEndpointMap, staleSet map[endpointServicePair]bool) {
|
||||||
|
|
||||||
// return values
|
// return values
|
||||||
@ -638,7 +638,7 @@ func updateEndpoints(allEndpoints []*api.Endpoints, curMap proxyEndpointMap, hos
|
|||||||
//
|
//
|
||||||
// TODO: this could be simplified:
|
// TODO: this could be simplified:
|
||||||
// - hostPortInfo and endpointsInfo overlap too much
|
// - 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
|
// - naming is poor and responsibilities are muddled
|
||||||
func accumulateEndpointsMap(endpoints *api.Endpoints, hostname string,
|
func accumulateEndpointsMap(endpoints *api.Endpoints, hostname string,
|
||||||
curEndpoints proxyEndpointMap,
|
curEndpoints proxyEndpointMap,
|
||||||
|
@ -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 {
|
if len(serviceMap) != 8 {
|
||||||
t.Errorf("expected service map length 8, got %v", serviceMap)
|
t.Errorf("expected service map length 8, got %v", serviceMap)
|
||||||
}
|
}
|
||||||
@ -961,7 +961,7 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
|
|||||||
// Remove some stuff
|
// Remove some stuff
|
||||||
services = []*api.Service{services[0]}
|
services = []*api.Service{services[0]}
|
||||||
services[0].Spec.Ports = []api.ServicePort{services[0].Spec.Ports[1]}
|
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 {
|
if len(serviceMap) != 1 {
|
||||||
t.Errorf("expected service map length 1, got %v", serviceMap)
|
t.Errorf("expected service map length 1, got %v", serviceMap)
|
||||||
}
|
}
|
||||||
@ -1008,7 +1008,7 @@ func TestBuildServiceMapServiceHeadless(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Headless service should be ignored
|
// 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 {
|
if len(serviceMap) != 0 {
|
||||||
t.Errorf("expected service map length 0, got %d", len(serviceMap))
|
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 {
|
if len(serviceMap) != 0 {
|
||||||
t.Errorf("expected service map length 0, got %v", serviceMap)
|
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 {
|
if len(serviceMap) != 2 {
|
||||||
t.Errorf("expected service map length 2, got %v", serviceMap)
|
t.Errorf("expected service map length 2, got %v", serviceMap)
|
||||||
}
|
}
|
||||||
@ -1097,7 +1097,7 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Change service to load-balancer
|
// Change service to load-balancer
|
||||||
serviceMap, hcAdd, hcDel, staleUDPServices = buildServiceMap(second, serviceMap)
|
serviceMap, hcAdd, hcDel, staleUDPServices = buildNewServiceMap(second, serviceMap)
|
||||||
if len(serviceMap) != 2 {
|
if len(serviceMap) != 2 {
|
||||||
t.Errorf("expected service map length 2, got %v", serviceMap)
|
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 change; make sure the service map stays the same and there are
|
||||||
// no health-check changes
|
// no health-check changes
|
||||||
serviceMap, hcAdd, hcDel, staleUDPServices = buildServiceMap(second, serviceMap)
|
serviceMap, hcAdd, hcDel, staleUDPServices = buildNewServiceMap(second, serviceMap)
|
||||||
if len(serviceMap) != 2 {
|
if len(serviceMap) != 2 {
|
||||||
t.Errorf("expected service map length 2, got %v", serviceMap)
|
t.Errorf("expected service map length 2, got %v", serviceMap)
|
||||||
}
|
}
|
||||||
@ -1128,7 +1128,7 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// And back to ClusterIP
|
// And back to ClusterIP
|
||||||
serviceMap, hcAdd, hcDel, staleUDPServices = buildServiceMap(first, serviceMap)
|
serviceMap, hcAdd, hcDel, staleUDPServices = buildNewServiceMap(first, serviceMap)
|
||||||
if len(serviceMap) != 2 {
|
if len(serviceMap) != 2 {
|
||||||
t.Errorf("expected service map length 2, got %v", serviceMap)
|
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 {
|
testCases := []struct {
|
||||||
newEndpoints []*api.Endpoints
|
newEndpoints []*api.Endpoints
|
||||||
oldEndpoints map[proxy.ServicePortName][]*endpointsInfo
|
oldEndpoints map[proxy.ServicePortName][]*endpointsInfo
|
||||||
@ -1993,7 +1993,7 @@ func Test_updateEndpoints(t *testing.T) {
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
for tci, tc := range testCases {
|
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) {
|
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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user