Commit Graph

6 Commits

Author SHA1 Message Date
Julian Friedman 50410e0b83
Use consistent case for "Deprecated" comments (#2216)
* 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
2021-08-17 09:15:16 -07:00
Markus Thömmes cc77cba3ea
Add GetObservers to tracker interface (#1896)
* 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
2020-11-10 10:19:59 -08:00
Markus Thömmes 3a2ec57c2c
Add specific callback for the tracker to delete items eagerly. (#1235)
* Add specific callback for the tracker to delete items eagerly.

* Rename to OnDeletedObserver.

* Enhance FakeTracker and add tests.
2020-04-24 09:17:50 -07:00
Matt Moore 6d806b9983 Add support for Selector in tracker.Reference. (#861)
* 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
2019-11-11 07:05:21 -08:00
Matt Moore a805b647f3 Expand the tracker interface to include a variant with its own type. (#860)
`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
2019-11-10 09:04:12 -08:00
Matt Moore e653ef4b1b This change implements a more generalized form of the BuildTracker. (#95)
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
2018-09-26 17:31:21 -07:00