pub struct ApiGroup { /* private fields */ }
This is supported on crate feature client only.
Expand description

Describes one API groups collected resources and capabilities.

Each ApiGroup contains all data pinned to a each version. In particular, one data set within the ApiGroup for "apiregistration.k8s.io" is the subset pinned to "v1"; commonly referred to as "apiregistration.k8s.io/v1".

If you know the version of the discovered group, you can fetch it directly:

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 apigroup = discovery::group(&client, "apiregistration.k8s.io").await?;
     for (apiresource, caps) in apigroup.versioned_resources("v1") {
         println!("Found ApiResource {}", apiresource.kind);
     }
    Ok(())
}

But if you do not know this information, you can use ApiGroup::preferred_version_or_latest.

Whichever way you choose the end result is something describing a resource and its abilities:

  • Vec<(ApiResource, ApiCapabilities)>` :: for all resources in a versioned ApiGroup
  • (ApiResource, ApiCapabilities) :: for a single kind under a versioned ApiGroud

These two types: ApiResource, and ApiCapabilities should contain the information needed to construct an Api and start querying the kubernetes API. You will likely need to use DynamicObject as the generic type for Api to do this, as well as the ApiResource for the DynamicType for the Resource trait.

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 apigroup = discovery::group(&client, "apiregistration.k8s.io").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());
    }
    Ok(())
}

Implementations

Public ApiGroup interface

Core group name

Returns the name of this group.

Returns served versions (e.g. ["v1", "v2beta1"]) of this group.

This Iterator is never empty, and returns elements in descending order of Version:

  • Stable versions (with the last being the first)
  • Beta versions (with the last being the first)
  • Alpha versions (with the last being the first)
  • Other versions, alphabetically

Returns preferred version for working with given group.

Returns the preferred version or latest version for working with given group.

If the server does not recommend a version, we pick the “most stable and most recent” version in accordance with kubernetes version priority via the descending sort order from Version.

Returns the resources in the group at an arbitrary version string.

If the group does not support this version, the returned vector is empty.

If you are looking for the api recommended list of resources, or just on particular kind consider ApiGroup::recommended_resources or ApiGroup::recommended_kind instead.

Returns the recommended (preferred or latest) versioned resources in the group

use kube::{Client, api::{Api, DynamicObject}, discovery::{self, verbs}, ResourceExt};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::try_default().await?;
    let apigroup = discovery::group(&client, "apiregistration.k8s.io").await?;
    for (ar, caps) in apigroup.recommended_resources() {
        if !caps.supports_operation(verbs::LIST) {
            continue;
        }
        let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar);
        for inst in api.list(&Default::default()).await? {
            println!("Found {}: {}", ar.kind, inst.name());
        }
    }
    Ok(())
}

This is equivalent to taking the ApiGroup::versioned_resources at the ApiGroup::preferred_version_or_latest.

Returns the recommended version of the kind in the recommended resources (if found)

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 apigroup = discovery::group(&client, "apiregistration.k8s.io").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());
    }
    Ok(())
}

This is equivalent to filtering the ApiGroup::versioned_resources at ApiGroup::preferred_version_or_latest against a chosen kind.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more