From c8ead7af3e271e27eb5f81899eaccc4735979dec Mon Sep 17 00:00:00 2001 From: Will Daly Date: Tue, 30 Jul 2024 10:07:05 -0700 Subject: [PATCH] kube-proxy: initialization wait for service and endpoint handlers synced Ensure kube-proxy waits for the services/endpointslices informer caches to be synced *and* all pre-sync events delivered before setting isInitialized=true. Otherwise, in clusters with many services, some services may be missing from svcPortMap when kube-proxy starts (e.g. during daemonset rollout). This can cause kube-proxy to temporarily remove service DNAT rules and then skip cleanup of UDP conntrack entries to a service VIP. Resolves: https://github.com/kubernetes/kubernetes/issues/126468 --- pkg/proxy/config/config.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/proxy/config/config.go b/pkg/proxy/config/config.go index 090062c46ba9f..bcbbaf3005e25 100644 --- a/pkg/proxy/config/config.go +++ b/pkg/proxy/config/config.go @@ -71,11 +71,9 @@ type EndpointSliceConfig struct { // NewEndpointSliceConfig creates a new EndpointSliceConfig. func NewEndpointSliceConfig(endpointSliceInformer discoveryinformers.EndpointSliceInformer, resyncPeriod time.Duration) *EndpointSliceConfig { - result := &EndpointSliceConfig{ - listerSynced: endpointSliceInformer.Informer().HasSynced, - } + result := &EndpointSliceConfig{} - endpointSliceInformer.Informer().AddEventHandlerWithResyncPeriod( + handlerRegistration, _ := endpointSliceInformer.Informer().AddEventHandlerWithResyncPeriod( cache.ResourceEventHandlerFuncs{ AddFunc: result.handleAddEndpointSlice, UpdateFunc: result.handleUpdateEndpointSlice, @@ -84,6 +82,8 @@ func NewEndpointSliceConfig(endpointSliceInformer discoveryinformers.EndpointSli resyncPeriod, ) + result.listerSynced = handlerRegistration.HasSynced + return result } @@ -162,11 +162,9 @@ type ServiceConfig struct { // NewServiceConfig creates a new ServiceConfig. func NewServiceConfig(serviceInformer coreinformers.ServiceInformer, resyncPeriod time.Duration) *ServiceConfig { - result := &ServiceConfig{ - listerSynced: serviceInformer.Informer().HasSynced, - } + result := &ServiceConfig{} - serviceInformer.Informer().AddEventHandlerWithResyncPeriod( + handlerRegistration, _ := serviceInformer.Informer().AddEventHandlerWithResyncPeriod( cache.ResourceEventHandlerFuncs{ AddFunc: result.handleAddService, UpdateFunc: result.handleUpdateService, @@ -175,6 +173,8 @@ func NewServiceConfig(serviceInformer coreinformers.ServiceInformer, resyncPerio resyncPeriod, ) + result.listerSynced = handlerRegistration.HasSynced + return result }