Commit Diff


commit - fd89046d494b4bd492ea66ced9d8d18fe21b9273
commit + 4d6a19e9c385219c615df81f8205165737dd3eb7
blob - 60aa4e274b3355c07a06997bdfe9da6adaddec1e
blob + 886d58d7faf23ec9cba9edc69fc1f45459d48b42
--- kopsctl/src/cmd/pods.rs
+++ kopsctl/src/cmd/pods.rs
@@ -29,7 +29,7 @@ pub async fn execute(
     let resp = send_request(Request::Pods(req)).await?;
 
     match resp {
-        Response::Pods { pods } => print_pods(&pods),
+        Response::Pods { pods } => print_pods(&pods, failed_only),
         Response::Error { message } => bail!("reponse error {message}"),
         _ => bail!("unexpected response to version"),
     }
@@ -37,16 +37,31 @@ pub async fn execute(
     Ok(())
 }
 
-fn print_pods(pods: &Vec<PodSummary>) {
+fn print_pods(pods: &Vec<PodSummary>, failed_only: bool) {
     println!(
         "{:<20} {:<20} {:<30} {:<10} {:<10}",
         "CLUSTER", "NAMESPACE", "NAME", "READY", "RESTARTS"
     );
 
     for p in pods {
-        println!(
-            "{:<20} {:<20} {:<30} {:<10} {:<10}",
-            p.cluster, p.namespace, p.name, p.ready, p.restart_count
-        );
+        if failed_only {
+            if let Some(msg) = &p.message {
+                println!(
+                    "{:<20} {:<20} {:<30} {:<10} {:<10} {:<10}",
+                    p.cluster, p.namespace, p.name, p.ready, p.restart_count, msg
+                );
+            } else {
+                println!(
+                    "{:<20} {:<20} {:<30} {:<10} {:<10}",
+                    p.cluster, p.namespace, p.name, p.ready, p.restart_count,
+                );
+            }
+
+        } else {
+            println!(
+                "{:<20} {:<20} {:<30} {:<10} {:<10}",
+                p.cluster, p.namespace, p.name, p.ready, p.restart_count
+            );
+        }
     }
 }
blob - 229379fec7987c02ced194584bcd422ee3513084
blob + 70299a96755ff0ef3ec3a50f2ddf87c87106c2e8
--- kopsd/src/handler.rs
+++ kopsd/src/handler.rs
@@ -176,40 +176,42 @@ impl Handler {
             };
         };
 
-        let mut pods: Vec<PodSummary> = Vec::new();
+        // let mut pods: Vec<PodSummary> = Vec::new();
         let pods_snapshot = cluster_state.store().state();
-        for pod in pods_snapshot {
-            if let Some(summary) = PodSummary::from_pod(cluster_name, &pod) {
-                pods.push(summary);
-            }
-        }
+        // for pod in pods_snapshot {
+        //     if let Some(summary) = PodSummary::from_pod(cluster_name, &pod) {
+        //         pods.push(summary);
+        //     }
+        // }
 
         // // let map = cluster_state.pods.read().await;
         // let map = cluster_state.store().state();
 
-        // let mut pods: Vec<_> = map
-        //     .values()
-        //     .cloned()
-        //     .filter(|p| {
-        //         if let Some(ns) = &req.namespace {
-        //             if &p.namespace != ns {
-        //                 return false;
-        //             }
-        //         }
-        //         if req.failed_only {
-        //             if p.phase.as_deref() != Some("Failed")
-        //                 && p.reason.as_deref() != Some("CrashLoopBackOff")
-        //             {
-        //                 return false;
-        //             }
-        //         }
-        //         true
-        //     })
-        //     .collect();
+        let mut pods: Vec<PodSummary> = pods_snapshot
+            .into_iter()
+            .filter_map(|p| {
+                PodSummary::from_pod(cluster_name, &p)
+            })
+            .filter(|p| {
+                if let Some(ns) = &req.namespace {
+                    if &p.namespace != ns {
+                        return false;
+                    }
+                }
+                if req.failed_only {
+                    if p.phase.as_deref() != Some("Failed")
+                        && p.reason.as_deref() != Some("CrashLoopBackOff")
+                    {
+                        return false;
+                    }
+                }
+                true
+            })
+            .collect();
 
-        // pods.sort_by(|a, b| {
-        //     a.namespace.cmp(&b.namespace).then(a.name.cmp(&b.name))
-        // });
+        pods.sort_by(|a, b| {
+            a.namespace.cmp(&b.namespace).then(a.name.cmp(&b.name))
+        });
 
         Response::Pods { pods }
     }