Skip to content

Commit 37a5c61

Browse files
authored
Merge pull request #794 from akhinos/issue-650
✨ Create a supported way of setting a cache on source.Kind
2 parents 0fcf28e + f515d1e commit 37a5c61

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pkg/source/source.go

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

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

0 commit comments

Comments
 (0)