Skip to main content

Crate kubex

Crate kubex 

Source
Expand description

§kubex

§Overview

kubex is a Rust library that provides utilities for Kubernetes. It complements kube and k8s-openapi crates, making it easier to detect contexts and explore API resources.

§Installation

Add the following dependency to your Cargo.toml.

[dependencies]
kubex = "0.3.0"

§Example

An example that combines DiscoverClient with the helper functions for namespaces and kube contexts.

cargo run --example main
use kubex::{determine_context, determine_namespace, discover::DiscoverClient};
use kube::Client;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let context = determine_context(&None)?;
    println!("context={context}");
    let namespace = determine_namespace(None, &context);
    println!("namespace={namespace}");

    let client = Client::try_default().await?;
    let discover = DiscoverClient::new(client);
    let resources = discover.list_api_resources().await?;

    for resource in resources {
        println!("{} {}", resource.group.as_deref().unwrap_or("").trim(), resource.name);
    }

    Ok(())
}

§License

This project is released under the MIT License.

Re-exports§

pub use claputil::context_value_completer;
pub use claputil::namespace_value_completer;
pub use clap_complete;
pub use k8s_openapi;
pub use kube;

Modules§

claputil
discover
dynamic

Functions§

determine_context
Detects the Kubernetes context based on the provided context argument.
determine_namespace
Determines the Kubernetes namespace based on the provided namespace and context.
find_resource
Finds and returns the APIResource that matches the given resource name from the list of api_resources.
match_resource
Checks if the given api_resource matches the target resource name. Matching is done against the resource’s name, singular name, short names, and group-qualified name.