From 8d24fc398436abe2310d7a997da277545d2bb12b Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 2 Feb 2017 17:37:34 -0800 Subject: [PATCH] Simplify maps which had almost the exact same info --- pkg/proxy/iptables/proxier.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index deba2cc6f83..e915c3c808e 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -643,11 +643,14 @@ func accumulateEndpointsMap(endpoints *api.Endpoints, hostname string, // We need to build a map of portname -> all ip:ports for that // portname. Explode Endpoints.Subsets[*] into this structure. - portsToEndpoints := map[string][]hostPortInfo{} for i := range endpoints.Subsets { ss := &endpoints.Subsets[i] for i := range ss.Ports { port := &ss.Ports[i] + svcPort := proxy.ServicePortName{ + NamespacedName: types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name}, + Port: port.Name, + } for i := range ss.Addresses { addr := &ss.Addresses[i] hostPortObject := hostPortInfo{ @@ -655,17 +658,13 @@ func accumulateEndpointsMap(endpoints *api.Endpoints, hostname string, port: int(port.Port), isLocal: addr.NodeName != nil && *addr.NodeName == hostname, } - portsToEndpoints[port.Name] = append(portsToEndpoints[port.Name], hostPortObject) + (*svcPortToInfoMap)[svcPort] = append((*svcPortToInfoMap)[svcPort], hostPortObject) } } } - for portname := range portsToEndpoints { - svcPort := proxy.ServicePortName{ - NamespacedName: types.NamespacedName{Namespace: endpoints.Namespace, Name: endpoints.Name}, - Port: portname, - } - (*svcPortToInfoMap)[svcPort] = portsToEndpoints[portname] - newEPList := flattenValidEndpoints(portsToEndpoints[portname]) + // Decompose the lists of endpoints into details of what was changed for the caller. + for svcPort, hostPortInfos := range *svcPortToInfoMap { + newEPList := flattenValidEndpoints(hostPortInfos) // Flatten the list of current endpoint infos to just a list of ips as strings curEndpointIPs := flattenEndpointsInfo(curEndpoints[svcPort]) if len(curEndpointIPs) != len(newEPList) || !slicesEquiv(slice.CopyStrings(curEndpointIPs), newEPList) { @@ -678,7 +677,7 @@ func accumulateEndpointsMap(endpoints *api.Endpoints, hostname string, } glog.V(3).Infof("Setting endpoints for %q to %+v", svcPort, newEPList) // Once the set operations using the list of ips are complete, build the list of endpoint infos - (*newEndpoints)[svcPort] = buildEndpointInfoList(portsToEndpoints[portname], newEPList) + (*newEndpoints)[svcPort] = buildEndpointInfoList(hostPortInfos, newEPList) } }