Struct Kubernetes

Source
pub struct Kubernetes { /* private fields */ }
Expand description

The main type for instantiating clients for managing kubernetes resources

Implementations§

Source§

impl Kubernetes

Source

pub fn load_conf<P: AsRef<Path>>(path: P) -> Result<Kubernetes>

Initialize a Kubernetes client from a Kubernets config file

Incomplete: load_conf was only implemented to meet the needs of a single config, so it is currently hard-coded to require a CA cert, a client cert, and skip hostname verification. PRs for improving this are much appreciated.

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
Source

pub fn load_conf_with_ctx<P: AsRef<Path>>( path: P, ctxname: &str, ) -> Result<Kubernetes>

Initialize a Kubernetes client from a Kubernets config file

Incomplete: load_conf was only implemented to meet the needs of a single config, so it is currently hard-coded to require a CA cert, a client cert, and skip hostname verification. PRs for improving this are much appreciated.

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
Source

pub fn config_maps(&self) -> KubeClient<ConfigMap>

Get a kubernetes client for managing ConfigMaps

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
if kube.config_maps().exists("my-config-map")? {
    println!("Found 'my-config-map'")
}
Source

pub fn deployments(&self) -> KubeClient<Deployment>

Get a kubernetes client for managing Deployments

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
if kube.deployments().exists("web-server")? {
    println!("Found 'web-server' deployment")
}
Source

pub fn network_policies(&self) -> KubeClient<NetworkPolicy>

Get a kubernetes client for managing NetworkPolicies

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
if kube.network_policies().exists("web-server")? {
    println!("Found 'web-server' network policy")
}
Source

pub fn nodes(&self) -> KubeClient<Node>

Get a kubernetes client for managing Nodes

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
if kube.nodes().exists("node-123")? {
    println!("Found 'node-123'")
}
Source

pub fn pods(&self) -> KubeClient<Pod>

Get a kubernetes client for managing Pods

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
if kube.pods().exists("web-server-abcdefgh12345678")? {
    println!("Found 'web-server-abcdefgh12345678' pod")
}
Source

pub fn secrets(&self) -> KubeClient<Secret>

Get a kubernetes client for managing Secrets

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
if kube.secrets().exists("my-secret")? {
    println!("Found 'my-secret'")
}
Source

pub fn services(&self) -> KubeClient<Service>

Get a kubernetes client for managing Services

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
if kube.services().exists("web-server")? {
    println!("Found 'web-server' service")
}
Source

pub fn namespace(&self, namespace: &str) -> Kubernetes

Get a kubernetes client that uses a specific namespace

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
let cluster_info = kube.namespace("kube-system")
    .secrets()
    .get("clusterinfo")?;
Source

pub fn logs(&self) -> Kubernetes

Get a kubernetes client that uses a specific namespace

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
let cluster_info = kube.namespace("kube-system")
    .secrets()
    .get("clusterinfo")?;
Source

pub fn healthy(&self) -> Result<bool>

Check to see if the Kubernetes API is healthy

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
let is_healthy = kube.healthy()?;
Source

pub fn apply<P: AsRef<Path>>(&self, path: P) -> Result<()>

Applies a JSON or YAML resource file

This is similar to the kubectl apply CLI commands.

This may be a single file or an entire directory. If the resource(s) specified already exists, this method will NOT replace the resource.

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
let is_healthy = kube.apply("web-server/deployment.yaml")?;
Source

pub fn replace<P: AsRef<Path>>(&self, path: P) -> Result<()>

Replaces a JSON or YAML resource file

This is similar to the kubectl replace CLI commands.

This may be a single file or an entire directory. If the resource(s) specified already exists, this method will replace the resource.

§Examples
let kube = Kubernetes::load_conf("admin.conf")?;
let is_healthy = kube.replace("web-server/deployment.yaml")?;
Source

pub fn create<R: Resource>(&self, resource: &R) -> Result<R>

Creates a resource from a typed resource defintion

This is similar to the kubectl create CLI commands.

Note: most of the resource type defintions are incomplete Pull requests to fill missing fields/types are appreciated (especially if documented).

§Examples:
let kube = Kubernetes::load_conf("admin.conf")?;
let mut secret = Secret::new("web-server");
secret.insert("db_password", "abc123");
let response = kube.create(&secret)?;

Trait Implementations§

Source§

impl Clone for Kubernetes

Source§

fn clone(&self) -> Kubernetes

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

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Err = <U as TryFrom<T>>::Err

Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Err>

Source§

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