Trait roperator::handler::Handler[][src]

pub trait Handler: Send + Sync + 'static {
    fn sync(&self, request: &SyncRequest) -> Result<SyncResponse, Error>;

    fn finalize(&self, request: &SyncRequest) -> Result<FinalizeResponse, Error> { ... }
}

The main trait that’s used to implement your operator. Most operators will only need to implement the sync function.

Required methods

fn sync(&self, request: &SyncRequest) -> Result<SyncResponse, Error>[src]

The main logic of an operator is implemented in this function. This function is passed a &SyncRequest, which provides a snapshot of the state of your parent resource and any children that already exist. The Handler then returns a SyncResponse that contains the desired child resources and the status to be set on the parent. Roperator will ensure that the parent status and any child resources all match the values provided by this response.

This function is allowed to have side effects, such as calling out to external systems and such, but it’s important that any such operations are idempotent. An example would be an operator that calls out to a service to create a database schema for each parent custom resource instance. It is a good idea to generate deterministic identifiers for such things based on some immutable metadata from the parent resource (name, namespace, uid).

If this function returns an Err, then roperator will retry calling this function after applying a backoff delay.

Loading content...

Provided methods

fn finalize(&self, request: &SyncRequest) -> Result<FinalizeResponse, Error>[src]

Finalize is invoked whenever the parent resource starts being deleted. Roperator makes every reasonable attempt to ensure that this function gets invoked at least once for each parent as it’s being deleted. We cannot make any guarantees, though, since it’s possible for Kuberentes resources to be force deleted without waiting for finalizers.

The FinalizeResponse can return a new parent status, as well as an Option<Duration> indicating whether the finalization is complete or needs to be retried. If the retry field is Some, then the finalize function will be invoked again after the given duration. If it is None, then roperator will tell kubernetes to proceed with the deletion.

The default implementation of this function simply allows the deletion to proceed and does not modify the status.

If this function returns an Err, then roperator will retry calling this function after applying a backoff delay.

Loading content...

Implementations on Foreign Types

impl<SyncFn, ErrorFn> Handler for (SyncFn, ErrorFn) where
    SyncFn: Fn(&SyncRequest) -> Result<SyncResponse, Error> + Send + Sync + 'static,
    ErrorFn: Fn(&SyncRequest, Error) -> (Value, Option<Duration>) + Send + Sync + 'static, 
[src]

Loading content...

Implementors

impl<F> Handler for F where
    F: Fn(&SyncRequest) -> Result<SyncResponse, Error> + Send + Sync + 'static, 
[src]

impl<H: FailableHandler> Handler for DefaultFailableHandler<H>[src]

Loading content...