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

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>

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.

If this function returns an Error, then neither the status or any child resources will be updated!

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).

Loading content...

Provided methods

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

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 a boolean indicating whether the finalization is complete. If the boolean is true, then Roperator will remove itself from the list of parent finalizers, allowing kubernetes to proceed with the deletion. If the boolean is false, then Roperator will re-try finalizing again after a backoff period.

The default implementation of this function simply returns true and does not modify the status.

Loading content...

Implementors

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

Loading content...