forked from kube-rs/kube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic_api.rs
39 lines (33 loc) · 1.19 KB
/
dynamic_api.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! In this example we will implement something similar to `kubectl get all`.
use kube::{
api::{Api, DynamicObject, ResourceExt},
discovery::{verbs, Discovery, Scope},
Client,
};
use tracing::*;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();
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> = if caps.scope == Scope::Cluster {
Api::all_with(client.clone(), &ar)
} else {
Api::default_namespaced_with(client.clone(), &ar)
};
info!("{}/{} : {}", group.name(), ar.version, ar.kind);
let list = api.list(&Default::default()).await?;
for item in list.items {
let name = item.name_any();
let ns = item.metadata.namespace.map(|s| s + "/").unwrap_or_default();
info!("\t\t{}{}", ns, name);
}
}
}
Ok(())
}