Struct kube_client::Client
source · [−]pub struct Client { /* private fields */ }
client
only.Expand description
Client for connecting with a Kubernetes cluster.
The easiest way to instantiate the client is either by
inferring the configuration from the environment using
Client::try_default
or with an existing Config
using Client::try_from
.
Implementations
sourceimpl Client
impl Client
sourcepub fn new<S, B, T>(service: S, default_namespace: T) -> Self where
S: Service<Request<Body>, Response = Response<B>> + Send + 'static,
S::Future: Send + 'static,
S::Error: Into<BoxError>,
B: Body<Data = Bytes> + Send + 'static,
B::Error: Into<BoxError>,
T: Into<String>,
pub fn new<S, B, T>(service: S, default_namespace: T) -> Self where
S: Service<Request<Body>, Response = Response<B>> + Send + 'static,
S::Future: Send + 'static,
S::Error: Into<BoxError>,
B: Body<Data = Bytes> + Send + 'static,
B::Error: Into<BoxError>,
T: Into<String>,
Create a Client
using a custom Service
stack.
ConfigExt
provides extensions for
building a custom stack.
To create with the default stack with a Config
, use
Client::try_from
.
To create with the default stack with an inferred Config
, use
Client::try_default
.
Example
use kube::{client::ConfigExt, Client, Config};
use tower::ServiceBuilder;
let config = Config::infer().await?;
let service = ServiceBuilder::new()
.layer(config.base_uri_layer())
.option_layer(config.auth_layer()?)
.service(hyper::Client::new());
let client = Client::new(service, config.default_namespace);
sourcepub async fn try_default() -> Result<Self>
pub async fn try_default() -> Result<Self>
Create and initialize a Client
using the inferred configuration.
Will use Config::infer
which attempts to load the local kubec-config first,
and then if that fails, trying the in-cluster environment variables.
Will fail if neither configuration could be loaded.
If you already have a Config
then use Client::try_from
instead.
sourcepub async fn connect(
&self,
request: Request<Vec<u8>>
) -> Result<WebSocketStream<Upgraded>>
Available on crate feature ws
only.
pub async fn connect(
&self,
request: Request<Vec<u8>>
) -> Result<WebSocketStream<Upgraded>>
ws
only.Make WebSocket connection.
sourcepub async fn request<T>(&self, request: Request<Vec<u8>>) -> Result<T> where
T: DeserializeOwned,
pub async fn request<T>(&self, request: Request<Vec<u8>>) -> Result<T> where
T: DeserializeOwned,
Perform a raw HTTP request against the API and deserialize the response as JSON to some known type.
sourcepub async fn request_text(&self, request: Request<Vec<u8>>) -> Result<String>
pub async fn request_text(&self, request: Request<Vec<u8>>) -> Result<String>
Perform a raw HTTP request against the API and get back the response as a string
sourcepub async fn request_text_stream(
&self,
request: Request<Vec<u8>>
) -> Result<impl Stream<Item = Result<Bytes>>>
pub async fn request_text_stream(
&self,
request: Request<Vec<u8>>
) -> Result<impl Stream<Item = Result<Bytes>>>
Perform a raw HTTP request against the API and get back the response as a stream of bytes
sourcepub async fn request_status<T>(
&self,
request: Request<Vec<u8>>
) -> Result<Either<T, Status>> where
T: DeserializeOwned,
pub async fn request_status<T>(
&self,
request: Request<Vec<u8>>
) -> Result<Either<T, Status>> where
T: DeserializeOwned,
Perform a raw HTTP request against the API and get back either an object
deserialized as JSON or a Status
Object.
sourcepub async fn request_events<T>(
&self,
request: Request<Vec<u8>>
) -> Result<impl TryStream<Item = Result<WatchEvent<T>>>> where
T: Clone + DeserializeOwned,
pub async fn request_events<T>(
&self,
request: Request<Vec<u8>>
) -> Result<impl TryStream<Item = Result<WatchEvent<T>>>> where
T: Clone + DeserializeOwned,
Perform a raw request and get back a stream of WatchEvent
objects
sourceimpl Client
impl Client
Low level discovery methods using k8s_openapi
types.
Consider using the discovery
module for
easier-to-use variants of this functionality.
The following methods might be deprecated to avoid confusion between similarly named types within discovery
.
sourcepub async fn apiserver_version(&self) -> Result<Info>
pub async fn apiserver_version(&self) -> Result<Info>
Returns apiserver version.
sourcepub async fn list_api_groups(&self) -> Result<APIGroupList>
pub async fn list_api_groups(&self) -> Result<APIGroupList>
Lists api groups that apiserver serves.
sourcepub async fn list_api_group_resources(
&self,
apiversion: &str
) -> Result<APIResourceList>
pub async fn list_api_group_resources(
&self,
apiversion: &str
) -> Result<APIResourceList>
Lists resources served in given API group.
Example usage:
let apigroups = client.list_api_groups().await?;
for g in apigroups.groups {
let ver = g
.preferred_version
.as_ref()
.or_else(|| g.versions.first())
.expect("preferred or versions exists");
let apis = client.list_api_group_resources(&ver.group_version).await?;
dbg!(apis);
}
sourcepub async fn list_core_api_versions(&self) -> Result<APIVersions>
pub async fn list_core_api_versions(&self) -> Result<APIVersions>
Lists versions of core
a.k.a. ""
legacy API group.
sourcepub async fn list_core_api_resources(
&self,
version: &str
) -> Result<APIResourceList>
pub async fn list_core_api_resources(
&self,
version: &str
) -> Result<APIResourceList>
Lists resources served in particular core
group version.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more