Skip to content

Commit 8dbcd1c

Browse files
author
zhoubo9
committed
feat: Fix webhook race condition kubernetes-sigs#1
1 parent f7a3dc6 commit 8dbcd1c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

pkg/manager/internal.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,16 +591,47 @@ func (cm *controllerManager) startNonLeaderElectionRunnables() {
591591
cm.mu.Lock()
592592
defer cm.mu.Unlock()
593593

594+
// First start any webhook servers, which includes conversion, validation, and defaulting
595+
// webhooks that are registered.
596+
//
597+
// WARNING: Webhooks MUST start before any cache is populated, otherwise there is a race condition
598+
// between conversion webhooks and the cache sync (usually initial list) which causes the webhooks
599+
// to never start because no cache can be populated.
600+
for _, c := range cm.nonLeaderElectionRunnables {
601+
if _, ok := c.(*webhook.Server); ok {
602+
cm.startRunnable(c)
603+
}
604+
}
605+
606+
// Start and wait for caches.
594607
cm.waitForCache(cm.internalCtx)
595608

596609
// Start the non-leaderelection Runnables after the cache has synced
597610
for _, c := range cm.nonLeaderElectionRunnables {
611+
if _, ok := c.(*webhook.Server); ok {
612+
continue
613+
}
614+
598615
// Controllers block, but we want to return an error if any have an error starting.
599616
// Write any Start errors to a channel so we can return them
600617
cm.startRunnable(c)
601618
}
602619
}
603620

621+
//func (cm *controllerManager) startNonLeaderElectionRunnables() {
622+
// cm.mu.Lock()
623+
// defer cm.mu.Unlock()
624+
//
625+
// cm.waitForCache(cm.internalCtx)
626+
//
627+
// // Start the non-leaderelection Runnables after the cache has synced
628+
// for _, c := range cm.nonLeaderElectionRunnables {
629+
// // Controllers block, but we want to return an error if any have an error starting.
630+
// // Write any Start errors to a channel so we can return them
631+
// cm.startRunnable(c)
632+
// }
633+
//}
634+
604635
func (cm *controllerManager) startLeaderElectionRunnables() {
605636
cm.mu.Lock()
606637
defer cm.mu.Unlock()

0 commit comments

Comments
 (0)