1
0
Fork 0
mirror of https://github.com/imjasonh/client-go2 synced 2026-07-08 09:05:38 +00:00

make event handler configuration the caller's responsibility, maybe they want to enqueue the event

This commit is contained in:
Jason Hall 2021-12-15 12:17:04 -05:00
parent 8736289eac
commit fbf85d4793
2 changed files with 17 additions and 16 deletions

View file

@ -92,22 +92,9 @@ func (c client[T]) Create(ctx context.Context, namespace string, t T) error {
return err
}
func (c client[T]) Inform(ctx context.Context) {
func (c client[T]) Inform(ctx context.Context, handler cache.ResourceEventHandler) {
inf := c.dsif.ForResource(c.gvr).Informer()
inf.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
key, _ := cache.MetaNamespaceKeyFunc(obj)
log.Println("--> ADD", key)
},
UpdateFunc: func(_, obj interface{}) {
key, _ := cache.MetaNamespaceKeyFunc(obj)
log.Println("--> UPDATE", key)
},
DeleteFunc: func(obj interface{}) {
key, _ := cache.MetaNamespaceKeyFunc(obj)
log.Println("--> DELETE", key)
},
})
inf.AddEventHandler(handler)
go inf.Run(ctx.Done())
if !cache.WaitForNamedCacheSync(c.gvr.String(), ctx.Done(), inf.HasSynced) {
log.Println("Failed to wait for caches to sync:"< c.gvr.String())