* 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
Stop using `t.Run` to segment things, since they aren't truly independent tests.
Use a longer lease/sleep as I have concerns that slow execution may be a part of the flakiness here.
* Some fixes to the spoof.go and exporter.go
While reviewing some other CL, I saw some avenues for improving
spoof.go, to log the URL that's being fetched, which would help in test
debugging and to use switch construct, rather than nested if's.
While testing the change, I noticed some shifty loggin from the
exporter, so I fixed that as well while I was there.
* Continuation of the previous cleanups.
* Fix the issues with formatting by executing a grep
* and fix compilation error
* lowercase error
* fix the newly changed unit test
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