pub trait ProvideApi<R>where
R: Resource<Scope = NamespaceResourceScope> + Clone + DeserializeOwned + Debug + Send + Sync + 'static,
R::DynamicType: Default,{
// 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
StaticApiProvider- Flexible provider supporting Strict, Adhoc, and Extendable caching strategiesCachedApiProvider- RwLock-based, lazy-loading cache (flexible, for dynamic namespaces)
§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 examplesRequired Methods§
Sourcefn get(&self, namespace: &str) -> Result<Arc<Api<R>>>
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:
StaticApiProviderwith Strict: Errors if not pre-cachedStaticApiProviderwith Adhoc: Creates on-the-fly if not cachedStaticApiProviderwith Extendable: Creates and caches if not cachedCachedApiProvider: Creates and caches on first access
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".