mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Cleanup iptables proxier
This commit is contained in:
parent
2c2b5f7379
commit
37a6989c79
@ -652,12 +652,16 @@ func updateServiceMap(
|
|||||||
syncRequired = false
|
syncRequired = false
|
||||||
staleServices = sets.NewString()
|
staleServices = sets.NewString()
|
||||||
|
|
||||||
for _, change := range changes.items {
|
func() {
|
||||||
mergeSyncRequired, existingPorts := serviceMap.mergeService(change.current)
|
changes.Lock()
|
||||||
unmergeSyncRequired := serviceMap.unmergeService(change.previous, existingPorts, staleServices)
|
defer changes.Unlock()
|
||||||
syncRequired = syncRequired || mergeSyncRequired || unmergeSyncRequired
|
for _, change := range changes.items {
|
||||||
}
|
mergeSyncRequired, existingPorts := serviceMap.mergeService(change.current)
|
||||||
changes.items = make(map[types.NamespacedName]*serviceChange)
|
unmergeSyncRequired := serviceMap.unmergeService(change.previous, existingPorts, staleServices)
|
||||||
|
syncRequired = syncRequired || mergeSyncRequired || unmergeSyncRequired
|
||||||
|
}
|
||||||
|
changes.items = make(map[types.NamespacedName]*serviceChange)
|
||||||
|
}()
|
||||||
|
|
||||||
// TODO: If this will appear to be computationally expensive, consider
|
// TODO: If this will appear to be computationally expensive, consider
|
||||||
// computing this incrementally similarly to serviceMap.
|
// computing this incrementally similarly to serviceMap.
|
||||||
@ -708,17 +712,22 @@ func updateEndpointsMap(
|
|||||||
hostname string) (syncRequired bool, hcEndpoints map[types.NamespacedName]int, staleSet map[endpointServicePair]bool) {
|
hostname string) (syncRequired bool, hcEndpoints map[types.NamespacedName]int, staleSet map[endpointServicePair]bool) {
|
||||||
syncRequired = false
|
syncRequired = false
|
||||||
staleSet = make(map[endpointServicePair]bool)
|
staleSet = make(map[endpointServicePair]bool)
|
||||||
for _, change := range changes.items {
|
|
||||||
oldEndpointsMap := endpointsToEndpointsMap(change.previous, hostname)
|
func() {
|
||||||
newEndpointsMap := endpointsToEndpointsMap(change.current, hostname)
|
changes.Lock()
|
||||||
if !reflect.DeepEqual(oldEndpointsMap, newEndpointsMap) {
|
defer changes.Unlock()
|
||||||
endpointsMap.unmerge(oldEndpointsMap)
|
for _, change := range changes.items {
|
||||||
endpointsMap.merge(newEndpointsMap)
|
oldEndpointsMap := endpointsToEndpointsMap(change.previous, hostname)
|
||||||
detectStaleConnections(oldEndpointsMap, newEndpointsMap, staleSet)
|
newEndpointsMap := endpointsToEndpointsMap(change.current, hostname)
|
||||||
syncRequired = true
|
if !reflect.DeepEqual(oldEndpointsMap, newEndpointsMap) {
|
||||||
|
endpointsMap.unmerge(oldEndpointsMap)
|
||||||
|
endpointsMap.merge(newEndpointsMap)
|
||||||
|
detectStaleConnections(oldEndpointsMap, newEndpointsMap, staleSet)
|
||||||
|
syncRequired = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
changes.items = make(map[types.NamespacedName]*endpointsChange)
|
||||||
changes.items = make(map[types.NamespacedName]*endpointsChange)
|
}()
|
||||||
|
|
||||||
if !utilfeature.DefaultFeatureGate.Enabled(features.ExternalTrafficLocalOnly) {
|
if !utilfeature.DefaultFeatureGate.Enabled(features.ExternalTrafficLocalOnly) {
|
||||||
return
|
return
|
||||||
@ -914,10 +923,8 @@ func (proxier *Proxier) syncProxyRules(reason syncReason) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Figure out the new services we need to activate.
|
// Figure out the new services we need to activate.
|
||||||
proxier.serviceChanges.Lock()
|
|
||||||
serviceSyncRequired, hcServices, staleServices := updateServiceMap(
|
serviceSyncRequired, hcServices, staleServices := updateServiceMap(
|
||||||
proxier.serviceMap, &proxier.serviceChanges)
|
proxier.serviceMap, &proxier.serviceChanges)
|
||||||
proxier.serviceChanges.Unlock()
|
|
||||||
|
|
||||||
// If this was called because of a services update, but nothing actionable has changed, skip it.
|
// If this was called because of a services update, but nothing actionable has changed, skip it.
|
||||||
if reason == syncReasonServices && !serviceSyncRequired {
|
if reason == syncReasonServices && !serviceSyncRequired {
|
||||||
@ -925,10 +932,8 @@ func (proxier *Proxier) syncProxyRules(reason syncReason) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
proxier.endpointsChanges.Lock()
|
|
||||||
endpointsSyncRequired, hcEndpoints, staleEndpoints := updateEndpointsMap(
|
endpointsSyncRequired, hcEndpoints, staleEndpoints := updateEndpointsMap(
|
||||||
proxier.endpointsMap, &proxier.endpointsChanges, proxier.hostname)
|
proxier.endpointsMap, &proxier.endpointsChanges, proxier.hostname)
|
||||||
proxier.endpointsChanges.Unlock()
|
|
||||||
|
|
||||||
// If this was called because of an endpoints update, but nothing actionable has changed, skip it.
|
// If this was called because of an endpoints update, but nothing actionable has changed, skip it.
|
||||||
if reason == syncReasonEndpoints && !endpointsSyncRequired {
|
if reason == syncReasonEndpoints && !endpointsSyncRequired {
|
||||||
|
Loading…
Reference in New Issue
Block a user