mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
fix: ttl manager stop informer on error (#7966)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
e9c8a3da0a
commit
549f290002
1 changed files with 16 additions and 18 deletions
|
@ -127,35 +127,33 @@ func (m *manager) start(ctx context.Context, gvr schema.GroupVersionResource, wo
|
|||
indexers,
|
||||
options,
|
||||
)
|
||||
controller, err := newController(m.metadataClient.Resource(gvr), informer, logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cont, cancel := context.WithCancel(ctx)
|
||||
var wg wait.Group
|
||||
|
||||
stopFunc := func() {
|
||||
// Send stop signal to informer's goroutine
|
||||
cancel()
|
||||
// Wait for the group to terminate
|
||||
wg.Wait()
|
||||
controller.Stop()
|
||||
}
|
||||
|
||||
wg.StartWithContext(cont, func(ctx context.Context) {
|
||||
logger.Info("informer starting...")
|
||||
informer.Informer().Run(cont.Done())
|
||||
})
|
||||
|
||||
if !cache.WaitForCacheSync(ctx.Done(), informer.Informer().HasSynced) {
|
||||
stopInformer := func() {
|
||||
// Send stop signal to informer's goroutine
|
||||
cancel()
|
||||
// Wait for the group to terminate
|
||||
wg.Wait()
|
||||
}
|
||||
if !cache.WaitForCacheSync(ctx.Done(), informer.Informer().HasSynced) {
|
||||
stopInformer()
|
||||
return fmt.Errorf("failed to wait for cache sync: %s", gvr.Resource)
|
||||
}
|
||||
|
||||
controller, err := newController(m.metadataClient.Resource(gvr), informer, logger)
|
||||
if err != nil {
|
||||
stopInformer()
|
||||
return err
|
||||
}
|
||||
logger.Info("controller starting...")
|
||||
controller.Start(cont, workers)
|
||||
m.resController[gvr] = stopFunc // Store the stop function
|
||||
m.resController[gvr] = func() {
|
||||
stopInformer()
|
||||
controller.Stop()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue