1
0
Fork 0
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:
Charles-Edouard Brétéché 2023-08-03 19:53:52 +02:00 committed by GitHub
parent e9c8a3da0a
commit 549f290002
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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