diff --git a/Cargo.lock b/Cargo.lock index 6bc0520..01e75f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -851,12 +851,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "iana-time-zone" version = "0.1.58" @@ -1823,7 +1817,6 @@ dependencies = [ "fs2", "futures", "handlebars", - "humantime", "itertools", "k8s-openapi", "log", diff --git a/Cargo.toml b/Cargo.toml index 1877cf0..f3e97ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,4 +34,3 @@ fs2 = "0.4.3" log = "0.4.20" handlebars = "5.1.2" cron = "0.12.1" -humantime = "2.1.0" diff --git a/src/get/cronjob.rs b/src/get/cronjob.rs index 973e76e..4a8a4cd 100644 --- a/src/get/cronjob.rs +++ b/src/get/cronjob.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; use chrono::SecondsFormat; -use humantime; use k8s_openapi::api::batch::v1::CronJob; use crate::filestore::ObjectListItem; use crate::get::{Lister}; diff --git a/src/get/ingress.rs b/src/get/ingress.rs index f0b394c..f3e78e8 100644 --- a/src/get/ingress.rs +++ b/src/get/ingress.rs @@ -4,6 +4,7 @@ use crate::filestore::ObjectListItem; use crate::get::{Lister}; use crate::get::lister::NameFilters; use crate::skatelet::SystemInfo; +use crate::util::{age, NamespacedName}; pub(crate) struct IngresssLister {} @@ -16,18 +17,27 @@ impl Lister for IngresssLister { } fn print(&self, resources: Vec) { + macro_rules! cols { + () => ("{0: <15} {1: <15} {2: <15} {3: <15} {4: <15} {5: <15} {6: <15}") + } println!( - "{0: <30} {1: <5} {2: <20}", - "NAME", "#", "CREATED", + cols!(), + "NAMESPACE", "NAME", "CLASS", "HOSTS", "ADDRESS", "PORTS", "AGE" ); - let map = resources.iter().fold(HashMap::>::new(), |mut acc, item| { - acc.entry(item.name.to_string()).or_insert(vec![]).push(item.clone()); + let map = resources.iter().fold(HashMap::>::new(), |mut acc, item| { + acc.entry(item.name.clone()).or_insert(vec![]).push(item.clone()); acc }); + for (name, item) in map { + let hosts = "TODO"; + let age = age(item.first().unwrap().created_at); + let address = "TODO"; + let class = "TODO"; + let ports = "TODO"; println!( - "{0: <30} {1: <5} {2: <20}", - name, item.len(), item.first().unwrap().created_at.to_rfc3339_opts(SecondsFormat::Secs, true) + cols!(), + name.namespace, name.name, class, hosts, address, ports, age ) } } diff --git a/src/util.rs b/src/util.rs index 66bd57b..8591cf3 100644 --- a/src/util.rs +++ b/src/util.rs @@ -179,9 +179,22 @@ pub fn hash_k8s_resource(obj: &mut (impl Metadata) -> String { match Local::now().signed_duration_since(date_time).to_std() { - Ok(age) => humantime::format_duration(age).to_string() - .split_whitespace().take(1).collect::>() - .join(""), + Ok(duration) => { + if duration.as_secs() < 60 { + return format!("{}s", duration.as_secs()); + } + let minutes = (duration.as_secs() / 60) % 60; + if minutes < 60 { + return format!("{}m", minutes); + } + let hours = duration.as_secs() / 60 * 60; + if hours < 24 { + return format!("{}h", hours); + } + + let days = duration.as_secs() / 60 * 60 * 24; + return format!("{}d", days); + } Err(_) => "".to_string() } } \ No newline at end of file