forked from kube-rs/kube
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_client.rs
More file actions
29 lines (23 loc) · 889 Bytes
/
custom_client.rs
File metadata and controls
29 lines (23 loc) · 889 Bytes
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
use hyper_util::rt::TokioExecutor;
// Minimal custom client example.
use k8s_openapi::api::core::v1::Pod;
use tower::BoxError;
use tracing::*;
use kube::{client::ConfigExt, Api, Client, Config, ResourceExt};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();
let config = Config::infer().await?;
let https = config.rustls_https_connector()?;
let service = tower::ServiceBuilder::new()
.layer(config.base_uri_layer())
.option_layer(config.auth_layer()?)
.map_err(BoxError::from)
.service(hyper_util::client::legacy::Client::builder(TokioExecutor::new()).build(https));
let client = Client::new(service, config.default_namespace);
let pods: Api<Pod> = Api::default_namespaced(client);
for p in pods.list(&Default::default()).await? {
info!("{}", p.name_any());
}
Ok(())
}