Struct kube::Discovery[][src]

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

A caching client for running API discovery against the Kubernetes API.

This simplifies the required querying and type matching, and stores the responses for each discovered api group and exposes helpers to access them.

The discovery process varies in complexity depending on:

  • how much you know about the kind(s) and group(s) you are interested in
  • how many groups you are interested in

Discovery can be performed on:

  • all api groups (default)
  • a subset of api groups (by setting Discovery::filter)

To make use of discovered apis, extract one or more ApiGroups from it, or resolve a precise one using Discovery::resolve_gvk.

If caching of results is not required, then a simpler oneshot discovery system can be used.

Implementations

Caching discovery interface

Builds an internal map of its cache

Construct a caching api discovery client

Configure the discovery client to only look for the listed apigroups

Configure the discovery client to look for all apigroups except the listed ones

Runs or re-runs the configured discovery algorithm and updates/populates the cache

The cache is empty cleared when this is started. By default, every api group found is checked, causing N+2 queries to the api server (where N is number of api groups).

use kube::{Client, api::{Api, DynamicObject}, discovery::{Discovery, verbs, Scope}, ResourceExt};
#[tokio::main]
async fn main() -> Result<(), kube::Error> {
    let client = Client::try_default().await?;
    let discovery = Discovery::new(client.clone()).run().await?;
    for group in discovery.groups() {
        for (ar, caps) in group.recommended_resources() {
            if !caps.supports_operation(verbs::LIST) {
                continue;
            }
            let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar);
            // can now api.list() to emulate kubectl get all --all
            for obj in api.list(&Default::default()).await? {
                println!("{} {}: {}", ar.api_version, ar.kind, obj.name());
            }
        }
    }
    Ok(())
}

See a bigger example in examples/dynamic.api

Interface to the Discovery cache

Returns iterator over all served groups

Returns the ApiGroup for a given group if served

Check if a group is served by the apiserver

Finds an ApiResource and its ApiCapabilities after discovery by matching a GVK

This is for quick extraction after having done a complete discovery. If you are only interested in a single kind, consider oneshot::pinned_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

Performs the conversion.

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

Performs the conversion.

Should always be Self

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.