Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Create a supported way of setting a cache on source.Kind #794

Merged
merged 3 commits into from
Feb 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the first sentence of this godoc is basically for ppl who know how its implemented and not explaining the purpose which is far more important. It would be nice to just say sth like NewKindWithCache is used to create a Wach for a different cluster, then go on with the implementation details like "this is achieved by intentionally not implementing InjectCache" etc. Would be great if someone could create a followup for that.

/lgtm

// 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