From 88865715a09b0b38318c331f68512bf81d8844f0 Mon Sep 17 00:00:00 2001
From: Philippe Scorsolini
Date: Wed, 31 Jan 2024 15:05:57 +0000
Subject: [PATCH] fix: add RemoveInformer to implement Informers
Co-authored-by: Maximilian Blatt
Signed-off-by: Philippe Scorsolini
---
pkg/controller/cache.go | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/pkg/controller/cache.go b/pkg/controller/cache.go
index 1712d9ed8..fa65bf54e 100644
--- a/pkg/controller/cache.go
+++ b/pkg/controller/cache.go
@@ -142,6 +142,24 @@ func (c *GVKRoutedCache) GetInformerForKind(ctx context.Context, gvk schema.Grou
return c.fallback.GetInformerForKind(ctx, gvk, opts...)
}
+// RemoveInformer removes an informer entry and stops it if it was running.
+func (c *GVKRoutedCache) RemoveInformer(ctx context.Context, obj client.Object) error {
+ gvk, err := apiutil.GVKForObject(obj, c.scheme)
+ if err != nil {
+ return errors.Errorf("failed to get GVK for type %T: %w", obj, err)
+ }
+
+ c.lock.RLock()
+ delegate, ok := c.delegates[gvk]
+ c.lock.RUnlock()
+
+ if ok {
+ return delegate.RemoveInformer(ctx, obj)
+ }
+
+ return c.fallback.RemoveInformer(ctx, obj)
+}
+
// Start for a GVKRoutedCache is a no-op. Start must be called for each delegate.
func (c *GVKRoutedCache) Start(_ context.Context) error {
return nil