@@ -28,6 +28,7 @@ import (
28
28
"github.com/fatih/color"
29
29
"github.com/gobuffalo/flect"
30
30
"github.com/olekukonko/tablewriter"
31
+ "github.com/olekukonko/tablewriter/tw"
31
32
corev1 "k8s.io/api/core/v1"
32
33
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33
34
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -64,12 +65,19 @@ var (
64
65
// PrintObjectTree prints the cluster status to stdout.
65
66
// Note: this function is exposed only for usage in clusterctl and Cluster API E2E tests.
66
67
func PrintObjectTree (tree * tree.ObjectTree , w io.Writer ) {
68
+
69
+ cfg := getObjectTreeConfig ()
67
70
// Creates the output table
68
- tbl := tablewriter .NewWriter (w )
69
- tbl .SetHeader ([]string {"NAME" , "REPLICAS" , "AVAILABLE" , "READY" , "UP TO DATE" , "STATUS" , "REASON" , "SINCE" , "MESSAGE" })
71
+ tbl := tablewriter .NewTable (os .Stdin , tablewriter .WithConfig (cfg ), tablewriter .WithRendition (tw.Rendition {
72
+ Settings : tw.Settings {
73
+ Separators : tw .SeparatorsNone , Lines : tw .LinesNone ,
74
+ },
75
+ Borders : tw .BorderNone ,
76
+ }))
77
+
78
+ // tbl := tablewriter.NewWriter(w)
79
+ tbl .Header ([]string {"NAME" , "REPLICAS" , "AVAILABLE" , "READY" , "UP TO DATE" , "STATUS" , "REASON" , "SINCE" , "MESSAGE" })
70
80
71
- formatTableTree (tbl )
72
- // Add row for the root object, the cluster, and recursively for all the nodes representing the cluster status.
73
81
addObjectRow ("" , tbl , tree , tree .GetRoot ())
74
82
75
83
// Prints the output table
@@ -79,48 +87,56 @@ func PrintObjectTree(tree *tree.ObjectTree, w io.Writer) {
79
87
// PrintObjectTreeV1Beta1 prints the cluster status to stdout.
80
88
// Note: this function is exposed only for usage in clusterctl and Cluster API E2E tests.
81
89
func PrintObjectTreeV1Beta1 (tree * tree.ObjectTree ) {
90
+ cfg := getObjectTreeConfigV1Beta1 ()
91
+
82
92
// Creates the output table
83
- tbl := tablewriter .NewWriter (os .Stdout )
84
- tbl .SetHeader ([]string {"NAME" , "READY" , "SEVERITY" , "REASON" , "SINCE" , "MESSAGE" })
93
+ tbl := tablewriter .NewTable (os .Stdin , tablewriter .WithConfig (cfg ), tablewriter .WithRendition (tw.Rendition {
94
+ Settings : tw.Settings {
95
+ Separators : tw .SeparatorsNone , Lines : tw .LinesNone ,
96
+ },
97
+ Borders : tw .BorderNone ,
98
+ }))
99
+ tbl .Header ([]string {"NAME" , "READY" , "SEVERITY" , "REASON" , "SINCE" , "MESSAGE" })
85
100
86
- formatTableTreeV1Beta1 (tbl )
87
101
// Add row for the root object, the cluster, and recursively for all the nodes representing the cluster status.
88
102
addObjectRowV1Beta1 ("" , tbl , tree , tree .GetRoot ())
89
103
90
104
// Prints the output table
91
105
tbl .Render ()
92
106
}
93
107
94
- // formats the table with required attributes.
95
- func formatTableTree (tbl * tablewriter.Table ) {
96
- tbl .SetAutoWrapText (false )
97
- tbl .SetHeaderAlignment (tablewriter .ALIGN_LEFT )
98
- tbl .SetAlignment (tablewriter .ALIGN_LEFT )
99
-
100
- tbl .SetCenterSeparator ("" )
101
- tbl .SetRowSeparator ("" )
102
-
103
- tbl .SetHeaderLine (false )
104
- tbl .SetTablePadding (" " )
105
- tbl .SetNoWhiteSpace (true )
108
+ // Creates custom configuration for the table for the object tree.
109
+ func getObjectTreeConfig () tablewriter.Config {
110
+ cfg := tablewriter.Config {
111
+ Row : tw.CellConfig {
112
+ Formatting : tw.CellFormatting {AutoWrap : tw .WrapNone },
113
+ Alignment : tw.CellAlignment {Global : tw .AlignLeft },
114
+ Padding : tw.CellPadding {Global : tw.Padding {Left : "" , Right : " " }},
115
+ },
116
+ Header : tw.CellConfig {
117
+ Alignment : tw.CellAlignment {Global : tw .AlignLeft },
118
+ },
119
+ Behavior : tw.Behavior {TrimSpace : tw .Off },
120
+ }
121
+
122
+ return cfg
106
123
}
107
124
108
- // formats the table with required attributes.
109
- func formatTableTreeV1Beta1 (tbl * tablewriter.Table ) {
110
- tbl .SetAutoWrapText (false )
111
- tbl .SetHeaderAlignment (tablewriter .ALIGN_LEFT )
112
- tbl .SetAlignment (tablewriter .ALIGN_LEFT )
113
-
114
- tbl .SetCenterSeparator ("" )
115
- tbl .SetColumnSeparator ("" )
116
- tbl .SetRowSeparator ("" )
125
+ func getObjectTreeConfigV1Beta1 () tablewriter.Config {
126
+ cfg := tablewriter.Config {
127
+ Row : tw.CellConfig {
128
+ Formatting : tw.CellFormatting {AutoWrap : tw .WrapNone },
129
+ Alignment : tw.CellAlignment {Global : tw .AlignLeft },
130
+ Padding : tw.CellPadding {Global : tw.Padding {Left : "" , Right : " " }},
131
+ },
132
+ Header : tw.CellConfig {
133
+ Alignment : tw.CellAlignment {Global : tw .AlignLeft },
134
+ },
135
+ Behavior : tw.Behavior {TrimSpace : tw .Off },
136
+ }
117
137
118
- tbl .SetHeaderLine (false )
119
- tbl .SetBorder (false )
120
- tbl .SetTablePadding (" " )
121
- tbl .SetNoWhiteSpace (true )
138
+ return cfg
122
139
}
123
-
124
140
// addObjectRow add a row for a given object, and recursively for all the object's children.
125
141
// NOTE: each row name gets a prefix, that generates a tree view like representation.
126
142
func addObjectRow (prefix string , tbl * tablewriter.Table , objectTree * tree.ObjectTree , obj ctrlclient.Object ) {
0 commit comments