Skip to content

Commit 201bdaa

Browse files
authored
Merge pull request kubernetes#126532 from wedaly/kube-proxy-initial-sync-race
kube-proxy: initialization wait for service and endpoint handlers synced
2 parents 702cea2 + 5bd6cbb commit 201bdaa

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)