Commit 2850ce69 authored by mengxue's avatar mengxue
Browse files

change createTime in ListObjects

parent f5774f3b
......@@ -25,8 +25,9 @@ import scala.concurrent.duration._
object ListObjects extends App{
case class PodInfo (
status: String,
restarts: Int,
startTime: Timestamp
createTime: Timestamp
)
private def listPods(pods: List[Pod]) = {
......@@ -37,23 +38,19 @@ object ListObjects extends App{
pods.map { pod: Pod =>
val name = pod.name
val ns = pod.namespace
val phaseOpt = for {
stat <- pod.status
status <- stat.phase
} yield status
val status = phaseOpt.getOrElse("Not set")
val podInfo = (for {
status <- pod.status.toList
restarts <- status.containerStatuses
startTime <- status.startTime
stat <- pod.status.toList
status <- stat.phase
restarts <- stat.containerStatuses.headOption
createTime <- pod.metadata.creationTimestamp
} yield {
//st = status.containerStatuses.map {_.restartCount}
PodInfo(restarts.restartCount,startTime)
PodInfo(status.toString, restarts.restartCount, createTime)
}).headOption
val startTimeString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(podInfo.map{_.startTime}.getOrElse("None").toString())
val createTimeString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(podInfo.map{_.createTime}.getOrElse("None").toString())
System.out.println(f"${name}%-50s${ns}%-20s${status}%-20s${podInfo.map{_.restarts}.getOrElse("None")}%-20s${startTimeString}")
System.out.println(f"${name}%-50s${ns}%-20s${podInfo.map{_.status}.getOrElse("None")}%-20s${podInfo.map{_.restarts}.getOrElse("None")}%-20s${createTimeString}")
}
}
......@@ -64,7 +61,6 @@ object ListObjects extends App{
val k8s = k8sInit
System.out.println("\n======================================== kubectl get pods ========================================")
System.out.println("\nGetting list of pods in namespace of current context ==>")
......@@ -78,7 +74,6 @@ object ListObjects extends App{
}
Await.ready(printCurrNsPods, 30 seconds)
System.out.println("\n============================= kubectl get pods --namespace=kube-system ============================")
System.out.println("\nGetting lists of pods in 'kube-system' namespace ==>")
......@@ -92,7 +87,6 @@ object ListObjects extends App{
}
Await.ready(printKSysPods, 30 seconds)
System.out.println("\n================================= kubectl get pods --all-namespaces ================================")
System.out.println("\nGetting lists of pods in all namespaces in the cluster ==>")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment