#[macro_use] extern crate log;
use k8s_openapi::api::apps::v1::Deployment;
use kube::{
api::{ListParams, Meta, Resource},
client::APIClient,
config,
runtime::Reflector,
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
std::env::set_var("RUST_LOG", "info,kube=debug");
env_logger::init();
let config = config::load_kube_config().await?;
let client = APIClient::new(config);
let namespace = std::env::var("NAMESPACE").unwrap_or("default".into());
let resource = Resource::namespaced::<Deployment>(&namespace);
let lp = ListParams::default().timeout(10); let rf: Reflector<Deployment> = Reflector::new(client, lp, resource).init().await?;
rf.state().await?.into_iter().for_each(|d| {
info!(
"Found deployment for {} - {} replicas running {:?}",
Meta::name(&d),
d.status.unwrap().replicas.unwrap(),
d.spec
.unwrap()
.template
.spec
.unwrap()
.containers
.into_iter()
.map(|c| c.image.unwrap())
.collect::<Vec<_>>()
);
});
loop {
rf.poll().await?;
let deploys: Vec<_> = rf.state().await?.iter().map(Meta::name).collect();
info!("Current deploys: {:?}", deploys);
}
}