Skip to content

Commit cbaa31a

Browse files
achawkic0d1ngm0nk3y
authored andcommitted
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 <ralf.pannemans@sap.com>
1 parent 82a78f9 commit cbaa31a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/source/source.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ type Source interface {
5555
Start(handler.EventHandler, workqueue.RateLimitingInterface, ...predicate.Predicate) error
5656
}
5757

58+
// CreateSourceWithFixedCache creates a Source without InjectCache, so that it is assured that the given cache is used
59+
// and not overwritten
60+
func CreateSourceWithFixedCache(object runtime.Object, cache cache.Cache) Source {
61+
return &sourceWithFixedCache{kind: Kind{Type: object, cache: cache}}
62+
}
63+
64+
type sourceWithFixedCache struct {
65+
kind Kind
66+
}
67+
68+
func (ks *sourceWithFixedCache) Start(handler handler.EventHandler, queue workqueue.RateLimitingInterface,
69+
prct ...predicate.Predicate) error {
70+
return ks.kind.Start(handler, queue, prct...)
71+
}
72+
5873
// Kind is used to provide a source of events originating inside the cluster from Watches (e.g. Pod Create)
5974
type Kind struct {
6075
// Type is the type of object to watch. e.g. &v1.Pod{}

0 commit comments

Comments
 (0)