diff --git a/lib/services/watcher.go b/lib/services/watcher.go index 7699f5459b070..d06d97dc7c7c2 100644 --- a/lib/services/watcher.go +++ b/lib/services/watcher.go @@ -839,9 +839,9 @@ func (g *genericCollector[T, R]) processEventsAndUpdateCurrent(ctx context.Conte } key := g.ResourceKey(resource) - current := g.current[key] + current, exists := g.current[key] g.current[key] = resource - updated = g.ResourceDiffer(current, resource) + updated = !exists || g.ResourceDiffer(current, resource) default: g.Logger.WarnContext(ctx, "Skipping unsupported event type", "event_type", event.Type) } diff --git a/lib/services/watcher_test.go b/lib/services/watcher_test.go index 730c7430696a4..52988beae8355 100644 --- a/lib/services/watcher_test.go +++ b/lib/services/watcher_test.go @@ -134,6 +134,9 @@ func TestProxyWatcher(t *testing.T) { }, ProxyGetter: presence, ProxiesC: make(chan []types.Server, 10), + ProxyDiffer: func(old, new types.Server) bool { + return old.GetPeerAddr() != new.GetPeerAddr() + }, }) require.NoError(t, err) t.Cleanup(w.Close)