From d578105a44e55319706871ae1157ec1e36ede4da Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Wed, 1 Feb 2017 12:17:41 -0800 Subject: [PATCH] Simple cleanup before refactoring --- pkg/proxy/iptables/proxier.go | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index 612f8cfb638..8d2127af322 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -150,8 +150,8 @@ type serviceInfo struct { // internal struct for endpoints information type endpointsInfo struct { - ip string - localEndpoint bool + endpoint string // TODO: should be an endpointString type + isLocal bool } // returns a new serviceInfo struct @@ -546,7 +546,7 @@ func (proxier *Proxier) OnServiceUpdate(allServices []api.Service) { func flattenEndpointsInfo(endPoints []*endpointsInfo) []string { var endpointIPs []string for _, ep := range endPoints { - endpointIPs = append(endpointIPs, ep.ip) + endpointIPs = append(endpointIPs, ep.endpoint) } return endpointIPs } @@ -562,7 +562,7 @@ func flattenEndpointsInfo(endPoints []*endpointsInfo) []string { // then output will be // // []endpointsInfo{ {"2.2.2.2:80", localEndpointOnly=} } -func (proxier *Proxier) buildEndpointInfoList(endPoints []hostPortInfo, endpointIPs []string) []*endpointsInfo { +func buildEndpointInfoList(endPoints []hostPortInfo, endpointIPs []string) []*endpointsInfo { lookupSet := sets.NewString() for _, ip := range endpointIPs { lookupSet.Insert(ip) @@ -571,7 +571,7 @@ func (proxier *Proxier) buildEndpointInfoList(endPoints []hostPortInfo, endpoint for _, hpp := range endPoints { key := net.JoinHostPort(hpp.host, strconv.Itoa(hpp.port)) if lookupSet.Has(key) { - filteredEndpoints = append(filteredEndpoints, &endpointsInfo{ip: key, localEndpoint: hpp.localEndpoint}) + filteredEndpoints = append(filteredEndpoints, &endpointsInfo{endpoint: key, isLocal: hpp.isLocal}) } } return filteredEndpoints @@ -607,9 +607,9 @@ func (proxier *Proxier) OnEndpointsUpdate(allEndpoints []api.Endpoints) { for i := range ss.Addresses { addr := &ss.Addresses[i] hostPortObject := hostPortInfo{ - host: addr.IP, - port: int(port.Port), - localEndpoint: addr.NodeName != nil && *addr.NodeName == proxier.hostname, + host: addr.IP, + port: int(port.Port), + isLocal: addr.NodeName != nil && *addr.NodeName == proxier.hostname, } portsToEndpoints[port.Name] = append(portsToEndpoints[port.Name], hostPortObject) } @@ -631,7 +631,7 @@ func (proxier *Proxier) OnEndpointsUpdate(allEndpoints []api.Endpoints) { } } // Once the set operations using the list of ips are complete, build the list of endpoint infos - newEndpointsMap[svcPort] = proxier.buildEndpointInfoList(portsToEndpoints[portname], newEndpoints) + newEndpointsMap[svcPort] = buildEndpointInfoList(portsToEndpoints[portname], newEndpoints) activeEndpoints[svcPort] = true } } @@ -641,7 +641,7 @@ func (proxier *Proxier) OnEndpointsUpdate(allEndpoints []api.Endpoints) { glog.V(2).Infof("Removing endpoints for %q", svcPort) // record endpoints of unactive service to stale connections for _, ep := range proxier.endpointsMap[svcPort] { - staleConnections[endpointServicePair{endpoint: ep.ip, servicePortName: svcPort}] = true + staleConnections[endpointServicePair{endpoint: ep.endpoint, servicePortName: svcPort}] = true } } } @@ -677,7 +677,7 @@ func (proxier *Proxier) updateHealthCheckEntries(name types.NamespacedName, host // Use a set instead of a slice to provide deduplication endpoints := sets.NewString() for _, portInfo := range hostPorts { - if portInfo.localEndpoint { + if portInfo.isLocal { // kube-proxy health check only needs local endpoints endpoints.Insert(fmt.Sprintf("%s/%s", name.Namespace, name.Name)) } @@ -687,9 +687,9 @@ func (proxier *Proxier) updateHealthCheckEntries(name types.NamespacedName, host // used in OnEndpointsUpdate type hostPortInfo struct { - host string - port int - localEndpoint bool + host string + port int + isLocal bool } func isValidEndpoint(hpp *hostPortInfo) bool { @@ -1194,7 +1194,7 @@ func (proxier *Proxier) syncProxyRules() { endpointChains := make([]utiliptables.Chain, 0) for _, ep := range proxier.endpointsMap[svcName] { endpoints = append(endpoints, ep) - endpointChain := servicePortEndpointChainName(svcName, protocol, ep.ip) + endpointChain := servicePortEndpointChainName(svcName, protocol, ep.endpoint) endpointChains = append(endpointChains, endpointChain) // Create the endpoint chain, retaining counters if possible. @@ -1244,14 +1244,14 @@ func (proxier *Proxier) syncProxyRules() { } // Handle traffic that loops back to the originator with SNAT. writeLine(natRules, append(args, - "-s", fmt.Sprintf("%s/32", strings.Split(endpoints[i].ip, ":")[0]), + "-s", fmt.Sprintf("%s/32", strings.Split(endpoints[i].endpoint, ":")[0]), "-j", string(KubeMarkMasqChain))...) // Update client-affinity lists. if svcInfo.sessionAffinityType == api.ServiceAffinityClientIP { args = append(args, "-m", "recent", "--name", string(endpointChain), "--set") } // DNAT to final destination. - args = append(args, "-m", protocol, "-p", protocol, "-j", "DNAT", "--to-destination", endpoints[i].ip) + args = append(args, "-m", protocol, "-p", protocol, "-j", "DNAT", "--to-destination", endpoints[i].endpoint) writeLine(natRules, args...) } @@ -1265,7 +1265,7 @@ func (proxier *Proxier) syncProxyRules() { localEndpoints := make([]*endpointsInfo, 0) localEndpointChains := make([]utiliptables.Chain, 0) for i := range endpointChains { - if endpoints[i].localEndpoint { + if endpoints[i].isLocal { // These slices parallel each other; must be kept in sync localEndpoints = append(localEndpoints, endpoints[i]) localEndpointChains = append(localEndpointChains, endpointChains[i])