@@ -1176,18 +1176,18 @@ func TestGetListComponentStatus(t *testing.T) {
1176
1176
1177
1177
tf .UnstructuredClient = & fake.RESTClient {
1178
1178
NegotiatedSerializer : resource .UnstructuredPlusDefaultContentConfig ().NegotiatedSerializer ,
1179
- Resp : & http.Response {StatusCode : http .StatusOK , Header : cmdtesting .DefaultHeader (), Body : cmdtesting . ObjBody (codec , statuses )},
1179
+ Resp : & http.Response {StatusCode : http .StatusOK , Header : cmdtesting .DefaultHeader (), Body : componentStatusTableObjBody (codec , ( * statuses ). Items ... )},
1180
1180
}
1181
1181
1182
1182
streams , _ , buf , _ := genericclioptions .NewTestIOStreams ()
1183
1183
cmd := NewCmdGet ("kubectl" , tf , streams )
1184
1184
cmd .SetOutput (buf )
1185
1185
cmd .Run (cmd , []string {"componentstatuses" })
1186
1186
1187
- expected := `NAME AGE
1188
- servergood <unknown>
1189
- serverbad <unknown>
1190
- serverunknown <unknown>
1187
+ expected := `NAME STATUS MESSAGE ERROR
1188
+ servergood Healthy ok
1189
+ serverbad Unhealthy bad status: 500
1190
+ serverunknown Unhealthy fizzbuzz error
1191
1191
`
1192
1192
if e , a := expected , buf .String (); e != a {
1193
1193
t .Errorf ("expected\n %v\n got\n %v" , e , a )
@@ -2788,6 +2788,33 @@ func nodeTableObjBody(codec runtime.Codec, nodes ...corev1.Node) io.ReadCloser {
2788
2788
return cmdtesting .ObjBody (codec , table )
2789
2789
}
2790
2790
2791
+ // build a meta table response from a componentStatus list
2792
+ func componentStatusTableObjBody (codec runtime.Codec , componentStatuses ... corev1.ComponentStatus ) io.ReadCloser {
2793
+ table := & metav1.Table {
2794
+ ColumnDefinitions : []metav1.TableColumnDefinition {
2795
+ {Name : "Name" , Type : "string" , Format : "name" },
2796
+ {Name : "Status" , Type : "string" , Format : "" },
2797
+ {Name : "Message" , Type : "string" , Format : "" },
2798
+ {Name : "Error" , Type : "string" , Format : "" },
2799
+ },
2800
+ }
2801
+ for _ , v := range componentStatuses {
2802
+ b := bytes .NewBuffer (nil )
2803
+ codec .Encode (& v , b )
2804
+ var status string
2805
+ if v .Conditions [0 ].Status == corev1 .ConditionTrue {
2806
+ status = "Healthy"
2807
+ } else {
2808
+ status = "Unhealthy"
2809
+ }
2810
+ table .Rows = append (table .Rows , metav1.TableRow {
2811
+ Object : runtime.RawExtension {Raw : b .Bytes ()},
2812
+ Cells : []interface {}{v .Name , status , v .Conditions [0 ].Message , v .Conditions [0 ].Error },
2813
+ })
2814
+ }
2815
+ return cmdtesting .ObjBody (codec , table )
2816
+ }
2817
+
2791
2818
// build an empty table response
2792
2819
func emptyTableObjBody (codec runtime.Codec ) io.ReadCloser {
2793
2820
table := & metav1.Table {
0 commit comments