kube_client::config

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 disable_compression: bool,
    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.

§disable_compression: bool

Whether to disable compression (would only have an effect when the gzip feature is enabled)

§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 u8)

🔬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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T