From cbaa31aced173092707ca9920f3c9282e72c461f Mon Sep 17 00:00:00 2001 From: Amin Chawki Date: Mon, 3 Feb 2020 12:55:39 +0100 Subject: [PATCH 1/3] 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{} From befff0bc2583966e0f37cadae1b1a89fe5d3d877 Mon Sep 17 00:00:00 2001 From: Jakob Schmid Date: Mon, 10 Feb 2020 13:05:55 +0100 Subject: [PATCH 2/3] Rename CreateSourceWithFixedCache to NewKindWithFixedCache Co-authored-by: Ulrich Kramer --- pkg/source/source.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/source/source.go b/pkg/source/source.go index cbec357c14..b84b425cf9 100644 --- a/pkg/source/source.go +++ b/pkg/source/source.go @@ -55,17 +55,18 @@ 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}} +// NewKindWithFixedCache creates a Source without InjectCache, so that it is assured that the given cache is used +// and not overwritten. It can be used to watch objects in a different cluster by passing the cache +// from that other cluster +func NewKindWithFixedCache(object runtime.Object, cache cache.Cache) Source { + return &kindWithFixedCache{kind: Kind{Type: object, cache: cache}} } -type sourceWithFixedCache struct { +type kindWithFixedCache struct { kind Kind } -func (ks *sourceWithFixedCache) Start(handler handler.EventHandler, queue workqueue.RateLimitingInterface, +func (ks *kindWithFixedCache) Start(handler handler.EventHandler, queue workqueue.RateLimitingInterface, prct ...predicate.Predicate) error { return ks.kind.Start(handler, queue, prct...) } From f515d1e05bc071898beba7fd5da7a9ea10cf6263 Mon Sep 17 00:00:00 2001 From: Ulrich Kramer Date: Tue, 11 Feb 2020 17:15:36 +0100 Subject: [PATCH 3/3] Change NewKindWithFixedCache to NewKindWithCache --- pkg/source/source.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/source/source.go b/pkg/source/source.go index b84b425cf9..7251cea770 100644 --- a/pkg/source/source.go +++ b/pkg/source/source.go @@ -55,18 +55,18 @@ type Source interface { Start(handler.EventHandler, workqueue.RateLimitingInterface, ...predicate.Predicate) error } -// NewKindWithFixedCache creates a Source without InjectCache, so that it is assured that the given cache is used +// NewKindWithCache creates a Source without InjectCache, so that it is assured that the given cache is used // and not overwritten. It can be used to watch objects in a different cluster by passing the cache // from that other cluster -func NewKindWithFixedCache(object runtime.Object, cache cache.Cache) Source { - return &kindWithFixedCache{kind: Kind{Type: object, cache: cache}} +func NewKindWithCache(object runtime.Object, cache cache.Cache) Source { + return &kindWithCache{kind: Kind{Type: object, cache: cache}} } -type kindWithFixedCache struct { +type kindWithCache struct { kind Kind } -func (ks *kindWithFixedCache) Start(handler handler.EventHandler, queue workqueue.RateLimitingInterface, +func (ks *kindWithCache) Start(handler handler.EventHandler, queue workqueue.RateLimitingInterface, prct ...predicate.Predicate) error { return ks.kind.Start(handler, queue, prct...) }