Delay start of informers in sharedmain (#1767)

The EnableInjectionOrDie starts informers immedidately in a go
routine, which changes the order of informer start and controller
setup. As a result setting resync period to informer handler will
be ignored as the informer is already started. Though this will
likely affect more components, changing the EnableInjectionOrDie
function will break the API, so this is a temporary solution to
fix all the controllers depending on sharedmain.
This commit is contained in:
Zhongduo Lin (Jimmy) 2020-10-03 13:57:33 -04:00 committed by GitHub
parent 84e91da23c
commit ea7374e811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -225,7 +225,16 @@ func MainWithConfig(ctx context.Context, component string, cfg *rest.Config, cto
cfg.Burst = len(ctors) * rest.DefaultBurst
}
ctx = EnableInjectionOrDie(ctx, cfg)
// Respect user provided settings, but if omitted customize the default behavior.
if cfg.QPS == 0 {
cfg.QPS = rest.DefaultQPS
}
if cfg.Burst == 0 {
cfg.Burst = rest.DefaultBurst
}
ctx = injection.WithConfig(ctx, cfg)
ctx, informers := injection.Default.SetupInformers(ctx, cfg)
logger, atomicLevel := SetupLoggerOrDie(ctx, component)
defer flush(logger)
@ -278,7 +287,11 @@ func MainWithConfig(ctx context.Context, component string, cfg *rest.Config, cto
return wh.Run(ctx.Done())
})
}
// Start the injection clients and informers.
logging.FromContext(ctx).Info("Starting informers...")
if err := controller.StartInformers(ctx.Done(), informers...); err != nil {
logging.FromContext(ctx).Fatalw("Failed to start informers", zap.Error(err))
}
// Wait for webhook informers to sync.
if wh != nil {
wh.InformersHaveSynced()