mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Store chain names to avoid recomputing them multiple times
This commit is contained in:
parent
c4d51f12a2
commit
03c255d7c5
@ -148,6 +148,11 @@ type serviceInfo struct {
|
|||||||
loadBalancerSourceRanges []string
|
loadBalancerSourceRanges []string
|
||||||
onlyNodeLocalEndpoints bool
|
onlyNodeLocalEndpoints bool
|
||||||
healthCheckNodePort int
|
healthCheckNodePort int
|
||||||
|
// The following fields are computed and stored for performance reasons.
|
||||||
|
serviceNameString string
|
||||||
|
servicePortChainName utiliptables.Chain
|
||||||
|
serviceFirewallChainName utiliptables.Chain
|
||||||
|
serviceLBChainName utiliptables.Chain
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal struct for endpoints information
|
// internal struct for endpoints information
|
||||||
@ -214,6 +219,13 @@ func newServiceInfo(svcPortName proxy.ServicePortName, port *api.ServicePort, se
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store the following for performance reasons.
|
||||||
|
protocol := strings.ToLower(string(info.protocol))
|
||||||
|
info.serviceNameString = svcPortName.String()
|
||||||
|
info.servicePortChainName = servicePortChainName(info.serviceNameString, protocol)
|
||||||
|
info.serviceFirewallChainName = serviceFirewallChainName(info.serviceNameString, protocol)
|
||||||
|
info.serviceLBChainName = serviceLBChainName(info.serviceNameString, protocol)
|
||||||
|
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1124,14 +1136,13 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
args := make([]string, 64)
|
args := make([]string, 64)
|
||||||
|
|
||||||
// Build rules for each service.
|
// Build rules for each service.
|
||||||
|
var svcNameString string
|
||||||
for svcName, svcInfo := range proxier.serviceMap {
|
for svcName, svcInfo := range proxier.serviceMap {
|
||||||
protocol := strings.ToLower(string(svcInfo.protocol))
|
protocol := strings.ToLower(string(svcInfo.protocol))
|
||||||
// Precompute svcNameString; with many services the many calls
|
svcNameString = svcInfo.serviceNameString
|
||||||
// to ServicePortName.String() show up in CPU profiles.
|
|
||||||
svcNameString := svcName.String()
|
|
||||||
|
|
||||||
// Create the per-service chain, retaining counters if possible.
|
// Create the per-service chain, retaining counters if possible.
|
||||||
svcChain := servicePortChainName(svcNameString, protocol)
|
svcChain := svcInfo.servicePortChainName
|
||||||
if chain, ok := existingNATChains[svcChain]; ok {
|
if chain, ok := existingNATChains[svcChain]; ok {
|
||||||
writeLine(proxier.natChains, chain)
|
writeLine(proxier.natChains, chain)
|
||||||
} else {
|
} else {
|
||||||
@ -1139,7 +1150,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
}
|
}
|
||||||
activeNATChains[svcChain] = true
|
activeNATChains[svcChain] = true
|
||||||
|
|
||||||
svcXlbChain := serviceLBChainName(svcNameString, protocol)
|
svcXlbChain := svcInfo.serviceLBChainName
|
||||||
if svcInfo.onlyNodeLocalEndpoints {
|
if svcInfo.onlyNodeLocalEndpoints {
|
||||||
// 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.
|
||||||
@ -1243,10 +1254,10 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Capture load-balancer ingress.
|
// Capture load-balancer ingress.
|
||||||
|
fwChain := svcInfo.serviceFirewallChainName
|
||||||
for _, ingress := range svcInfo.loadBalancerStatus.Ingress {
|
for _, ingress := range svcInfo.loadBalancerStatus.Ingress {
|
||||||
if ingress.IP != "" {
|
if ingress.IP != "" {
|
||||||
// create service firewall chain
|
// create service firewall chain
|
||||||
fwChain := serviceFirewallChainName(svcNameString, protocol)
|
|
||||||
if chain, ok := existingNATChains[fwChain]; ok {
|
if chain, ok := existingNATChains[fwChain]; ok {
|
||||||
writeLine(proxier.natChains, chain)
|
writeLine(proxier.natChains, chain)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user