k8s_controller

Trait Context

Source
pub trait Context {
    type Resource: Resource;
    type Error: Error;

    const FINALIZER_NAME: &'static str;

    // Required methods
    fn apply<'life0, 'life1, 'async_trait>(
        &'life0 self,
        client: Client,
        resource: &'life1 Self::Resource,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Action>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn cleanup<'life0, 'life1, 'async_trait>(
        &'life0 self,
        client: Client,
        resource: &'life1 Self::Resource,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Action>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    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 { ... }
}
Expand description

The Context trait should be implemented in order to provide callbacks for events that happen to resources watched by a Controller.

Required Associated Constants§

Source

const FINALIZER_NAME: &'static str

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.

Required Associated Types§

Source

type Resource: Resource

The type of Kubernetes resource that will be watched by the Controller this context is passed to

Source

type Error: Error

The error type which will be returned by the apply and cleanup methods

Required Methods§

Source

fn apply<'life0, 'life1, 'async_trait>( &'life0 self, client: Client, resource: &'life1 Self::Resource, ) -> Pin<Box<dyn Future<Output = Result<Option<Action>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: '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.

Source

fn cleanup<'life0, 'life1, 'async_trait>( &'life0 self, client: Client, resource: &'life1 Self::Resource, ) -> Pin<Box<dyn Future<Output = Result<Option<Action>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: '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.

Provided Methods§

Source

fn success_action(&self, resource: &Self::Resource) -> Action

This method is called when a call to apply or cleanup returns Ok(None). It should return the default Action to perform. The default implementation will requeue the event at a random time between 40 and 60 minutes in the future.

Source

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§