Skip to content

Commit 5bd6cbb

Browse files
author
Will Daly
committed
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: kubernetes#126468
1 parent 0fc1671 commit 5bd6cbb

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pkg/proxy/config/config.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ type EndpointSliceConfig struct {
7878
// NewEndpointSliceConfig creates a new EndpointSliceConfig.
7979
func NewEndpointSliceConfig(ctx context.Context, endpointSliceInformer discoveryv1informers.EndpointSliceInformer, resyncPeriod time.Duration) *EndpointSliceConfig {
8080
result := &EndpointSliceConfig{
81-
listerSynced: endpointSliceInformer.Informer().HasSynced,
82-
logger: klog.FromContext(ctx),
81+
logger: klog.FromContext(ctx),
8382
}
8483

85-
_, _ = endpointSliceInformer.Informer().AddEventHandlerWithResyncPeriod(
84+
handlerRegistration, _ := endpointSliceInformer.Informer().AddEventHandlerWithResyncPeriod(
8685
cache.ResourceEventHandlerFuncs{
8786
AddFunc: result.handleAddEndpointSlice,
8887
UpdateFunc: result.handleUpdateEndpointSlice,
@@ -91,6 +90,8 @@ func NewEndpointSliceConfig(ctx context.Context, endpointSliceInformer discovery
9190
resyncPeriod,
9291
)
9392

93+
result.listerSynced = handlerRegistration.HasSynced
94+
9495
return result
9596
}
9697

@@ -171,11 +172,10 @@ type ServiceConfig struct {
171172
// NewServiceConfig creates a new ServiceConfig.
172173
func NewServiceConfig(ctx context.Context, serviceInformer v1informers.ServiceInformer, resyncPeriod time.Duration) *ServiceConfig {
173174
result := &ServiceConfig{
174-
listerSynced: serviceInformer.Informer().HasSynced,
175-
logger: klog.FromContext(ctx),
175+
logger: klog.FromContext(ctx),
176176
}
177177

178-
_, _ = serviceInformer.Informer().AddEventHandlerWithResyncPeriod(
178+
handlerRegistration, _ := serviceInformer.Informer().AddEventHandlerWithResyncPeriod(
179179
cache.ResourceEventHandlerFuncs{
180180
AddFunc: result.handleAddService,
181181
UpdateFunc: result.handleUpdateService,
@@ -184,6 +184,8 @@ func NewServiceConfig(ctx context.Context, serviceInformer v1informers.ServiceIn
184184
resyncPeriod,
185185
)
186186

187+
result.listerSynced = handlerRegistration.HasSynced
188+
187189
return result
188190
}
189191

0 commit comments

Comments
 (0)