* Use consistent case for "Deprecated" comments
Not the most important thing ever, but the canonical string to use for
Deprecated warnings is case sensitive, and also it's nice to be
consistent.
* Add nolint comment
* Add GetObservers to tracker interface
This allows an arbitrary client to fetch all the observers of a given object. Ultimately, this enables an informer setup that can use this knowledge as a filter to decide whether or not the current object is actually watched by anything.
* Fix log line
* Add support for Selector in tracker.Reference.
`tracker.Reference` may now optionally replace `Name` with `Selector` to track zero or multiple resources of a particular `apiVersion`, `kind` and `namespace`.
Fixes: https://github.com/knative/pkg/issues/859
* Address code review comments
`TrackReference` is the same as `Track`, but takes a `tracker.Reference` instead. This type has been seeded with the subset of `corev1.ObjectReference` that the tracker currently consumes / supports, but the intention is to expand this type to allow inexact references that (optionally) use label selectors in place of name to reference objects.
See also: https://github.com/knative/pkg/issues/859
To use this with a typical informer, e.g. the way `Route` would monitor `Configurations` and `Revisions`, you'd do something like:
```go
c := &Reconciler{
Base: reconciler.NewBase(opt, controllerAgentName),
...
}
impl := controller.NewImpl(c, c.Logger, "Routes")
t := New(impl.EnqueueKey, 30*time.Minute)
configInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: t.OnChanged,
UpdateFunc: controller.PassNew(t.OnChanged),
})
revisionInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: t.OnChanged,
UpdateFunc: controller.PassNew(t.OnChanged),
})
// Now use c.tracker.Track(revisionRef, route) or c.tracker.Track(configRef, route)
// each Reconcile(route) to refresh the cross-object leases.
c.tracker = t
```
To use this with a `duck.InformerFactory`, e.g. the way `Revision` will monitor `BuildRef`s you'd do something like:
```go
c := &Reconciler{
Base: reconciler.NewBase(opt, controllerAgentName),
...
}
impl := controller.NewImpl(c, c.Logger, "Revisions")
t := New(impl.EnqueueKey, 30*time.Minute)
cif := &duck.CachedInformerFactory{
Delegate: &duck.EnqueueInformerFactory{
Delegate: buildInformerFactory,
EventHandler: cache.ResourceEventHandlerFuncs{
AddFunc: t.OnChanged,
UpdateFunc: controller.PassNew(t.OnChanged),
},
},
}
// Now use: `c.buildInformerFactory.Get()` to access ObjectReferences.
c.buildInformerFactory = buildInformerFactory
// Now use: `c.tracker.Track(rev.Spec.BuildRef, rev)` to queue `rev`
// each time `rev.Spec.BuildRef` changes (expires 30 minutes after BuildRef
// points to something else).
c.tracker = t
```
Fixes: https://github.com/knative/pkg/issues/94