@@ -10,6 +10,7 @@ import (
1010 "github.com/gosuri/uitable"
1111 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1212 "k8s.io/apimachinery/pkg/util/duration"
13+ "sigs.k8s.io/cli-utils/pkg/kstatus/status"
1314)
1415
1516const (
@@ -20,22 +21,23 @@ const (
2021)
2122
2223var (
23- gray = color .New (color .FgHiBlack )
24- red = color .New (color .FgRed )
25- green = color .New (color .FgGreen )
24+ gray = color .New (color .FgHiBlack )
25+ red = color .New (color .FgRed )
26+ yellow = color .New (color .FgYellow )
27+ green = color .New (color .FgGreen )
2628)
2729
2830// treeView prints object hierarchy to out stream.
2931func treeView (out io.Writer , objs objectDirectory , obj unstructured.Unstructured ) {
3032 tbl := uitable .New ()
3133 tbl .Separator = " "
32- tbl .AddRow ("NAMESPACE" , "NAME" , "READY" , "REASON" , "AGE" )
34+ tbl .AddRow ("NAMESPACE" , "NAME" , "READY" , "REASON" , "STATUS" , " AGE" )
3335 treeViewInner ("" , tbl , objs , obj )
3436 fmt .Fprintln (color .Output , tbl )
3537}
3638
3739func treeViewInner (prefix string , tbl * uitable.Table , objs objectDirectory , obj unstructured.Unstructured ) {
38- ready , reason := extractStatus (obj )
40+ ready , reason , kstatus := extractStatus (obj )
3941
4042 var readyColor * color.Color
4143 switch ready {
@@ -50,6 +52,21 @@ func treeViewInner(prefix string, tbl *uitable.Table, objs objectDirectory, obj
5052 ready = "-"
5153 }
5254
55+ var statusColor * color.Color
56+ switch kstatus {
57+ case status .CurrentStatus :
58+ statusColor = green
59+ case status .InProgressStatus :
60+ statusColor = yellow
61+ case status .FailedStatus , status .TerminatingStatus :
62+ statusColor = red
63+ default :
64+ statusColor = gray
65+ }
66+ if kstatus == "" {
67+ kstatus = "-"
68+ }
69+
5370 c := obj .GetCreationTimestamp ()
5471 age := duration .HumanDuration (time .Since (c .Time ))
5572 if c .IsZero () {
@@ -62,6 +79,7 @@ func treeViewInner(prefix string, tbl *uitable.Table, objs objectDirectory, obj
6279 color .New (color .Bold ).Sprint (obj .GetName ())),
6380 readyColor .Sprint (ready ),
6481 readyColor .Sprint (reason ),
82+ statusColor .Sprint (kstatus ),
6583 age )
6684 chs := objs .ownedBy (obj .GetUID ())
6785 for i , child := range chs {
0 commit comments