New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
skip iptables sync if no endpoint changes #41223
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -591,6 +591,7 @@ func (proxier *Proxier) OnEndpointsUpdate(allEndpoints []api.Endpoints) { | |
activeEndpoints := make(map[proxy.ServicePortName]bool) // use a map as a set | ||
staleConnections := make(map[endpointServicePair]bool) | ||
svcPortToInfoMap := make(map[proxy.ServicePortName][]hostPortInfo) | ||
newEndpointsMap := make(map[proxy.ServicePortName][]*endpointsInfo) | ||
|
||
// Update endpoints for services. | ||
for i := range allEndpoints { | ||
|
@@ -627,32 +628,38 @@ func (proxier *Proxier) OnEndpointsUpdate(allEndpoints []api.Endpoints) { | |
// Flatten the list of current endpoint infos to just a list of ips as strings | ||
curEndpointIPs := flattenEndpointsInfo(curEndpoints) | ||
if len(curEndpointIPs) != len(newEndpoints) || !slicesEquiv(slice.CopyStrings(curEndpointIPs), newEndpoints) { | ||
glog.V(3).Infof("Setting endpoints for %q to %+v", svcPort, newEndpoints) | ||
// Gather stale connections to removed endpoints | ||
removedEndpoints := getRemovedEndpoints(curEndpointIPs, newEndpoints) | ||
for _, ep := range removedEndpoints { | ||
staleConnections[endpointServicePair{endpoint: ep, servicePortName: svcPort}] = true | ||
} | ||
glog.V(3).Infof("Setting endpoints for %q to %+v", svcPort, newEndpoints) | ||
// Once the set operations using the list of ips are complete, build the list of endpoint infos | ||
proxier.endpointsMap[svcPort] = proxier.buildEndpointInfoList(portsToEndpoints[portname], newEndpoints) | ||
} | ||
// Once the set operations using the list of ips are complete, build the list of endpoint infos | ||
newEndpointsMap[svcPort] = proxier.buildEndpointInfoList(portsToEndpoints[portname], newEndpoints) | ||
activeEndpoints[svcPort] = true | ||
} | ||
} | ||
// Remove endpoints missing from the update. | ||
// Check stale connections against endpoints missing from the update. | ||
for svcPort := range proxier.endpointsMap { | ||
if !activeEndpoints[svcPort] { | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment: this version seems cleaner since we're not deleting from the map we're iterating, and there's no residual state as we start with a fresh map everytime. |
||
} | ||
|
||
glog.V(2).Infof("Removing endpoints for %q", svcPort) | ||
delete(proxier.endpointsMap, svcPort) | ||
} | ||
|
||
proxier.updateHealthCheckEntries(svcPort.NamespacedName, svcPortToInfoMap[svcPort]) | ||
} | ||
proxier.syncProxyRules() | ||
|
||
if len(newEndpointsMap) != len(proxier.endpointsMap) || !reflect.DeepEqual(newEndpointsMap, proxier.endpointsMap) { | ||
proxier.endpointsMap = newEndpointsMap | ||
proxier.syncProxyRules() | ||
} else { | ||
glog.V(4).Infof("Skipping proxy iptables rule sync on endpoint update because nothing changed") | ||
} | ||
|
||
proxier.deleteEndpointConnections(staleConnections) | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: The only significant diff is that we were only doing the work to
buildEndpointInfoList
lazily, but that function only seems as expensive asflattenEndpointsInfo
anyway (O(endpoints)), so I don't think we're burning any more cpu.