Skip to content

Commit

Permalink
Refactor ES addition logic in Destination
Browse files Browse the repository at this point in the history
This is a second take on #12427, which avoided a theoretical/correctness
issue around overwritting new ES addresses with stale data.

We had to revert that in #12589 because the change introduced a bug, by
returning early when the ES had no addresses and failed to properly
initiallize `addesses` for the portPublisher.

This just removes the early return.
  • Loading branch information
alpeb committed May 20, 2024
1 parent 47c3118 commit 33c677f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions controller/api/destination/watcher/endpoints_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,17 +795,22 @@ 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)
}

for _, listener := range pp.listeners {
listener.Add(add)
}

// even if the ES doesn't have addresses yet we need to create a new
// pp.addresses entry with the appropriate Labels and LocalTrafficPolicy,
// which isn't going to be captured during the ES update event when
// addresses get added

pp.addresses = newAddressSet
pp.exists = true
pp.metrics.incUpdates()
Expand Down

0 comments on commit 33c677f

Please sign in to comment.