Skip to content

Commit

Permalink
generic controller: allow controllers with only a resync func
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kriss <[email protected]>
  • Loading branch information
skriss committed Aug 28, 2018
1 parent 6f7bfe5 commit 7a1e6d1
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pkg/controller/generic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7a1e6d1

Please sign in to comment.