Struct kube::Discovery [−][src]
pub struct Discovery { /* fields omitted */ }
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 ApiGroup
s 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
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 the ApiGroup
for a given group if served
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
impl !RefUnwindSafe for Discovery
impl !UnwindSafe for Discovery
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
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