Skip to content

Commit f8472ce

Browse files
authored
Merge pull request #1690 from fabriziopandini/start-webhooks-first
🐛 Start web hooks first
2 parents 43ea648 + 708d539 commit f8472ce

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

pkg/manager/internal.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,13 @@ func (cm *controllerManager) serveHealthProbes() {
425425
cm.healthzStarted = true
426426
}()
427427

428-
// Shutdown the server when stop is closed
429-
<-cm.internalProceduresStop
430-
if err := server.Shutdown(cm.shutdownCtx); err != nil {
431-
cm.errChan <- err
432-
}
428+
go func() {
429+
// Shutdown the server when stop is closed
430+
<-cm.internalProceduresStop
431+
if err := server.Shutdown(cm.shutdownCtx); err != nil {
432+
cm.errChan <- err
433+
}
434+
}()
433435
}
434436

435437
func (cm *controllerManager) Start(ctx context.Context) (err error) {
@@ -473,9 +475,14 @@ func (cm *controllerManager) Start(ctx context.Context) (err error) {
473475

474476
// Serve health probes
475477
if cm.healthProbeListener != nil {
476-
go cm.serveHealthProbes()
478+
cm.serveHealthProbes()
477479
}
478480

481+
// Webhooks MUST start before any cache is populated, otherwise there is a race condition
482+
// between conversion webhooks and the cache sync (usually initial list) which causes the webhooks
483+
// to never start because no cache can be populated.
484+
cm.startWebhookRunnables()
485+
479486
go cm.startNonLeaderElectionRunnables()
480487

481488
go func() {
@@ -573,13 +580,10 @@ func (cm *controllerManager) waitForRunnableToEnd(shutdownCancel context.CancelF
573580
return nil
574581
}
575582

576-
func (cm *controllerManager) startNonLeaderElectionRunnables() {
583+
func (cm *controllerManager) startWebhookRunnables() {
577584
cm.mu.Lock()
578585
defer cm.mu.Unlock()
579586

580-
// First start any webhook servers, which includes conversion, validation, and defaulting
581-
// webhooks that are registered.
582-
//
583587
// WARNING: Webhooks MUST start before any cache is populated, otherwise there is a race condition
584588
// between conversion webhooks and the cache sync (usually initial list) which causes the webhooks
585589
// to never start because no cache can be populated.
@@ -588,6 +592,11 @@ func (cm *controllerManager) startNonLeaderElectionRunnables() {
588592
cm.startRunnable(c)
589593
}
590594
}
595+
}
596+
597+
func (cm *controllerManager) startNonLeaderElectionRunnables() {
598+
cm.mu.Lock()
599+
defer cm.mu.Unlock()
591600

592601
// Start and wait for caches.
593602
cm.waitForCache(cm.internalCtx)

0 commit comments

Comments
 (0)