kube_client

Struct Client

Source
pub struct Client { /* private fields */ }
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§

Source§

impl Client

Constructors and low-level api interfaces.

Most users only need Client::try_default or Client::new from this block.

The many various lower level interfaces here are for more advanced use-cases with specific requirements.

Source

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;
use hyper_util::rt::TokioExecutor;

let config = Config::infer().await?;
let service = ServiceBuilder::new()
    .layer(config.base_uri_layer())
    .option_layer(config.auth_layer()?)
    .service(hyper_util::client::legacy::Client::builder(TokioExecutor::new()).build_http());
let client = Client::new(service, config.default_namespace);
Source

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 kubeconfig first, and then if that fails, trying the in-cluster environment variables.

Will fail if neither configuration could be loaded.

let client = Client::try_default().await?;

If you already have a Config then use Client::try_from instead.

Source

pub fn default_namespace(&self) -> &str

Get the default namespace for the client

The namespace is either configured on context in the kubeconfig, falls back to default when running locally, or uses the service account’s namespace when deployed in-cluster.

Source

pub async fn send(&self, request: Request<Body>) -> Result<Response<Body>>

Perform a raw HTTP request against the API and return the raw response back. This method can be used to get raw access to the API which may be used to, for example, create a proxy server or application-level gateway between localhost and the API server.

Source

pub async fn connect( &self, request: Request<Vec<u8>>, ) -> Result<WebSocketStream<TokioIo<Upgraded>>>

Make WebSocket connection.

Source

pub async fn request<T>(&self, request: Request<Vec<u8>>) -> Result<T>

Perform a raw HTTP request against the API and deserialize the response as JSON to some known type.

Source

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

Source

pub async fn request_stream( &self, request: Request<Vec<u8>>, ) -> Result<impl AsyncBufRead>

Perform a raw HTTP request against the API and stream the response body.

The response can be processed using AsyncReadExt and AsyncBufReadExt.

Source

pub async fn request_status<T>( &self, request: Request<Vec<u8>>, ) -> Result<Either<T, Status>>

Perform a raw HTTP request against the API and get back either an object deserialized as JSON or a Status Object.

Source

pub async fn request_events<T>( &self, request: Request<Vec<u8>>, ) -> Result<impl TryStream<Item = Result<WatchEvent<T>>>>

Perform a raw request and get back a stream of WatchEvent objects

Source§

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.

Source

pub async fn apiserver_version(&self) -> Result<Info>

Returns apiserver version.

Source

pub async fn list_api_groups(&self) -> Result<APIGroupList>

Lists api groups that apiserver serves.

Source

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);
}
Source

pub async fn list_core_api_versions(&self) -> Result<APIVersions>

Lists versions of core a.k.a. "" legacy API group.

Source

pub async fn list_core_api_resources( &self, version: &str, ) -> Result<APIResourceList>

Lists resources served in particular core group version.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K> From<Api<K>> for Client

Source§

fn from(api: Api<K>) -> Self

Converts to this type from the input type.
Source§

impl TryFrom<Config> for Client

Source§

fn try_from(config: Config) -> Result<Self>

Builds a default Client from a Config.

See ClientBuilder or Client::new if more customization is required

Source§

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

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