From eca489460a33a45b95b18251de2a76642f9c4ca3 Mon Sep 17 00:00:00 2001 From: Donal Byrne Date: Tue, 30 Jul 2024 10:54:17 +0200 Subject: [PATCH] Ingress table format --- src/get/ingress.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/get/ingress.rs b/src/get/ingress.rs index f3e78e8..fc5ddc9 100644 --- a/src/get/ingress.rs +++ b/src/get/ingress.rs @@ -1,5 +1,7 @@ use std::collections::HashMap; use chrono::SecondsFormat; +use k8s_openapi::api::batch::v1::CronJob; +use k8s_openapi::api::networking::v1::Ingress; use crate::filestore::ObjectListItem; use crate::get::{Lister}; use crate::get::lister::NameFilters; @@ -18,7 +20,7 @@ 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}") + () => ("{0: <15} {1: <15} {2: <15} {3: <25} {4: <15} {5: <15} {6: <15}") } println!( cols!(), @@ -29,12 +31,16 @@ impl Lister for IngresssLister { 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"; + for (name, items) in map { + let first = items.first().unwrap(); + let ingress: Ingress = serde_yaml::from_value(first.manifest.as_ref().unwrap().clone()).unwrap_or_default(); + let spec = ingress.spec.unwrap_or_default(); + + let hosts = spec.rules.unwrap_or_default().iter().map(|r| r.host.clone().unwrap_or_default()).collect::>().join(","); + let age = age(first.created_at); + let address = ""; + let class = "external"; + let ports = "80,443"; println!( cols!(), name.namespace, name.name, class, hosts, address, ports, age