Skip to content

Commit 93de6a6

Browse files
committed
introduce a new runnable group for basic servers of the manager
1 parent e7b9407 commit 93de6a6

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

pkg/manager/internal.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,17 @@ func (cm *controllerManager) Start(ctx context.Context) (err error) {
459459
}
460460
}
461461

462-
// First start any webhook servers, which includes conversion, validation, and defaulting
462+
// First start any internal HTTP servers, which includes health probes, metrics and profiling if enabled.
463+
//
464+
// WARNING: Internal HTTP servers MUST start before any cache is populated, otherwise it would block
465+
// conversion webhooks to be ready for serving which make the cache never get ready.
466+
if err := cm.runnables.HTTPServers.Start(cm.internalCtx); err != nil {
467+
if err != nil {
468+
return fmt.Errorf("failed to start HTTP servers: %w", err)
469+
}
470+
}
471+
472+
// Start any webhook servers, which includes conversion, validation, and defaulting
463473
// webhooks that are registered.
464474
//
465475
// WARNING: Webhooks MUST start before any cache is populated, otherwise there is a race condition
@@ -591,10 +601,13 @@ func (cm *controllerManager) engageStopProcedure(stopComplete <-chan struct{}) e
591601
cm.logger.Info("Stopping and waiting for caches")
592602
cm.runnables.Caches.StopAndWait(cm.shutdownCtx)
593603

594-
// Webhooks should come last, as they might be still serving some requests.
604+
// Webhooks and internal HTTP servers should come last, as they might be still serving some requests.
595605
cm.logger.Info("Stopping and waiting for webhooks")
596606
cm.runnables.Webhooks.StopAndWait(cm.shutdownCtx)
597607

608+
cm.logger.Info("Stopping and waiting for HTTP servers")
609+
cm.runnables.HTTPServers.StopAndWait(cm.shutdownCtx)
610+
598611
// Proceed to close the manager and overall shutdown context.
599612
cm.logger.Info("Wait completed, proceeding to shutdown the manager")
600613
shutdownCancel()

pkg/manager/runnable_group.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type runnableCheck func(ctx context.Context) bool
2828
// runnables handles all the runnables for a manager by grouping them accordingly to their
2929
// type (webhooks, caches etc.).
3030
type runnables struct {
31+
HTTPServers *runnableGroup
3132
Webhooks *runnableGroup
3233
Caches *runnableGroup
3334
LeaderElection *runnableGroup
@@ -37,6 +38,7 @@ type runnables struct {
3738
// newRunnables creates a new runnables object.
3839
func newRunnables(baseContext BaseContextFunc, errChan chan error) *runnables {
3940
return &runnables{
41+
HTTPServers: newRunnableGroup(baseContext, errChan),
4042
Webhooks: newRunnableGroup(baseContext, errChan),
4143
Caches: newRunnableGroup(baseContext, errChan),
4244
LeaderElection: newRunnableGroup(baseContext, errChan),
@@ -52,6 +54,8 @@ func newRunnables(baseContext BaseContextFunc, errChan chan error) *runnables {
5254
// The runnables added after Start are started directly.
5355
func (r *runnables) Add(fn Runnable) error {
5456
switch runnable := fn.(type) {
57+
case *server:
58+
return r.HTTPServers.Add(fn, nil)
5559
case hasCache:
5660
return r.Caches.Add(fn, func(ctx context.Context) bool {
5761
return runnable.GetCache().WaitForCacheSync(ctx)

pkg/manager/runnable_group_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ var _ = Describe("runnables", func() {
2121
Expect(newRunnables(defaultBaseContext, errCh)).ToNot(BeNil())
2222
})
2323

24+
It("should add HTTP servers to the appropriate group", func() {
25+
server := &server{}
26+
r := newRunnables(defaultBaseContext, errCh)
27+
Expect(r.Add(server)).To(Succeed())
28+
Expect(r.HTTPServers.startQueue).To(HaveLen(1))
29+
})
30+
2431
It("should add caches to the appropriate group", func() {
2532
cache := &cacheProvider{cache: &informertest.FakeInformers{Error: fmt.Errorf("expected error")}}
2633
r := newRunnables(defaultBaseContext, errCh)

0 commit comments

Comments
 (0)