@@ -425,11 +425,13 @@ func (cm *controllerManager) serveHealthProbes() {
425
425
cm .healthzStarted = true
426
426
}()
427
427
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
+ }()
433
435
}
434
436
435
437
func (cm * controllerManager ) Start (ctx context.Context ) (err error ) {
@@ -473,9 +475,14 @@ func (cm *controllerManager) Start(ctx context.Context) (err error) {
473
475
474
476
// Serve health probes
475
477
if cm .healthProbeListener != nil {
476
- go cm .serveHealthProbes ()
478
+ cm .serveHealthProbes ()
477
479
}
478
480
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
+
479
486
go cm .startNonLeaderElectionRunnables ()
480
487
481
488
go func () {
@@ -573,13 +580,10 @@ func (cm *controllerManager) waitForRunnableToEnd(shutdownCancel context.CancelF
573
580
return nil
574
581
}
575
582
576
- func (cm * controllerManager ) startNonLeaderElectionRunnables () {
583
+ func (cm * controllerManager ) startWebhookRunnables () {
577
584
cm .mu .Lock ()
578
585
defer cm .mu .Unlock ()
579
586
580
- // First start any webhook servers, which includes conversion, validation, and defaulting
581
- // webhooks that are registered.
582
- //
583
587
// WARNING: Webhooks MUST start before any cache is populated, otherwise there is a race condition
584
588
// between conversion webhooks and the cache sync (usually initial list) which causes the webhooks
585
589
// to never start because no cache can be populated.
@@ -588,6 +592,11 @@ func (cm *controllerManager) startNonLeaderElectionRunnables() {
588
592
cm .startRunnable (c )
589
593
}
590
594
}
595
+ }
596
+
597
+ func (cm * controllerManager ) startNonLeaderElectionRunnables () {
598
+ cm .mu .Lock ()
599
+ defer cm .mu .Unlock ()
591
600
592
601
// Start and wait for caches.
593
602
cm .waitForCache (cm .internalCtx )
0 commit comments