Skip to main content

Module predicates

Module predicates 

Source
Expand description

Predicate functions for WatchStreamExt::predicate_filter

These functions just return a hash of commonly compared values, to help decide whether to pass a watch event along or not.

§Choosing a predicate

PredicateUse caseDeletion behavior
[generation]Observe desired-state changes while ignoring status-only updates, for resources supporting generationCan suppress deletion-related updates and deleted objects when generation is unchanged
[resource_version]Observe object revisions, including status-only changesRetains observed deletes whose resource version differs from the cached version
[labels], [annotations], [finalizers]Observe changes to those fieldsCan suppress deletions when the selected fields are unchanged
fallbackUse another predicate when the first has no valueSee Predicate::fallback for the deletion caveat

§Deletion handling

Predicates operate on decoded objects (versus Events). After touched_objects, an object from a delete event is filtered using the same rules as any other object. Deletion does not necessarily change metadata.generation or populate metadata.deletionTimestamp, so predicates based on unchanged fields can suppress that object.

Use [resource_version] when observed deletions should trigger reconciliation, for example to recreate a missing owned resource. The Kubernetes apiserver stamps the delete revision onto the deleted object. This predicate also passes status-only changes, so it does not provide the same filtering as [generation].

No predicate guarantees delivery of every deletion: events can be missed while a watcher is unavailable. Reconcilers should check current desired and actual state, and use a recovery mechanism such as periodic requeues when missed triggers matter. Use finalizers for cleanup that must complete before deletion. The initial deletion marking bumps a positive generation, so a generation-only predicate lets that update through to start cleanup. It can still suppress the final delete event and the update that adds the finalizer, since adding a finalizer leaves generation unchanged. See the finalizer documentation.

Functional rewrite of the controller-runtime/predicate module.

Functions§

annotations
Hash the annotations of a Resource K
finalizers
Hash the finalizers of a Resource K
generation
Hash the generation of a Resource K
labels
Hash the labels of a Resource K
resource_version
Hash the resource version of a Resource K