Trait Context

Source
pub trait Context<R, F>: Send + Sync{
    // Required methods
    fn k8s_repository(&self) -> Arc<F>;
    fn finalizer(&self) -> &'static str;
    fn handle_apply<'life0, 'async_trait>(
        &'life0 self,
        object: Arc<R>,
    ) -> Pin<Box<dyn Future<Output = Result<Action>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn handle_cleanup<'life0, 'async_trait>(
        &'life0 self,
        object: Arc<R>,
    ) -> Pin<Box<dyn Future<Output = Result<Action>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn handle_reconciliation<'life0, 'async_trait>(
        &'life0 self,
        object: Arc<R>,
    ) -> Pin<Box<dyn Future<Output = Result<Action>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn handle_error(
        &self,
        object: Arc<R>,
        error: &Error,
        requeue: Option<Duration>,
    ) -> Action { ... }
}
Expand description

The Context trait takes care of the apply and cleanup logic of a resource.

Required Methods§

Source

fn k8s_repository(&self) -> Arc<F>

Returns the k8s repository provided by the struct implementing the Context trait.

Source

fn finalizer(&self) -> &'static str

Returns the resources specific finalizer name provided by the struct implementing the Context trait.

Source

fn handle_apply<'life0, 'async_trait>( &'life0 self, object: Arc<R>, ) -> Pin<Box<dyn Future<Output = Result<Action>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handles the apply logic of a resource.

This method needs to be implemented by the struct implementing the Context trait. It handles all the logic that is needed to apply a resource: creation & updates.

This method needs to be idempotent and tolerate being executed several times (even if previously cancelled).

Source

fn handle_cleanup<'life0, 'async_trait>( &'life0 self, object: Arc<R>, ) -> Pin<Box<dyn Future<Output = Result<Action>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handles the cleanup logic of a resource.

This method needs to be implemented by the struct implementing the Context trait. It handles all the logic that is needed to clean up a resource: the deletion.

This method needs to be idempotent and tolerate being executed several times (even if previously cancelled).

Provided Methods§

Source

fn handle_reconciliation<'life0, 'async_trait>( &'life0 self, object: Arc<R>, ) -> Pin<Box<dyn Future<Output = Result<Action>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handles a successful reconciliation of a resource.

The method is called by the controller in Reconcile::start when a resource is reconciled. The method takes care of the finalizers of the resource as well as the Context::handle_apply and Context::handle_cleanup logic.

Source

fn handle_error( &self, object: Arc<R>, error: &Error, requeue: Option<Duration>, ) -> Action

Handles an error that occurs during reconciliation.

The method is called by the controller in Reconcile::start when an error occurs during reconciliation.

This method is used as a default implementation for the Reconcile::error_policy method that logs the error and requeues the resource or not depending on the requeue parameter.

Feel free to override it in your struct implementing the Context trait to suit your specific needs.

Implementors§