Skip to main content

ProvideApi

Trait ProvideApi 

Source
pub trait ProvideApi<R>{
    // Required method
    fn get(&self, namespace: &str) -> Result<Arc<Api<R>>>;
}
Expand description

Abstraction for obtaining kube::Api instances, allowing different caching strategies.

This trait decouples the crate::Finalize trait from the specific caching implementation, enabling you to choose the optimal strategy for your operator without changing your reconciliation logic.

§Implementations

§Example

use kuberator::cache::{ProvideApi, StaticApiProvider, CachedApiProvider, CachingStrategy};
use kuberator::Finalize;
use k8s_openapi::api::core::v1::ConfigMap;

// Your repository can be generic over any ProvideApi implementation
struct MyK8sRepo<P: ProvideApi<ConfigMap> + Send + Sync> {
    api_provider: P,
}

impl<P: ProvideApi<ConfigMap> + Send + Sync> Finalize<ConfigMap, P> for MyK8sRepo<P> {
    fn api_provider(&self) -> &P {
        &self.api_provider
    }
}

// This trait can be instantiated with different providers and strategies
// See their respective documentation for usage examples

Required Methods§

Source

fn get(&self, namespace: &str) -> Result<Arc<Api<R>>>

Gets an Arc<Api> instance for the given namespace.

Returns an error if the namespace is not available. The exact behavior depends on the implementation:

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§