pub struct StaticApiProvider<R>where
R: Resource<Scope = NamespaceResourceScope> + Clone + DeserializeOwned + Debug + Send + Sync + 'static,
R::DynamicType: Default,{ /* private fields */ }Expand description
A flexible API provider supporting multiple caching strategies.
Depending on the CachingStrategy chosen, this provider can behave as:
- Strict: Lock-free, pre-populated cache (fastest, errors on unknown namespaces)
- Adhoc: Lock-free for cached namespaces, creates Api on-the-fly for others (no caching of misses)
- Extendable: RwLock-based lazy loading (like CachedApiProvider, but can be pre-populated)
§Performance by Strategy
| Strategy | Cached Access | Uncached Access | Locking |
|---|---|---|---|
| Strict | ~5ns | Error | None |
| Adhoc | ~5ns | ~100ns | None |
| Extendable | ~10-15ns | ~100ns (cached) | RwLock |
§Example
ⓘ
use kuberator::cache::{StaticApiProvider, CachingStrategy};
use kube::Client;
use k8s_openapi::api::core::v1::ConfigMap;
// Strict: Only allow pre-defined namespaces
let strict = StaticApiProvider::new(
client.clone(),
vec!["default", "kube-system"],
CachingStrategy::Strict
);
// Adhoc: Pre-cache common namespaces, create others on-the-fly
let adhoc = StaticApiProvider::new(
client.clone(),
vec!["default"], // Common ones cached
CachingStrategy::Adhoc // Others created as needed
);
// Extendable: Start with known namespaces, dynamically cache new ones
let extendable = StaticApiProvider::new(
client.clone(),
vec!["default"],
CachingStrategy::Extendable // New namespaces cached on first access
);Implementations§
Source§impl<R> StaticApiProvider<R>where
R: Resource<Scope = NamespaceResourceScope> + Clone + DeserializeOwned + Debug + Send + Sync + 'static,
R::DynamicType: Default,
impl<R> StaticApiProvider<R>where
R: Resource<Scope = NamespaceResourceScope> + Clone + DeserializeOwned + Debug + Send + Sync + 'static,
R::DynamicType: Default,
Sourcepub fn new<I, S>(
client: Client,
namespaces: I,
strategy: CachingStrategy,
) -> Self
pub fn new<I, S>( client: Client, namespaces: I, strategy: CachingStrategy, ) -> Self
Creates a new StaticApiProvider with the specified caching strategy.
The behavior depends on the chosen CachingStrategy:
- Strict: Only allows access to pre-cached namespaces, errors otherwise
- Adhoc: Pre-caches given namespaces, creates others on-the-fly without caching
- Extendable: Pre-caches given namespaces, creates and caches others on first access
§Example
use kuberator::cache::{StaticApiProvider, CachingStrategy};
use k8s_openapi::api::core::v1::ConfigMap;
// Strict mode - only these namespaces allowed
let strict: StaticApiProvider<ConfigMap> = StaticApiProvider::new(
client.clone(),
vec!["default", "kube-system"],
CachingStrategy::Strict
);
// Adhoc mode - these cached, others created on demand
let adhoc: StaticApiProvider<ConfigMap> = StaticApiProvider::new(
client.clone(),
vec!["default"],
CachingStrategy::Adhoc
);Trait Implementations§
Source§impl<R> ProvideApi<R> for StaticApiProvider<R>where
R: Resource<Scope = NamespaceResourceScope> + Clone + DeserializeOwned + Debug + Send + Sync + 'static,
R::DynamicType: Default,
impl<R> ProvideApi<R> for StaticApiProvider<R>where
R: Resource<Scope = NamespaceResourceScope> + Clone + DeserializeOwned + Debug + Send + Sync + 'static,
R::DynamicType: Default,
Source§fn get(&self, namespace: &str) -> Result<Arc<Api<R>>>
fn get(&self, namespace: &str) -> Result<Arc<Api<R>>>
Gets an Api instance for the given namespace according to the configured CachingStrategy.
§Behavior by Strategy
- Strict: Returns cached Api or error if namespace not pre-cached
- Adhoc: Returns cached Api if available, otherwise creates new Api without caching
- Extendable: Returns cached Api if available, otherwise creates, caches, and returns new Api
§Performance
- Strict/Adhoc (cache hit): ~5ns (lock-free HashMap lookup)
- Adhoc (cache miss): ~100ns (Api creation, not cached)
- Extendable (cache hit): ~10-15ns (RwLock read + HashMap lookup)
- Extendable (cache miss): ~100ns (RwLock write + Api creation, one-time per namespace)
Auto Trait Implementations§
impl<R> !Freeze for StaticApiProvider<R>
impl<R> !RefUnwindSafe for StaticApiProvider<R>
impl<R> Send for StaticApiProvider<R>
impl<R> Sync for StaticApiProvider<R>
impl<R> Unpin for StaticApiProvider<R>
impl<R> !UnwindSafe for StaticApiProvider<R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more