wait for informer caches to sync before running controllers

Signed-off-by: Steve Kriss <krisss@vmware.com>
This commit is contained in:
Steve Kriss
2020-03-03 15:55:17 -07:00
parent 36e76518da
commit c7f283c7fa
16 changed files with 170 additions and 198 deletions
+7 -4
View File
@@ -76,11 +76,14 @@ func (c *genericController) Run(ctx context.Context, numWorkers int) error {
c.logger.Info("Starting controller")
defer c.logger.Info("Shutting down controller")
c.logger.Info("Waiting for caches to sync")
if !cache.WaitForCacheSync(ctx.Done(), c.cacheSyncWaiters...) {
return errors.New("timed out waiting for caches to sync")
// only want to log about cache sync waiters if there are any
if len(c.cacheSyncWaiters) > 0 {
c.logger.Info("Waiting for caches to sync")
if !cache.WaitForCacheSync(ctx.Done(), c.cacheSyncWaiters...) {
return errors.New("timed out waiting for caches to sync")
}
c.logger.Info("Caches are synced")
}
c.logger.Info("Caches are synced")
if c.syncHandler != nil {
wg.Add(numWorkers)