pub struct Discovery { /* private fields */ }
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§
source§impl Discovery
impl Discovery
Caching discovery interface
Builds an internal map of its cache
sourcepub fn filter(self, allow: &[&str]) -> Self
pub fn filter(self, allow: &[&str]) -> Self
Configure the discovery client to only look for the listed apigroups
sourcepub fn exclude(self, deny: &[&str]) -> Self
pub fn exclude(self, deny: &[&str]) -> Self
Configure the discovery client to look for all apigroups except the listed ones
sourcepub async fn run(self) -> Result<Self>
pub async fn run(self) -> Result<Self>
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<(), Box<dyn std::error::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_any());
}
}
}
Ok(())
}
See a bigger example in examples/dynamic.api
source§impl Discovery
impl Discovery
Interface to the Discovery cache
sourcepub fn groups(&self) -> impl Iterator<Item = &ApiGroup>
pub fn groups(&self) -> impl Iterator<Item = &ApiGroup>
Returns iterator over all served groups
sourcepub fn groups_alphabetical(&self) -> Vec<&ApiGroup>
pub fn groups_alphabetical(&self) -> Vec<&ApiGroup>
Returns a sorted vector of all served groups
This vector is in kubectl’s normal alphabetical group order
sourcepub fn get(&self, group: &str) -> Option<&ApiGroup>
pub fn get(&self, group: &str) -> Option<&ApiGroup>
Returns the ApiGroup
for a given group if served
sourcepub fn resolve_gvk(
&self,
gvk: &GroupVersionKind,
) -> Option<(ApiResource, ApiCapabilities)>
pub fn resolve_gvk( &self, gvk: &GroupVersionKind, ) -> Option<(ApiResource, ApiCapabilities)>
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 Freeze for Discovery
impl !RefUnwindSafe for Discovery
impl Send for Discovery
impl Sync for Discovery
impl Unpin for Discovery
impl !UnwindSafe for Discovery
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more