Struct kube_client::config::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>,
}
Expand description
Configuration object detailing things like cluster URL, default namespace, root certificates, and timeouts.
§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
Implementations§
source§impl Config
impl Config
sourcepub fn new(cluster_url: Uri) -> Self
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.
sourcepub async fn infer() -> Result<Self, InferConfigError>
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.
sourcepub fn incluster() -> Result<Self, InClusterError>
pub fn incluster() -> Result<Self, InClusterError>
Load an in-cluster Kubernetes client configuration using
Config::incluster_env
.
sourcepub fn incluster_env() -> Result<Self, InClusterError>
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.
sourcepub fn incluster_dns() -> Result<Self, InClusterError>
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.
sourcepub async fn from_kubeconfig(
options: &KubeConfigOptions,
) -> Result<Self, KubeconfigError>
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.
sourcepub async fn from_custom_kubeconfig(
kubeconfig: Kubeconfig,
options: &KubeConfigOptions,
) -> Result<Self, KubeconfigError>
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.
sourcepub fn apply_debug_overrides(&mut self)
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 theServiceAccount
foo
in theNamespace
default
KUBE_RS_DEBUG_IMPERSONATE_GROUP
: A Kubernetes group to impersonate, multiple groups may be specified by separating them with commasKUBE_RS_DEBUG_OVERRIDE_URL
: A Kubernetes cluster URL to use rather than the one specified in the config, useful for proxying traffic throughkubectl proxy
Trait Implementations§
source§impl ConfigExt for Config
impl ConfigExt for Config
source§fn base_uri_layer(&self) -> BaseUriLayer
fn base_uri_layer(&self) -> BaseUriLayer
source§fn auth_layer(&self) -> Result<Option<AuthLayer>>
fn auth_layer(&self) -> Result<Option<AuthLayer>>
Authorization
header depending on the config.source§fn extra_headers_layer(&self) -> Result<ExtraHeadersLayer>
fn extra_headers_layer(&self) -> Result<ExtraHeadersLayer>
source§fn openssl_ssl_connector_builder(&self) -> Result<SslConnectorBuilder>
fn openssl_ssl_connector_builder(&self) -> Result<SslConnectorBuilder>
openssl::ssl::SslConnectorBuilder
based on config. Read moresource§fn openssl_https_connector(&self) -> Result<HttpsConnector<HttpConnector>>
fn openssl_https_connector(&self) -> Result<HttpsConnector<HttpConnector>>
hyper_openssl::HttpsConnector
] based on config. Read moresource§fn openssl_https_connector_with_connector<H>(
&self,
connector: H,
) -> Result<HttpsConnector<H>>
fn openssl_https_connector_with_connector<H>( &self, connector: H, ) -> Result<HttpsConnector<H>>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)