Skip to content

Commit

Permalink
fix: add RemoveInformer to implement Informers
Browse files Browse the repository at this point in the history
Co-authored-by: Maximilian Blatt <[email protected]>
Signed-off-by: Philippe Scorsolini <[email protected]>
  • Loading branch information
phisco and MisterMX committed Jan 31, 2024
1 parent d05b5c2 commit 8886571
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/controller/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8886571

Please sign in to comment.