44package table
55
66import (
7+ "fmt"
8+ "io"
79 "time"
810
911 "k8s.io/cli-runtime/pkg/genericclioptions"
12+ "sigs.k8s.io/cli-utils/cmd/status/printers/printer"
1013 "sigs.k8s.io/cli-utils/pkg/kstatus/polling/collector"
1114 "sigs.k8s.io/cli-utils/pkg/kstatus/polling/event"
1215 "sigs.k8s.io/cli-utils/pkg/object"
@@ -22,12 +25,14 @@ const (
2225// status information about resources in a table format with in-place updates.
2326type Printer struct {
2427 IOStreams genericclioptions.IOStreams
28+ PrintData * printer.PrintData
2529}
2630
2731// NewPrinter returns a new instance of the tablePrinter.
28- func NewPrinter (ioStreams genericclioptions.IOStreams ) * Printer {
32+ func NewPrinter (ioStreams genericclioptions.IOStreams , printData * printer. PrintData ) * Printer {
2933 return & Printer {
3034 IOStreams : ioStreams ,
35+ PrintData : printData ,
3136 }
3237}
3338
@@ -41,7 +46,9 @@ func (t *Printer) Print(ch <-chan event.Event, identifiers object.ObjMetadataSet
4146 // Start the goroutine that is responsible for
4247 // printing the latest state on a regular cadence.
4348 printCompleted := t .runPrintLoop (& CollectorAdapter {
44- collector : coll ,
49+ collector : coll ,
50+ invNameMap : t .PrintData .InvNameMap ,
51+ statusSet : t .PrintData .StatusSet ,
4552 }, stop )
4653
4754 // Make the collector start listening on the eventChannel.
@@ -65,13 +72,28 @@ func (t *Printer) Print(ch <-chan event.Event, identifiers object.ObjMetadataSet
6572 return err
6673}
6774
75+ var invNameColumn = table.ColumnDef {
76+ ColumnName : "inventory_name" ,
77+ ColumnHeader : "INVENTORY_NAME" ,
78+ ColumnWidth : 30 ,
79+ PrintResourceFunc : func (w io.Writer , width int , r table.Resource ) (int , error ) {
80+ group := r .(* ResourceInfo ).invName
81+ if len (group ) > width {
82+ group = group [:width ]
83+ }
84+ _ , err := fmt .Fprint (w , group )
85+ return len (group ), err
86+ },
87+ }
88+
6889var columns = []table.ColumnDefinition {
6990 table .MustColumn ("namespace" ),
7091 table .MustColumn ("resource" ),
7192 table .MustColumn ("status" ),
7293 table .MustColumn ("conditions" ),
7394 table .MustColumn ("age" ),
7495 table .MustColumn ("message" ),
96+ invNameColumn ,
7597}
7698
7799// Print prints the table of resources with their statuses until the
0 commit comments