From 3bee7ab51b6ccd4edf554e747d122ca717d9e3e5 Mon Sep 17 00:00:00 2001 From: fabriziopandini Date: Mon, 11 Oct 2021 15:36:08 +0200 Subject: [PATCH] Start web hooks first --- pkg/manager/internal.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/manager/internal.go b/pkg/manager/internal.go index 7c25bd3c60..0e9309d6b4 100644 --- a/pkg/manager/internal.go +++ b/pkg/manager/internal.go @@ -476,6 +476,11 @@ func (cm *controllerManager) Start(ctx context.Context) (err error) { go cm.serveHealthProbes() } + // Webhooks MUST start before any cache is populated, otherwise there is a race condition + // between conversion webhooks and the cache sync (usually initial list) which causes the webhooks + // to never start because no cache can be populated. + cm.startWebHookRunnable() + go cm.startNonLeaderElectionRunnables() go func() { @@ -573,13 +578,10 @@ func (cm *controllerManager) waitForRunnableToEnd(shutdownCancel context.CancelF return nil } -func (cm *controllerManager) startNonLeaderElectionRunnables() { +func (cm *controllerManager) startWebHookRunnable() { cm.mu.Lock() defer cm.mu.Unlock() - // First start any webhook servers, which includes conversion, validation, and defaulting - // webhooks that are registered. - // // WARNING: Webhooks MUST start before any cache is populated, otherwise there is a race condition // between conversion webhooks and the cache sync (usually initial list) which causes the webhooks // to never start because no cache can be populated. @@ -588,6 +590,11 @@ func (cm *controllerManager) startNonLeaderElectionRunnables() { cm.startRunnable(c) } } +} + +func (cm *controllerManager) startNonLeaderElectionRunnables() { + cm.mu.Lock() + defer cm.mu.Unlock() // Start and wait for caches. cm.waitForCache(cm.internalCtx)