kube_client::discovery::oneshot

Function pinned_group

Source
pub async fn pinned_group(
    client: &Client,
    gv: &GroupVersion,
) -> Result<ApiGroup>
Available on crate feature client only.
Expand description

Discovers all APIs available under a certain group at a pinned version

This is a cheaper variant of oneshot::group when you know what version you want.

use kube::{Client, api::{Api, DynamicObject}, discovery, ResourceExt};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::try_default().await?;
    let gv = "apiregistration.k8s.io/v1".parse()?;
    let apigroup = discovery::pinned_group(&client, &gv).await?;
    let (ar, caps) = apigroup.recommended_kind("APIService").unwrap();
    let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar);
    for service in api.list(&Default::default()).await? {
        println!("Found APIService: {}", service.name_any());
    }
    Ok(())
}

While this example only uses a single kind, this type of discovery works best when you need more than a single kind. If you only need a single kind, oneshot::pinned_kind is the best solution.