Struct kubert::runtime::Runtime

source ·
pub struct Runtime<S = NoServer> { /* private fields */ }
Available on crate feature runtime only.
Expand description

Provides infrastructure for running:

  • a Kubernetes controller including logging
  • a default Kubernetes client
  • signal handling and graceful shutdown
  • an admin server with readiness and liveness probe endpoints

The runtime facilitates creating watches (with and without caches) that include error handling and graceful shutdown.

Implementations§

source§

impl<S> Runtime<S>

source

pub fn client(&self) -> Client

Obtains the runtime’s default Kubernetes client.

source

pub fn initialized_handle(&mut self) -> Handle

Creates a new initization handle used to block readiness

source

pub fn readiness(&self) -> Readiness

Obtains a handle to he admin server’s readiness state

source

pub fn shutdown_handle(&self) -> Watch

Obtains a handle that can be used to instrument graceful shutdown

source

pub fn cancel_on_shutdown<T>(&self, inner: T) -> CancelOnShutdown<T>

Wraps the given Future or Stream so that it completes when the runtime is shutdown

source

pub fn requeue<T>( &self, capacity: usize ) -> (Sender<T>, CancelOnShutdown<Receiver<T>>)
where T: Eq + Hash,

Available on features="runtime" and crate feature requeue only.

Wraps the given Future or Stream so that it completes when the runtime is shutdown

source

pub fn watch<T>( &mut self, api: Api<T>, watcher_config: Config ) -> impl Stream<Item = Event<T>>
where T: Resource + DeserializeOwned + Clone + Debug + Send + 'static, T::DynamicType: Default,

Creates a watch with the given Api

If the underlying stream encounters errors, the request is retried (potentially after a delay).

The runtime is not considered initialized until the returned stream returns at least one event.

The return stream terminates when the runtime receives a shutdown signal.

source

pub fn watch_all<T>( &mut self, watcher_config: Config ) -> impl Stream<Item = Event<T>>
where T: Resource + DeserializeOwned + Clone + Debug + Send + 'static, T::DynamicType: Default,

Creates a cluster-level watch on the default Kubernetes client

See Runtime::watch for more details.

source

pub fn watch_namespaced<T>( &mut self, ns: impl AsRef<str>, watcher_config: Config ) -> impl Stream<Item = Event<T>>

Creates a namespace-level watch on the default Kubernetes client

See Runtime::watch for more details.

source

pub fn cache<T>( &mut self, api: Api<T>, watcher_config: Config ) -> (Store<T>, impl Stream<Item = Event<T>>)
where T: Resource + DeserializeOwned + Clone + Debug + Send + 'static, T::DynamicType: Clone + Default + Eq + Hash,

Creates a cached watch with the given Api

The returned Store is updated as the returned stream is polled. If the underlying stream encounters errors, the request is retried (potentially after a delay).

The runtime is not considered initialized until the returned stream returns at least one event.

The return stream terminates when the runtime receives a shutdown signal.

source

pub fn cache_all<T>( &mut self, watcher_config: Config ) -> (Store<T>, impl Stream<Item = Event<T>>)
where T: Resource + DeserializeOwned + Clone + Debug + Send + 'static, T::DynamicType: Clone + Default + Eq + Hash,

Creates a cached cluster-level watch on the default Kubernetes client

See Runtime::cache for more details.

source

pub fn cache_namespaced<T>( &mut self, ns: impl AsRef<str>, watcher_config: Config ) -> (Store<T>, impl Stream<Item = Event<T>>)

Creates a cached namespace-level watch on the default Kubernetes client

See Runtime::cache for more details.

source§

impl Runtime<Bound>

source

pub fn server_addr(&self) -> SocketAddr

Returns the bound local address of the server

source

pub fn spawn_server<S, B>(self, service: S) -> Runtime<NoServer>
where S: Service<Request<Body>, Response = Response<B>> + Clone + Send + 'static, S::Error: Error + Send + Sync, S::Future: Send, B: HttpBody + Send + 'static, B::Data: Send, B::Error: Error + Send + Sync,

Spawns the HTTPS server with the given service. A runtime handle without the bound server configuration is returned.

The server shuts down gracefully when the runtime is shutdown.

source§

impl Runtime<Option<Bound>>

source

pub fn server_addr(&self) -> Option<SocketAddr>

Returns the bound local address of the server

source

pub fn spawn_server<S, B, F>(self, mk: F) -> Runtime<NoServer>
where F: FnOnce() -> S, S: Service<Request<Body>, Response = Response<B>> + Clone + Send + 'static, S::Error: Error + Send + Sync, S::Future: Send, B: HttpBody + Send + 'static, B::Data: Send, B::Error: Error + Send + Sync,

Spawns the HTTPS server, if bound, with the given service. A runtime handle without the bound server configuration is returned.

The server shuts down gracefully when the runtime is shutdown.

source§

impl Runtime<NoServer>

source

pub fn builder() -> Builder<NoServer>

Creates a runtime builder

source

pub async fn run(self) -> Result<(), Aborted>

Runs the runtime until it is shutdown

Shutdown starts when a SIGINT or SIGTERM signal is received and completes when all components have terminated gracefully or when a subsequent signal is received.

The admin server’s readiness endpoint returns success only once all watches (and other initalized components) have become ready and then returns an error after shutdown is initiated.

Auto Trait Implementations§

§

impl<S = NoServer> !RefUnwindSafe for Runtime<S>

§

impl<S> Send for Runtime<S>
where S: Send,

§

impl<S> Sync for Runtime<S>
where S: Sync,

§

impl<S> Unpin for Runtime<S>
where S: Unpin,

§

impl<S = NoServer> !UnwindSafe for Runtime<S>

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

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