From f7d305699c2a597399c2599825408dbdd3a673a3 Mon Sep 17 00:00:00 2001 From: Amin Chawki Date: Mon, 3 Feb 2020 12:55:39 +0100 Subject: [PATCH] Create wrapper to explictly set cache - sourceWithFixedCache does not implement InjectCache - it does not rely on the current implicit implementation that a cache is not overwriting in case it was injected before - see #650 Co-authored-by: Ralf Pannemans --- pkg/source/source.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/source/source.go b/pkg/source/source.go index c777a8c719..cbec357c14 100644 --- a/pkg/source/source.go +++ b/pkg/source/source.go @@ -55,6 +55,21 @@ type Source interface { Start(handler.EventHandler, workqueue.RateLimitingInterface, ...predicate.Predicate) error } +// CreateSourceWithFixedCache creates a Source without InjectCache, so that it is assured that the given cache is used +// and not overwritten +func CreateSourceWithFixedCache(object runtime.Object, cache cache.Cache) Source { + return &sourceWithFixedCache{kind: Kind{Type: object, cache: cache}} +} + +type sourceWithFixedCache struct { + kind Kind +} + +func (ks *sourceWithFixedCache) Start(handler handler.EventHandler, queue workqueue.RateLimitingInterface, + prct ...predicate.Predicate) error { + return ks.kind.Start(handler, queue, prct...) +} + // Kind is used to provide a source of events originating inside the cluster from Watches (e.g. Pod Create) type Kind struct { // Type is the type of object to watch. e.g. &v1.Pod{}