From 7a1e6d16cc690e52f43892b3469d51282185887d Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Thu, 23 Aug 2018 10:14:25 -0700 Subject: [PATCH] generic controller: allow controllers with only a resync func Signed-off-by: Steve Kriss --- pkg/controller/generic_controller.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/controller/generic_controller.go b/pkg/controller/generic_controller.go index e18b3e2436..11ec624ca4 100644 --- a/pkg/controller/generic_controller.go +++ b/pkg/controller/generic_controller.go @@ -53,9 +53,9 @@ func newGenericController(name string, logger logrus.FieldLogger) *genericContro // to process items in the work queue. It will return when it receives on the // ctx.Done() channel. func (c *genericController) Run(ctx context.Context, numWorkers int) error { - if c.syncHandler == nil { + if c.syncHandler == nil && c.resyncFunc == nil { // programmer error - panic("syncHandler is required") + panic("at least one of syncHandler or resyncFunc is required") } var wg sync.WaitGroup @@ -83,12 +83,14 @@ func (c *genericController) Run(ctx context.Context, numWorkers int) error { } c.logger.Info("Caches are synced") - wg.Add(numWorkers) - for i := 0; i < numWorkers; i++ { - go func() { - wait.Until(c.runWorker, time.Second, ctx.Done()) - wg.Done() - }() + if c.syncHandler != nil { + wg.Add(numWorkers) + for i := 0; i < numWorkers; i++ { + go func() { + wait.Until(c.runWorker, time.Second, ctx.Done()) + wg.Done() + }() + } } if c.resyncFunc != nil {