Fix destination staleness issue when adding EndpointSlices (#12427)

When updating the portPublisher's address set when a new EndpointSlice creation event is received, its addresses where getting overwritten with stale data whenever its IDs already existed in the current pp's address set.

There can be pathological cases in single-stack where this can be a problem. For example when ES get recycled but the deletion event is not caught for some reason, when the addition event is received its Address data will be overwritten by the old stale entry.

## Other Changes

- Remove overriding `newAddressSet.LocalTrafficPolicy` as that is already taken care inside `pp.endpointSliceToAddresses(slice)`.
- When there are no Add events to send, return early without updating state nor updating metrics.
This commit is contained in:
Alejandro Pedraza 2024-05-08 09:12:51 -05:00 committed by GitHub
parent 9882212964
commit 4fccf3e9ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 6 deletions

View File

@ -795,15 +795,18 @@ func (pp *portPublisher) updateEndpoints(endpoints *corev1.Endpoints) {
func (pp *portPublisher) addEndpointSlice(slice *discovery.EndpointSlice) {
newAddressSet := pp.endpointSliceToAddresses(slice)
for id, addr := range pp.addresses.Addresses {
newAddressSet.Addresses[id] = addr
newAddressSet.LocalTrafficPolicy = pp.localTrafficPolicy
if _, ok := newAddressSet.Addresses[id]; !ok {
newAddressSet.Addresses[id] = addr
}
}
add, _ := diffAddresses(pp.addresses, newAddressSet)
if len(add.Addresses) > 0 {
for _, listener := range pp.listeners {
listener.Add(add)
}
if len(add.Addresses) == 0 {
return
}
for _, listener := range pp.listeners {
listener.Add(add)
}
pp.addresses = newAddressSet