Using Predicates for Event Filtering with Operator SDK
A Predicate implements the following methods that take an event of a particular type and return true if the event should be processed by Reconcile()
:
All event types contain Kubernetes metadata about the object that triggered the event, and the object itself. Predicate logic uses these data to make decisions about what should be filtered. Some event types include other fields pertaining to the semantics of that event. For example, event.UpdateEvent
includes both old and new metadata and objects:
Any number of Predicates can be set for a controller via the builder method WithEventFilter()
, which will filter an event if any of those Predicates evaluates to false
. This first example is an implementation of a controller that simply filters Delete events on Pods that have been confirmed deleted; the controller receives all Delete events that occur, and we may only care about resources that have not been completely deleted: