Skip to content

Commit

Permalink
Merge pull request #794 from akhinos/issue-650
Browse files Browse the repository at this point in the history
✨ Create a supported way of setting a cache on source.Kind
  • Loading branch information
k8s-ci-robot committed Feb 17, 2020
2 parents 0fcf28e + f515d1e commit 37a5c61
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ type Source interface {
Start(handler.EventHandler, workqueue.RateLimitingInterface, ...predicate.Predicate) error
}

// 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 NewKindWithCache(object runtime.Object, cache cache.Cache) Source {
return &kindWithCache{kind: Kind{Type: object, cache: cache}}
}

type kindWithCache struct {
kind Kind
}

func (ks *kindWithCache) 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{}
Expand Down

0 comments on commit 37a5c61

Please sign in to comment.