Skip to main content

StaticApiProvider

Struct StaticApiProvider 

Source
pub struct StaticApiProvider<R>{ /* 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

StrategyCached AccessUncached AccessLocking
Strict~5nsErrorNone
Adhoc~5ns~100nsNone
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>

Source

pub fn new<I, S>( client: Client, namespaces: I, strategy: CachingStrategy, ) -> Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

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>

Source§

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>
where <R as Resource>::DynamicType: Sized,

§

impl<R> Sync for StaticApiProvider<R>
where <R as Resource>::DynamicType: Sized,

§

impl<R> Unpin for StaticApiProvider<R>
where <R as Resource>::DynamicType: Sized,

§

impl<R> !UnwindSafe for StaticApiProvider<R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more