mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
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;
This commit is contained in:
parent
7ed2f1d94d
commit
0621e90d31
@ -1025,7 +1025,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
// 2. ServiceTopology is not enabled.
|
// 2. ServiceTopology is not enabled.
|
||||||
// 3. EndpointSlice is not enabled (service topology depends on endpoint slice
|
// 3. EndpointSlice is not enabled (service topology depends on endpoint slice
|
||||||
// to get topology information).
|
// 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)
|
allEndpoints = proxy.FilterTopologyEndpoint(proxier.nodeLabels, svcInfo.TopologyKeys(), allEndpoints)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1033,7 +1033,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
// following are true:
|
// following are true:
|
||||||
// 1. InternalTrafficPolicy is Local
|
// 1. InternalTrafficPolicy is Local
|
||||||
// 2. ServiceInternalTrafficPolicy feature gate is on
|
// 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)
|
allEndpoints = proxy.FilterLocalEndpoint(svcInfo.InternalTrafficPolicy(), allEndpoints)
|
||||||
}
|
}
|
||||||
readyEndpoints := make([]proxy.Endpoint, 0, len(allEndpoints))
|
readyEndpoints := make([]proxy.Endpoint, 0, len(allEndpoints))
|
||||||
@ -1058,7 +1058,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
svcXlbChain := svcInfo.serviceLBChainName
|
svcXlbChain := svcInfo.serviceLBChainName
|
||||||
if svcInfo.OnlyNodeLocalEndpoints() {
|
if svcInfo.NodeLocalExternal() {
|
||||||
// Only for services request OnlyLocal traffic
|
// Only for services request OnlyLocal traffic
|
||||||
// create the per-service LB chain, retaining counters if possible.
|
// create the per-service LB chain, retaining counters if possible.
|
||||||
if lbChain, ok := existingNATChains[svcXlbChain]; ok {
|
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
|
// 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
|
// be always forwarded to the corresponding Service, so no need to SNAT
|
||||||
// If we can't differentiate the local traffic we always SNAT.
|
// If we can't differentiate the local traffic we always SNAT.
|
||||||
if !svcInfo.OnlyNodeLocalEndpoints() {
|
if !svcInfo.NodeLocalExternal() {
|
||||||
destChain = svcChain
|
destChain = svcChain
|
||||||
// This masquerades off-cluster traffic to a External IP.
|
// This masquerades off-cluster traffic to a External IP.
|
||||||
if proxier.localDetector.IsImplemented() {
|
if proxier.localDetector.IsImplemented() {
|
||||||
@ -1211,7 +1211,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
chosenChain := svcXlbChain
|
chosenChain := svcXlbChain
|
||||||
// If we are proxying globally, we need to masquerade in case we cross nodes.
|
// 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 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))...)
|
utilproxy.WriteLine(proxier.natRules, append(args, "-j", string(KubeMarkMasqChain))...)
|
||||||
chosenChain = svcChain
|
chosenChain = svcChain
|
||||||
}
|
}
|
||||||
@ -1308,7 +1308,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
"-m", protocol, "-p", protocol,
|
"-m", protocol, "-p", protocol,
|
||||||
"--dport", strconv.Itoa(svcInfo.NodePort()),
|
"--dport", strconv.Itoa(svcInfo.NodePort()),
|
||||||
)
|
)
|
||||||
if !svcInfo.OnlyNodeLocalEndpoints() {
|
if !svcInfo.NodeLocalExternal() {
|
||||||
// Nodeports need SNAT, unless they're local.
|
// Nodeports need SNAT, unless they're local.
|
||||||
utilproxy.WriteLine(proxier.natRules, append(args, "-j", string(KubeMarkMasqChain))...)
|
utilproxy.WriteLine(proxier.natRules, append(args, "-j", string(KubeMarkMasqChain))...)
|
||||||
// Jump to the service chain.
|
// Jump to the service chain.
|
||||||
@ -1402,7 +1402,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
localEndpointChains := make([]utiliptables.Chain, 0)
|
localEndpointChains := make([]utiliptables.Chain, 0)
|
||||||
for i, endpointChain := range endpointChains {
|
for i, endpointChain := range endpointChains {
|
||||||
// Write ingress loadbalancing & DNAT rules only for services that request OnlyLocal traffic.
|
// 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])
|
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
|
// The logic below this applies only if this service is marked as OnlyLocal
|
||||||
if !svcInfo.OnlyNodeLocalEndpoints() {
|
if !svcInfo.NodeLocalExternal() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1236,7 +1236,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
activeBindAddrs[serv.Address.String()] = true
|
activeBindAddrs[serv.Address.String()] = true
|
||||||
// ExternalTrafficPolicy only works for NodePort and external LB traffic, does not affect ClusterIP
|
// ExternalTrafficPolicy only works for NodePort and external LB traffic, does not affect ClusterIP
|
||||||
// So we still need clusterIP rules in onlyNodeLocalEndpoints mode.
|
// 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)
|
klog.Errorf("Failed to sync endpoint for service: %v, err: %v", serv, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1288,7 +1288,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
SetType: utilipset.HashIPPort,
|
SetType: utilipset.HashIPPort,
|
||||||
}
|
}
|
||||||
|
|
||||||
if svcInfo.OnlyNodeLocalEndpoints() {
|
if svcInfo.NodeLocalExternal() {
|
||||||
if valid := proxier.ipsetList[kubeExternalIPLocalSet].validateEntry(entry); !valid {
|
if valid := proxier.ipsetList[kubeExternalIPLocalSet].validateEntry(entry); !valid {
|
||||||
klog.Errorf("%s", fmt.Sprintf(EntryInvalidErr, entry, proxier.ipsetList[kubeExternalIPLocalSet].Name))
|
klog.Errorf("%s", fmt.Sprintf(EntryInvalidErr, entry, proxier.ipsetList[kubeExternalIPLocalSet].Name))
|
||||||
continue
|
continue
|
||||||
@ -1318,8 +1318,8 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
activeIPVSServices[serv.String()] = true
|
activeIPVSServices[serv.String()] = true
|
||||||
activeBindAddrs[serv.Address.String()] = true
|
activeBindAddrs[serv.Address.String()] = true
|
||||||
|
|
||||||
onlyNodeLocalEndpoints := svcInfo.OnlyNodeLocalEndpoints()
|
onlyNodeLocalEndpoints := svcInfo.NodeLocalExternal()
|
||||||
onlyNodeLocalEndpointsForInternal := svcInfo.OnlyNodeLocalEndpointsForInternal()
|
onlyNodeLocalEndpointsForInternal := svcInfo.NodeLocalInternal()
|
||||||
if err := proxier.syncEndpoint(svcName, onlyNodeLocalEndpoints, onlyNodeLocalEndpointsForInternal, serv); err != nil {
|
if err := proxier.syncEndpoint(svcName, onlyNodeLocalEndpoints, onlyNodeLocalEndpointsForInternal, serv); err != nil {
|
||||||
klog.Errorf("Failed to sync endpoint for service: %v, err: %v", serv, err)
|
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())
|
proxier.ipsetList[kubeLoadBalancerSet].activeEntries.Insert(entry.String())
|
||||||
// insert loadbalancer entry to lbIngressLocalSet if service externaltrafficpolicy=local
|
// insert loadbalancer entry to lbIngressLocalSet if service externaltrafficpolicy=local
|
||||||
if svcInfo.OnlyNodeLocalEndpoints() {
|
if svcInfo.NodeLocalExternal() {
|
||||||
if valid := proxier.ipsetList[kubeLoadBalancerLocalSet].validateEntry(entry); !valid {
|
if valid := proxier.ipsetList[kubeLoadBalancerLocalSet].validateEntry(entry); !valid {
|
||||||
klog.Errorf("%s", fmt.Sprintf(EntryInvalidErr, entry, proxier.ipsetList[kubeLoadBalancerLocalSet].Name))
|
klog.Errorf("%s", fmt.Sprintf(EntryInvalidErr, entry, proxier.ipsetList[kubeLoadBalancerLocalSet].Name))
|
||||||
continue
|
continue
|
||||||
@ -1421,7 +1421,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
if err := proxier.syncService(svcNameString, serv, true, bindedAddresses); err == nil {
|
if err := proxier.syncService(svcNameString, serv, true, bindedAddresses); err == nil {
|
||||||
activeIPVSServices[serv.String()] = true
|
activeIPVSServices[serv.String()] = true
|
||||||
activeBindAddrs[serv.Address.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)
|
klog.Errorf("Failed to sync endpoint for service: %v, err: %v", serv, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1535,7 +1535,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add externaltrafficpolicy=local type nodeport entry
|
// Add externaltrafficpolicy=local type nodeport entry
|
||||||
if svcInfo.OnlyNodeLocalEndpoints() {
|
if svcInfo.NodeLocalExternal() {
|
||||||
var nodePortLocalSet *IPSet
|
var nodePortLocalSet *IPSet
|
||||||
switch protocol {
|
switch protocol {
|
||||||
case utilipset.ProtocolTCP:
|
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`.
|
// 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 {
|
if err := proxier.syncService(svcNameString, serv, false, bindedAddresses); err == nil {
|
||||||
activeIPVSServices[serv.String()] = true
|
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)
|
klog.Errorf("Failed to sync endpoint for service: %v, err: %v", serv, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -41,20 +41,20 @@ import (
|
|||||||
// or can be used for constructing a more specific ServiceInfo struct
|
// or can be used for constructing a more specific ServiceInfo struct
|
||||||
// defined by the proxier if needed.
|
// defined by the proxier if needed.
|
||||||
type BaseServiceInfo struct {
|
type BaseServiceInfo struct {
|
||||||
clusterIP net.IP
|
clusterIP net.IP
|
||||||
port int
|
port int
|
||||||
protocol v1.Protocol
|
protocol v1.Protocol
|
||||||
nodePort int
|
nodePort int
|
||||||
loadBalancerStatus v1.LoadBalancerStatus
|
loadBalancerStatus v1.LoadBalancerStatus
|
||||||
sessionAffinityType v1.ServiceAffinity
|
sessionAffinityType v1.ServiceAffinity
|
||||||
stickyMaxAgeSeconds int
|
stickyMaxAgeSeconds int
|
||||||
externalIPs []string
|
externalIPs []string
|
||||||
loadBalancerSourceRanges []string
|
loadBalancerSourceRanges []string
|
||||||
healthCheckNodePort int
|
healthCheckNodePort int
|
||||||
onlyNodeLocalEndpoints bool
|
nodeLocalExternal bool
|
||||||
onlyNodeLocalEndpointsForInternal bool
|
nodeLocalInternal bool
|
||||||
internalTrafficPolicy *v1.ServiceInternalTrafficPolicyType
|
internalTrafficPolicy *v1.ServiceInternalTrafficPolicyType
|
||||||
topologyKeys []string
|
topologyKeys []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ ServicePort = &BaseServiceInfo{}
|
var _ ServicePort = &BaseServiceInfo{}
|
||||||
@ -118,14 +118,14 @@ func (info *BaseServiceInfo) LoadBalancerIPStrings() []string {
|
|||||||
return ips
|
return ips
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnlyNodeLocalEndpoints is part of ServicePort interface.
|
// NodeLocalExternal is part of ServicePort interface.
|
||||||
func (info *BaseServiceInfo) OnlyNodeLocalEndpoints() bool {
|
func (info *BaseServiceInfo) NodeLocalExternal() bool {
|
||||||
return info.onlyNodeLocalEndpoints
|
return info.nodeLocalExternal
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnlyNodeLocalEndpointsForInternal is part of ServicePort interface
|
// NodeLocalInternal is part of ServicePort interface
|
||||||
func (info *BaseServiceInfo) OnlyNodeLocalEndpointsForInternal() bool {
|
func (info *BaseServiceInfo) NodeLocalInternal() bool {
|
||||||
return info.onlyNodeLocalEndpointsForInternal
|
return info.nodeLocalInternal
|
||||||
}
|
}
|
||||||
|
|
||||||
// InternalTrafficPolicy is part of ServicePort interface
|
// 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 {
|
func (sct *ServiceChangeTracker) newBaseServiceInfo(port *v1.ServicePort, service *v1.Service) *BaseServiceInfo {
|
||||||
onlyNodeLocalEndpoints := false
|
nodeLocalExternal := false
|
||||||
if apiservice.RequestsOnlyLocalTraffic(service) {
|
if apiservice.RequestsOnlyLocalTraffic(service) {
|
||||||
onlyNodeLocalEndpoints = true
|
nodeLocalExternal = true
|
||||||
}
|
}
|
||||||
onlyNodeLocalEndpointsForInternal := false
|
nodeLocalInternal := false
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(features.ServiceInternalTrafficPolicy) {
|
if utilfeature.DefaultFeatureGate.Enabled(features.ServiceInternalTrafficPolicy) {
|
||||||
onlyNodeLocalEndpointsForInternal = apiservice.RequestsOnlyLocalTrafficForInternal(service)
|
nodeLocalInternal = apiservice.RequestsOnlyLocalTrafficForInternal(service)
|
||||||
}
|
}
|
||||||
var stickyMaxAgeSeconds int
|
var stickyMaxAgeSeconds int
|
||||||
if service.Spec.SessionAffinity == v1.ServiceAffinityClientIP {
|
if service.Spec.SessionAffinity == v1.ServiceAffinityClientIP {
|
||||||
@ -155,16 +155,16 @@ func (sct *ServiceChangeTracker) newBaseServiceInfo(port *v1.ServicePort, servic
|
|||||||
|
|
||||||
clusterIP := utilproxy.GetClusterIPByFamily(sct.ipFamily, service)
|
clusterIP := utilproxy.GetClusterIPByFamily(sct.ipFamily, service)
|
||||||
info := &BaseServiceInfo{
|
info := &BaseServiceInfo{
|
||||||
clusterIP: net.ParseIP(clusterIP),
|
clusterIP: net.ParseIP(clusterIP),
|
||||||
port: int(port.Port),
|
port: int(port.Port),
|
||||||
protocol: port.Protocol,
|
protocol: port.Protocol,
|
||||||
nodePort: int(port.NodePort),
|
nodePort: int(port.NodePort),
|
||||||
sessionAffinityType: service.Spec.SessionAffinity,
|
sessionAffinityType: service.Spec.SessionAffinity,
|
||||||
stickyMaxAgeSeconds: stickyMaxAgeSeconds,
|
stickyMaxAgeSeconds: stickyMaxAgeSeconds,
|
||||||
onlyNodeLocalEndpoints: onlyNodeLocalEndpoints,
|
nodeLocalExternal: nodeLocalExternal,
|
||||||
onlyNodeLocalEndpointsForInternal: onlyNodeLocalEndpointsForInternal,
|
nodeLocalInternal: nodeLocalInternal,
|
||||||
internalTrafficPolicy: service.Spec.InternalTrafficPolicy,
|
internalTrafficPolicy: service.Spec.InternalTrafficPolicy,
|
||||||
topologyKeys: service.Spec.TopologyKeys,
|
topologyKeys: service.Spec.TopologyKeys,
|
||||||
}
|
}
|
||||||
|
|
||||||
loadBalancerSourceRanges := make([]string, len(service.Spec.LoadBalancerSourceRanges))
|
loadBalancerSourceRanges := make([]string, len(service.Spec.LoadBalancerSourceRanges))
|
||||||
|
@ -83,10 +83,10 @@ type ServicePort interface {
|
|||||||
HealthCheckNodePort() int
|
HealthCheckNodePort() int
|
||||||
// GetNodePort returns a service Node port if present. If return 0, it means not present.
|
// GetNodePort returns a service Node port if present. If return 0, it means not present.
|
||||||
NodePort() int
|
NodePort() int
|
||||||
// GetOnlyNodeLocalEndpoints returns if a service has only node local endpoints
|
// NodeLocalExternal returns if a service has only node local endpoints for external traffic.
|
||||||
OnlyNodeLocalEndpoints() bool
|
NodeLocalExternal() bool
|
||||||
// OnlyNodeLocalEndpointsForInternal returns if a service prefers routing to node local endpoints for internal traffic
|
// NodeLocalInternal returns if a service has only node local endpoints for internal traffic.
|
||||||
OnlyNodeLocalEndpointsForInternal() bool
|
NodeLocalInternal() bool
|
||||||
// InternalTrafficPolicy returns service InternalTrafficPolicy
|
// InternalTrafficPolicy returns service InternalTrafficPolicy
|
||||||
InternalTrafficPolicy() *v1.ServiceInternalTrafficPolicyType
|
InternalTrafficPolicy() *v1.ServiceInternalTrafficPolicyType
|
||||||
// TopologyKeys returns service TopologyKeys as a string array.
|
// TopologyKeys returns service TopologyKeys as a string array.
|
||||||
|
Loading…
Reference in New Issue
Block a user