kube_client

Struct Config

source
pub struct Config {
    pub cluster_url: Uri,
    pub default_namespace: String,
    pub root_cert: Option<Vec<Vec<u8>>>,
    pub connect_timeout: Option<Duration>,
    pub read_timeout: Option<Duration>,
    pub write_timeout: Option<Duration>,
    pub accept_invalid_certs: bool,
    pub auth_info: AuthInfo,
    pub proxy_url: Option<Uri>,
    pub tls_server_name: Option<String>,
    pub headers: Vec<(HeaderName, HeaderValue)>,
}
Available on crate feature config only.
Expand description

Configuration object for accessing a Kuernetes cluster

The configurable parameters for connecting like cluster URL, default namespace, root certificates, and timeouts. Normally created implicitly through Config::infer or Client::try_default.

§Usage

Construct a Config instance by using one of the many constructors.

Prefer Config::infer unless you have particular issues, and avoid manually managing the data in this struct unless you have particular needs. It exists to be consumed by the Client.

If you are looking to parse the kubeconfig found in a user’s home directory see Kubeconfig.

Fields§

§cluster_url: Uri

The configured cluster url

§default_namespace: String

The configured default namespace

§root_cert: Option<Vec<Vec<u8>>>

The configured root certificate

§connect_timeout: Option<Duration>

Set the timeout for connecting to the Kubernetes API.

A value of None means no timeout

§read_timeout: Option<Duration>

Set the timeout for the Kubernetes API response.

A value of None means no timeout

§write_timeout: Option<Duration>

Set the timeout for the Kubernetes API request.

A value of None means no timeout

§accept_invalid_certs: bool

Whether to accept invalid certificates

§auth_info: AuthInfo

Stores information to tell the cluster who you are.

§proxy_url: Option<Uri>

Optional proxy URL. Proxy support requires the socks5 feature.

§tls_server_name: Option<String>

If set, apiserver certificate will be validated to contain this string

If not set, the cluster_url is used instead

§headers: Vec<(HeaderName, HeaderValue)>

Headers to pass with every request.

Implementations§

source§

impl Config

source

pub fn new(cluster_url: Uri) -> Self

Construct a new config where only the cluster_url is set by the user. and everything else receives a default value.

Most likely you want to use Config::infer to infer the config from the environment.

source

pub async fn infer() -> Result<Self, InferConfigError>

Infer a Kubernetes client configuration.

First, a user’s kubeconfig is loaded from KUBECONFIG or ~/.kube/config. If that fails, an in-cluster config is loaded via Config::incluster. If inference from both sources fails, then an error is returned.

Config::apply_debug_overrides is used to augment the loaded configuration based on the environment.

source

pub fn incluster() -> Result<Self, InClusterError>

Load an in-cluster Kubernetes client configuration using Config::incluster_env.

source

pub fn incluster_env() -> Result<Self, InClusterError>

Load an in-cluster config using the KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT environment variables.

A service account’s token must be available in /var/run/secrets/kubernetes.io/serviceaccount/.

This method matches the behavior of the official Kubernetes client libraries and is the default for both TLS stacks.

source

pub fn incluster_dns() -> Result<Self, InClusterError>

Load an in-cluster config using the API server at https://kubernetes.default.svc.

A service account’s token must be available in /var/run/secrets/kubernetes.io/serviceaccount/.

This behavior does not match that of the official Kubernetes clients, but can be used as a consistent entrypoint in many clusters. See https://github.com/kube-rs/kube/issues/1003 for more info.

source

pub async fn from_kubeconfig( options: &KubeConfigOptions, ) -> Result<Self, KubeconfigError>

Create configuration from the default local config file

This will respect the $KUBECONFIG evar, but otherwise default to ~/.kube/config. You can also customize what context/cluster/user you want to use here, but it will default to the current-context.

source

pub async fn from_custom_kubeconfig( kubeconfig: Kubeconfig, options: &KubeConfigOptions, ) -> Result<Self, KubeconfigError>

Create configuration from a Kubeconfig struct

This bypasses kube’s normal config parsing to obtain custom functionality.

source

pub fn apply_debug_overrides(&mut self)

Override configuration based on environment variables

This is only intended for use as a debugging aid, and the specific variables and their behaviour should not be considered stable across releases.

Currently, the following overrides are supported:

  • KUBE_RS_DEBUG_IMPERSONATE_USER: A Kubernetes user to impersonate, for example: system:serviceaccount:default:foo will impersonate the ServiceAccount foo in the Namespace default
  • KUBE_RS_DEBUG_IMPERSONATE_GROUP: A Kubernetes group to impersonate, multiple groups may be specified by separating them with commas
  • KUBE_RS_DEBUG_OVERRIDE_URL: A Kubernetes cluster URL to use rather than the one specified in the config, useful for proxying traffic through kubectl proxy

Trait Implementations§

source§

impl Clone for Config

source§

fn clone(&self) -> Config

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 ConfigExt for Config

Available on crate feature client only.
source§

fn base_uri_layer(&self) -> BaseUriLayer

Layer to set the base URI of requests to the configured server.
source§

fn auth_layer(&self) -> Result<Option<AuthLayer>>

Optional layer to set up Authorization header depending on the config.
source§

fn extra_headers_layer(&self) -> Result<ExtraHeadersLayer>

Layer to add non-authn HTTP headers depending on the config.
source§

fn rustls_client_config(&self) -> Result<ClientConfig>

Available on crate feature rustls-tls only.
Create rustls::ClientConfig based on config. Read more
source§

fn rustls_https_connector(&self) -> Result<HttpsConnector<HttpConnector>>

Available on crate feature rustls-tls only.
Create hyper_rustls::HttpsConnector based on config. Read more
source§

fn rustls_https_connector_with_connector<H>( &self, connector: H, ) -> Result<HttpsConnector<H>>

Available on crate feature rustls-tls only.
Create hyper_rustls::HttpsConnector based on config and connector. Read more
source§

fn openssl_ssl_connector_builder(&self) -> Result<SslConnectorBuilder>

Available on crate feature openssl-tls only.
source§

fn openssl_https_connector(&self) -> Result<HttpsConnector<HttpConnector>>

Available on crate feature openssl-tls only.
Create [hyper_openssl::HttpsConnector] based on config. Read more
source§

fn openssl_https_connector_with_connector<H>( &self, connector: H, ) -> Result<HttpsConnector<H>>
where H: Service<Uri> + Send, H::Error: Into<Box<dyn Error + Send + Sync>>, H::Future: Send + 'static, H::Response: Read + Write + Connection + Unpin,

Available on crate feature openssl-tls only.
Create [hyper_openssl::HttpsConnector] based on config and connector. Read more
source§

impl Debug for Config

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl TryFrom<Config> for Client

Available on crate feature client only.
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.
source§

impl TryFrom<Config> for ClientBuilder<BoxService<Request<Body>, Response<Box<DynBody>>, BoxError>>

Available on crate feature client only.
source§

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

Builds a default ClientBuilder stack from a given configuration

source§

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations§

§

impl !Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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