Skip to content

Commit

Permalink
Create wrapper to explictly set cache
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
achawki and c0d1ngm0nk3y committed Feb 3, 2020
1 parent 066ff64 commit f7d3056
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit f7d3056

Please sign in to comment.