generic controller: allow controllers with only a resync func

Signed-off-by: Steve Kriss <steve@heptio.com>
pull/799/head
Steve Kriss 2018-08-23 10:14:25 -07:00
parent 6f7bfe545d
commit 7a1e6d16cc
1 changed files with 10 additions and 8 deletions

View File

@ -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 {