pub struct Runtime<S = NoServer> { /* private fields */ }
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>
impl<S> Runtime<S>
sourcepub fn initialized_handle(&mut self) -> Handle
pub fn initialized_handle(&mut self) -> Handle
Creates a new initization handle used to block readiness
sourcepub fn shutdown_handle(&self) -> Watch
pub fn shutdown_handle(&self) -> Watch
Obtains a handle that can be used to instrument graceful shutdown
sourcepub fn cancel_on_shutdown<T>(&self, inner: T) -> CancelOnShutdown<T> ⓘ
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
sourcepub fn requeue<T>(
&self,
capacity: usize
) -> (Sender<T>, CancelOnShutdown<Receiver<T>>)
Available on features="runtime"
and crate feature requeue
only.
pub fn requeue<T>( &self, capacity: usize ) -> (Sender<T>, CancelOnShutdown<Receiver<T>>)
features="runtime"
and crate feature requeue
only.Wraps the given Future
or Stream
so that it completes when the runtime is shutdown
sourcepub fn watch<T>(
&mut self,
api: Api<T>,
watcher_config: Config
) -> impl Stream<Item = Event<T>>
pub fn watch<T>( &mut self, api: Api<T>, watcher_config: Config ) -> impl Stream<Item = Event<T>>
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.
sourcepub fn watch_all<T>(
&mut self,
watcher_config: Config
) -> impl Stream<Item = Event<T>>
pub fn watch_all<T>( &mut self, watcher_config: Config ) -> impl Stream<Item = Event<T>>
Creates a cluster-level watch on the default Kubernetes client
See Runtime::watch
for more details.
sourcepub fn watch_namespaced<T>(
&mut self,
ns: impl AsRef<str>,
watcher_config: Config
) -> impl Stream<Item = Event<T>>where
T: Resource<Scope = NamespaceResourceScope> + DeserializeOwned + Clone + Debug + Send + 'static,
T::DynamicType: Default,
pub fn watch_namespaced<T>(
&mut self,
ns: impl AsRef<str>,
watcher_config: Config
) -> impl Stream<Item = Event<T>>where
T: Resource<Scope = NamespaceResourceScope> + DeserializeOwned + Clone + Debug + Send + 'static,
T::DynamicType: Default,
Creates a namespace-level watch on the default Kubernetes client
See Runtime::watch
for more details.
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub fn cache_namespaced<T>(
&mut self,
ns: impl AsRef<str>,
watcher_config: Config
) -> (Store<T>, impl Stream<Item = Event<T>>)where
T: Resource<Scope = NamespaceResourceScope> + DeserializeOwned + Clone + Debug + Send + 'static,
T::DynamicType: Clone + Default + Eq + Hash,
pub fn cache_namespaced<T>(
&mut self,
ns: impl AsRef<str>,
watcher_config: Config
) -> (Store<T>, impl Stream<Item = Event<T>>)where
T: Resource<Scope = NamespaceResourceScope> + DeserializeOwned + Clone + Debug + Send + 'static,
T::DynamicType: Clone + Default + Eq + Hash,
Creates a cached namespace-level watch on the default Kubernetes client
See Runtime::cache
for more details.
source§impl Runtime<Bound>
impl Runtime<Bound>
sourcepub fn server_addr(&self) -> SocketAddr
pub fn server_addr(&self) -> SocketAddr
Returns the bound local address of the server
sourcepub fn spawn_server<S, B>(self, service: S) -> Runtime<NoServer>
pub fn spawn_server<S, B>(self, service: S) -> Runtime<NoServer>
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>>
impl Runtime<Option<Bound>>
sourcepub fn server_addr(&self) -> Option<SocketAddr>
pub fn server_addr(&self) -> Option<SocketAddr>
Returns the bound local address of the server
sourcepub fn spawn_server<S, B, F>(self, mk: F) -> Runtime<NoServer>
pub fn spawn_server<S, B, F>(self, mk: F) -> Runtime<NoServer>
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>
impl Runtime<NoServer>
sourcepub async fn run(self) -> Result<(), Aborted>
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.