pub trait Context {
type Resource: Resource + Send + Sync + 'static;
type Error: Error;
const FINALIZER_NAME: Option<&'static str> = None;
// Required method
fn apply<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
client: Client,
resource: &'life1 Self::Resource,
metadata: &'life2 mut TraceMetadata,
) -> Pin<Box<dyn Future<Output = Result<Option<Action>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided methods
fn cleanup<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
client: Client,
resource: &'life1 Self::Resource,
metadata: &'life2 mut TraceMetadata,
) -> Pin<Box<dyn Future<Output = Result<Option<Action>, Self::Error>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn success_action(&self, resource: &Self::Resource) -> Action { ... }
fn error_action(
self: Arc<Self>,
resource: Arc<Self::Resource>,
err: &Error<Self::Error>,
consecutive_errors: u32,
) -> Action { ... }
fn failure_event(
&self,
resource: &Self::Resource,
phase: Phase,
err: &Error<Self::Error>,
) -> Option<Event> { ... }
}Expand description
The Context trait should be implemented in order to provide callbacks
for events that happen to resources watched by a Controller.
Provided Associated Constants§
Sourceconst FINALIZER_NAME: Option<&'static str> = None
const FINALIZER_NAME: Option<&'static str> = None
The name to use for the finalizer. This must be unique across controllers - if multiple controllers with the same finalizer name run against the same resource, unexpected behavior can occur.
If this is None (the default), a finalizer will not be used, and cleanup events will not be reported.
Required Associated Types§
Required Methods§
Sourcefn apply<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
client: Client,
resource: &'life1 Self::Resource,
metadata: &'life2 mut TraceMetadata,
) -> Pin<Box<dyn Future<Output = Result<Option<Action>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn apply<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
client: Client,
resource: &'life1 Self::Resource,
metadata: &'life2 mut TraceMetadata,
) -> Pin<Box<dyn Future<Output = Result<Option<Action>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
This method is called when a watched resource is created or updated.
The Client used by the controller is passed in to allow making
additional API requests, as is the resource which triggered this
event. If this method returns Some(action), the given action will
be performed, otherwise if None is returned,
success_action will be called to find the
action to perform.
metadata is state for this reconciliation pass, which can be used
to annotate its tracing span, time steps of
the work for metrics, and publish events
about the resource.
What this returns determines the Outcome reported to the
controller’s observer, as described in
Outcome::of_result.
Provided Methods§
Sourcefn cleanup<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
client: Client,
resource: &'life1 Self::Resource,
metadata: &'life2 mut TraceMetadata,
) -> Pin<Box<dyn Future<Output = Result<Option<Action>, Self::Error>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn cleanup<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
client: Client,
resource: &'life1 Self::Resource,
metadata: &'life2 mut TraceMetadata,
) -> Pin<Box<dyn Future<Output = Result<Option<Action>, Self::Error>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
This method is called when a watched resource is marked for deletion.
The Client used by the controller is passed in to allow making
additional API requests, as is the resource which triggered this
event. If this method returns Some(action), the given action will
be performed, otherwise if None is returned,
success_action will be called to find the
action to perform.
metadata and the return value are treated as for
apply.
Note that this method will only be called if a finalizer is used.
Sourcefn success_action(&self, resource: &Self::Resource) -> Action
fn success_action(&self, resource: &Self::Resource) -> Action
Sourcefn error_action(
self: Arc<Self>,
resource: Arc<Self::Resource>,
err: &Error<Self::Error>,
consecutive_errors: u32,
) -> Action
fn error_action( self: Arc<Self>, resource: Arc<Self::Resource>, err: &Error<Self::Error>, consecutive_errors: u32, ) -> Action
This method is called when a call to apply or
cleanup returns Err. It should return the
default Action to perform. The error returned will be passed in
here, as well as a count of how many consecutive errors have happened
for this resource, to allow for an exponential backoff strategy. The
default implementation uses exponential backoff with a max of 256
seconds and some added randomization to avoid thundering herds.
Sourcefn failure_event(
&self,
resource: &Self::Resource,
phase: Phase,
err: &Error<Self::Error>,
) -> Option<Event>
fn failure_event( &self, resource: &Self::Resource, phase: Phase, err: &Error<Self::Error>, ) -> Option<Event>
This method is called when a reconciliation pass fails, if the
controller has an event recorder,
to determine the Kubernetes event to publish on the resource. Return
None to publish nothing, for instance for errors that are an
expected part of waiting on something else.
The default implementation publishes a Warning event with reason
ReconcileFailed (or CleanupFailed, if the resource is being
deleted), and the error and its causes as the note. Repeats of an
identical event are aggregated, as described in the
events module; this means that errors which
include something that varies from one attempt to the next (such as a
timestamp or request ID) create a new event per attempt, so should be
rephrased here.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".