From be9da8e52b32c0725abb7cf4549c493f06bac711 Mon Sep 17 00:00:00 2001 From: Eswar Rajan Subramanian Date: Mon, 12 Sep 2022 17:13:33 +0530 Subject: [PATCH] Display PodInfo in table format Signed-off-by: Eswar Rajan Subramanian --- summary/table.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/summary/table.go b/summary/table.go index 16d64c70..d062619b 100644 --- a/summary/table.go +++ b/summary/table.go @@ -27,9 +27,7 @@ func DisplaySummaryOutput(resp *opb.Response, revDNSLookup bool, requestType str return } - podInfo := resp.PodName + "/" + resp.Namespace + "/" + resp.ClusterName + "/" + resp.Label + "/" + resp.ContainerName - - fmt.Printf("\nPodInfo : [%s]\n", podInfo) + writePodInfoToTable(resp.PodName, resp.Namespace, resp.ClusterName, resp.ContainerName, resp.Label) if strings.Contains(requestType, "process") { if len(resp.ProcessData) > 0 { @@ -136,3 +134,27 @@ func WriteTable(header []string, data [][]string) { } table.Render() } + +func writePodInfoToTable(podname, namespace, clustername, containername, labels string) { + + fmt.Printf("\n") + + podinfo := [][]string{ + {"Pod Name", podname}, + {"Namespace Name", namespace}, + {"Cluster Name", clustername}, + {"Container Name", containername}, + {"Labels", labels}, + } + table := tablewriter.NewWriter(os.Stdout) + table.SetBorder(false) + table.SetTablePadding("\t") + table.SetCenterSeparator("") + table.SetColumnSeparator("") + table.SetRowSeparator("") + table.SetAlignment(tablewriter.ALIGN_LEFT) + for _, v := range podinfo { + table.Append(v) + } + table.Render() +}