From 0621e90d31b03f9628222a9abd3f0a9f1350b99a Mon Sep 17 00:00:00 2001 From: Fangyuan Li Date: Fri, 5 Mar 2021 15:01:50 -0800 Subject: [PATCH] Rename fields and methods for BaseServiceInfo Fields: 1. rename onlyNodeLocalEndpoints to nodeLocalExternal; 2. rename onlyNodeLocalEndpointsForInternal to nodeLocalInternal; Methods: 1. rename OnlyNodeLocalEndpoints to NodeLocalExternal; 2. rename OnlyNodeLocalEndpointsForInternal to NodeLocalInternal; --- pkg/proxy/iptables/proxier.go | 16 ++++----- pkg/proxy/ipvs/proxier.go | 16 ++++----- pkg/proxy/service.go | 68 +++++++++++++++++------------------ pkg/proxy/types.go | 8 ++--- 4 files changed, 54 insertions(+), 54 deletions(-) diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index 4dafa162167..292e05aa852 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -1025,7 +1025,7 @@ func (proxier *Proxier) syncProxyRules() { // 2. ServiceTopology is not enabled. // 3. EndpointSlice is not enabled (service topology depends on endpoint slice // to get topology information). - if !svcInfo.OnlyNodeLocalEndpoints() && utilfeature.DefaultFeatureGate.Enabled(features.ServiceTopology) && utilfeature.DefaultFeatureGate.Enabled(features.EndpointSliceProxying) { + if !svcInfo.NodeLocalExternal() && utilfeature.DefaultFeatureGate.Enabled(features.ServiceTopology) && utilfeature.DefaultFeatureGate.Enabled(features.EndpointSliceProxying) { allEndpoints = proxy.FilterTopologyEndpoint(proxier.nodeLabels, svcInfo.TopologyKeys(), allEndpoints) } @@ -1033,7 +1033,7 @@ func (proxier *Proxier) syncProxyRules() { // following are true: // 1. InternalTrafficPolicy is Local // 2. ServiceInternalTrafficPolicy feature gate is on - if utilfeature.DefaultFeatureGate.Enabled(features.ServiceInternalTrafficPolicy) && svcInfo.OnlyNodeLocalEndpointsForInternal() { + if utilfeature.DefaultFeatureGate.Enabled(features.ServiceInternalTrafficPolicy) && svcInfo.NodeLocalInternal() { allEndpoints = proxy.FilterLocalEndpoint(svcInfo.InternalTrafficPolicy(), allEndpoints) } readyEndpoints := make([]proxy.Endpoint, 0, len(allEndpoints)) @@ -1058,7 +1058,7 @@ func (proxier *Proxier) syncProxyRules() { } svcXlbChain := svcInfo.serviceLBChainName - if svcInfo.OnlyNodeLocalEndpoints() { + if svcInfo.NodeLocalExternal() { // Only for services request OnlyLocal traffic // create the per-service LB chain, retaining counters if possible. if lbChain, ok := existingNATChains[svcXlbChain]; ok { @@ -1151,7 +1151,7 @@ func (proxier *Proxier) syncProxyRules() { // and the traffic is NOT Local. Local traffic coming from Pods and Nodes will // be always forwarded to the corresponding Service, so no need to SNAT // If we can't differentiate the local traffic we always SNAT. - if !svcInfo.OnlyNodeLocalEndpoints() { + if !svcInfo.NodeLocalExternal() { destChain = svcChain // This masquerades off-cluster traffic to a External IP. if proxier.localDetector.IsImplemented() { @@ -1211,7 +1211,7 @@ func (proxier *Proxier) syncProxyRules() { chosenChain := svcXlbChain // If we are proxying globally, we need to masquerade in case we cross nodes. // If we are proxying only locally, we can retain the source IP. - if !svcInfo.OnlyNodeLocalEndpoints() { + if !svcInfo.NodeLocalExternal() { utilproxy.WriteLine(proxier.natRules, append(args, "-j", string(KubeMarkMasqChain))...) chosenChain = svcChain } @@ -1308,7 +1308,7 @@ func (proxier *Proxier) syncProxyRules() { "-m", protocol, "-p", protocol, "--dport", strconv.Itoa(svcInfo.NodePort()), ) - if !svcInfo.OnlyNodeLocalEndpoints() { + if !svcInfo.NodeLocalExternal() { // Nodeports need SNAT, unless they're local. utilproxy.WriteLine(proxier.natRules, append(args, "-j", string(KubeMarkMasqChain))...) // Jump to the service chain. @@ -1402,7 +1402,7 @@ func (proxier *Proxier) syncProxyRules() { localEndpointChains := make([]utiliptables.Chain, 0) for i, endpointChain := range endpointChains { // Write ingress loadbalancing & DNAT rules only for services that request OnlyLocal traffic. - if svcInfo.OnlyNodeLocalEndpoints() && endpoints[i].IsLocal { + if svcInfo.NodeLocalExternal() && endpoints[i].IsLocal { localEndpointChains = append(localEndpointChains, endpointChains[i]) } @@ -1443,7 +1443,7 @@ func (proxier *Proxier) syncProxyRules() { } // The logic below this applies only if this service is marked as OnlyLocal - if !svcInfo.OnlyNodeLocalEndpoints() { + if !svcInfo.NodeLocalExternal() { continue } diff --git a/pkg/proxy/ipvs/proxier.go b/pkg/proxy/ipvs/proxier.go index e084458db2d..2656b52caa2 100644 --- a/pkg/proxy/ipvs/proxier.go +++ b/pkg/proxy/ipvs/proxier.go @@ -1236,7 +1236,7 @@ func (proxier *Proxier) syncProxyRules() { activeBindAddrs[serv.Address.String()] = true // ExternalTrafficPolicy only works for NodePort and external LB traffic, does not affect ClusterIP // So we still need clusterIP rules in onlyNodeLocalEndpoints mode. - if err := proxier.syncEndpoint(svcName, false, svcInfo.OnlyNodeLocalEndpointsForInternal(), serv); err != nil { + if err := proxier.syncEndpoint(svcName, false, svcInfo.NodeLocalInternal(), serv); err != nil { klog.Errorf("Failed to sync endpoint for service: %v, err: %v", serv, err) } } else { @@ -1288,7 +1288,7 @@ func (proxier *Proxier) syncProxyRules() { SetType: utilipset.HashIPPort, } - if svcInfo.OnlyNodeLocalEndpoints() { + if svcInfo.NodeLocalExternal() { if valid := proxier.ipsetList[kubeExternalIPLocalSet].validateEntry(entry); !valid { klog.Errorf("%s", fmt.Sprintf(EntryInvalidErr, entry, proxier.ipsetList[kubeExternalIPLocalSet].Name)) continue @@ -1318,8 +1318,8 @@ func (proxier *Proxier) syncProxyRules() { activeIPVSServices[serv.String()] = true activeBindAddrs[serv.Address.String()] = true - onlyNodeLocalEndpoints := svcInfo.OnlyNodeLocalEndpoints() - onlyNodeLocalEndpointsForInternal := svcInfo.OnlyNodeLocalEndpointsForInternal() + onlyNodeLocalEndpoints := svcInfo.NodeLocalExternal() + onlyNodeLocalEndpointsForInternal := svcInfo.NodeLocalInternal() if err := proxier.syncEndpoint(svcName, onlyNodeLocalEndpoints, onlyNodeLocalEndpointsForInternal, serv); err != nil { klog.Errorf("Failed to sync endpoint for service: %v, err: %v", serv, err) } @@ -1348,7 +1348,7 @@ func (proxier *Proxier) syncProxyRules() { } proxier.ipsetList[kubeLoadBalancerSet].activeEntries.Insert(entry.String()) // insert loadbalancer entry to lbIngressLocalSet if service externaltrafficpolicy=local - if svcInfo.OnlyNodeLocalEndpoints() { + if svcInfo.NodeLocalExternal() { if valid := proxier.ipsetList[kubeLoadBalancerLocalSet].validateEntry(entry); !valid { klog.Errorf("%s", fmt.Sprintf(EntryInvalidErr, entry, proxier.ipsetList[kubeLoadBalancerLocalSet].Name)) continue @@ -1421,7 +1421,7 @@ func (proxier *Proxier) syncProxyRules() { if err := proxier.syncService(svcNameString, serv, true, bindedAddresses); err == nil { activeIPVSServices[serv.String()] = true activeBindAddrs[serv.Address.String()] = true - if err := proxier.syncEndpoint(svcName, svcInfo.OnlyNodeLocalEndpoints(), svcInfo.OnlyNodeLocalEndpointsForInternal(), serv); err != nil { + if err := proxier.syncEndpoint(svcName, svcInfo.NodeLocalExternal(), svcInfo.NodeLocalInternal(), serv); err != nil { klog.Errorf("Failed to sync endpoint for service: %v, err: %v", serv, err) } } else { @@ -1535,7 +1535,7 @@ func (proxier *Proxier) syncProxyRules() { } // Add externaltrafficpolicy=local type nodeport entry - if svcInfo.OnlyNodeLocalEndpoints() { + if svcInfo.NodeLocalExternal() { var nodePortLocalSet *IPSet switch protocol { case utilipset.ProtocolTCP: @@ -1580,7 +1580,7 @@ func (proxier *Proxier) syncProxyRules() { // There is no need to bind Node IP to dummy interface, so set parameter `bindAddr` to `false`. if err := proxier.syncService(svcNameString, serv, false, bindedAddresses); err == nil { activeIPVSServices[serv.String()] = true - if err := proxier.syncEndpoint(svcName, svcInfo.OnlyNodeLocalEndpoints(), svcInfo.OnlyNodeLocalEndpointsForInternal(), serv); err != nil { + if err := proxier.syncEndpoint(svcName, svcInfo.NodeLocalExternal(), svcInfo.NodeLocalInternal(), serv); err != nil { klog.Errorf("Failed to sync endpoint for service: %v, err: %v", serv, err) } } else { diff --git a/pkg/proxy/service.go b/pkg/proxy/service.go index a25ecc17041..a78930944a1 100644 --- a/pkg/proxy/service.go +++ b/pkg/proxy/service.go @@ -41,20 +41,20 @@ import ( // or can be used for constructing a more specific ServiceInfo struct // defined by the proxier if needed. type BaseServiceInfo struct { - clusterIP net.IP - port int - protocol v1.Protocol - nodePort int - loadBalancerStatus v1.LoadBalancerStatus - sessionAffinityType v1.ServiceAffinity - stickyMaxAgeSeconds int - externalIPs []string - loadBalancerSourceRanges []string - healthCheckNodePort int - onlyNodeLocalEndpoints bool - onlyNodeLocalEndpointsForInternal bool - internalTrafficPolicy *v1.ServiceInternalTrafficPolicyType - topologyKeys []string + clusterIP net.IP + port int + protocol v1.Protocol + nodePort int + loadBalancerStatus v1.LoadBalancerStatus + sessionAffinityType v1.ServiceAffinity + stickyMaxAgeSeconds int + externalIPs []string + loadBalancerSourceRanges []string + healthCheckNodePort int + nodeLocalExternal bool + nodeLocalInternal bool + internalTrafficPolicy *v1.ServiceInternalTrafficPolicyType + topologyKeys []string } var _ ServicePort = &BaseServiceInfo{} @@ -118,14 +118,14 @@ func (info *BaseServiceInfo) LoadBalancerIPStrings() []string { return ips } -// OnlyNodeLocalEndpoints is part of ServicePort interface. -func (info *BaseServiceInfo) OnlyNodeLocalEndpoints() bool { - return info.onlyNodeLocalEndpoints +// NodeLocalExternal is part of ServicePort interface. +func (info *BaseServiceInfo) NodeLocalExternal() bool { + return info.nodeLocalExternal } -// OnlyNodeLocalEndpointsForInternal is part of ServicePort interface -func (info *BaseServiceInfo) OnlyNodeLocalEndpointsForInternal() bool { - return info.onlyNodeLocalEndpointsForInternal +// NodeLocalInternal is part of ServicePort interface +func (info *BaseServiceInfo) NodeLocalInternal() bool { + return info.nodeLocalInternal } // InternalTrafficPolicy is part of ServicePort interface @@ -139,13 +139,13 @@ func (info *BaseServiceInfo) TopologyKeys() []string { } func (sct *ServiceChangeTracker) newBaseServiceInfo(port *v1.ServicePort, service *v1.Service) *BaseServiceInfo { - onlyNodeLocalEndpoints := false + nodeLocalExternal := false if apiservice.RequestsOnlyLocalTraffic(service) { - onlyNodeLocalEndpoints = true + nodeLocalExternal = true } - onlyNodeLocalEndpointsForInternal := false + nodeLocalInternal := false if utilfeature.DefaultFeatureGate.Enabled(features.ServiceInternalTrafficPolicy) { - onlyNodeLocalEndpointsForInternal = apiservice.RequestsOnlyLocalTrafficForInternal(service) + nodeLocalInternal = apiservice.RequestsOnlyLocalTrafficForInternal(service) } var stickyMaxAgeSeconds int if service.Spec.SessionAffinity == v1.ServiceAffinityClientIP { @@ -155,16 +155,16 @@ func (sct *ServiceChangeTracker) newBaseServiceInfo(port *v1.ServicePort, servic clusterIP := utilproxy.GetClusterIPByFamily(sct.ipFamily, service) info := &BaseServiceInfo{ - clusterIP: net.ParseIP(clusterIP), - port: int(port.Port), - protocol: port.Protocol, - nodePort: int(port.NodePort), - sessionAffinityType: service.Spec.SessionAffinity, - stickyMaxAgeSeconds: stickyMaxAgeSeconds, - onlyNodeLocalEndpoints: onlyNodeLocalEndpoints, - onlyNodeLocalEndpointsForInternal: onlyNodeLocalEndpointsForInternal, - internalTrafficPolicy: service.Spec.InternalTrafficPolicy, - topologyKeys: service.Spec.TopologyKeys, + clusterIP: net.ParseIP(clusterIP), + port: int(port.Port), + protocol: port.Protocol, + nodePort: int(port.NodePort), + sessionAffinityType: service.Spec.SessionAffinity, + stickyMaxAgeSeconds: stickyMaxAgeSeconds, + nodeLocalExternal: nodeLocalExternal, + nodeLocalInternal: nodeLocalInternal, + internalTrafficPolicy: service.Spec.InternalTrafficPolicy, + topologyKeys: service.Spec.TopologyKeys, } loadBalancerSourceRanges := make([]string, len(service.Spec.LoadBalancerSourceRanges)) diff --git a/pkg/proxy/types.go b/pkg/proxy/types.go index d88f2f826ff..9085bf0c743 100644 --- a/pkg/proxy/types.go +++ b/pkg/proxy/types.go @@ -83,10 +83,10 @@ type ServicePort interface { HealthCheckNodePort() int // GetNodePort returns a service Node port if present. If return 0, it means not present. NodePort() int - // GetOnlyNodeLocalEndpoints returns if a service has only node local endpoints - OnlyNodeLocalEndpoints() bool - // OnlyNodeLocalEndpointsForInternal returns if a service prefers routing to node local endpoints for internal traffic - OnlyNodeLocalEndpointsForInternal() bool + // NodeLocalExternal returns if a service has only node local endpoints for external traffic. + NodeLocalExternal() bool + // NodeLocalInternal returns if a service has only node local endpoints for internal traffic. + NodeLocalInternal() bool // InternalTrafficPolicy returns service InternalTrafficPolicy InternalTrafficPolicy() *v1.ServiceInternalTrafficPolicyType // TopologyKeys returns service TopologyKeys as a string array.