Skip to content

Commit

Permalink
chore: export table & event printer for extension
Browse files Browse the repository at this point in the history
  • Loading branch information
karlkfi committed Feb 15, 2022
1 parent 6ce2c31 commit 280f3e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
20 changes: 10 additions & 10 deletions cmd/status/printers/event/event_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ import (
"sigs.k8s.io/cli-utils/pkg/object"
)

// eventPrinter implements the Printer interface and outputs the resource
// EventPrinter implements the Printer interface and outputs the resource
// status information as a list of events as they happen.
type eventPrinter struct {
ioStreams genericclioptions.IOStreams
type EventPrinter struct {
IOStreams genericclioptions.IOStreams
}

// NewEventPrinter returns a new instance of the eventPrinter.
func NewEventPrinter(ioStreams genericclioptions.IOStreams) *eventPrinter {
return &eventPrinter{
ioStreams: ioStreams,
func NewEventPrinter(ioStreams genericclioptions.IOStreams) *EventPrinter {
return &EventPrinter{
IOStreams: ioStreams,
}
}

// Print takes an event channel and outputs the status events on the channel
// until the channel is closed. The provided cancelFunc is consulted on
// every event and is responsible for stopping the poller when appropriate.
// This function will block.
func (ep *eventPrinter) Print(ch <-chan pollevent.Event, identifiers object.ObjMetadataSet,
func (ep *EventPrinter) Print(ch <-chan pollevent.Event, identifiers object.ObjMetadataSet,
cancelFunc collector.ObserverFunc) error {
coll := collector.NewResourceStatusCollector(identifiers)
// The actual work is done by the collector, which will invoke the
Expand All @@ -52,15 +52,15 @@ func (ep *eventPrinter) Print(ch <-chan pollevent.Event, identifiers object.ObjM
return err
}

func (ep *eventPrinter) printStatusEvent(se pollevent.Event) {
func (ep *EventPrinter) printStatusEvent(se pollevent.Event) {
switch se.Type {
case pollevent.ResourceUpdateEvent:
id := se.Resource.Identifier
printResourceStatus(id, se, ep.ioStreams)
printResourceStatus(id, se, ep.IOStreams)
case pollevent.ErrorEvent:
id := se.Resource.Identifier
gk := id.GroupKind
fmt.Fprintf(ep.ioStreams.Out, "%s error: %s\n", resourceIDToString(gk, id.Name),
fmt.Fprintf(ep.IOStreams.Out, "%s error: %s\n", resourceIDToString(gk, id.Name),
se.Error.Error())
}
}
Expand Down
18 changes: 9 additions & 9 deletions cmd/status/printers/table/table_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ const (
updateInterval = 1 * time.Second
)

// tablePrinter is an implementation of the Printer interface that outputs
// TablePrinter is an implementation of the Printer interface that outputs
// status information about resources in a table format with in-place updates.
type tablePrinter struct {
ioStreams genericclioptions.IOStreams
type TablePrinter struct {
IOStreams genericclioptions.IOStreams
}

// NewTablePrinter returns a new instance of the tablePrinter.
func NewTablePrinter(ioStreams genericclioptions.IOStreams) *tablePrinter {
return &tablePrinter{
ioStreams: ioStreams,
func NewTablePrinter(ioStreams genericclioptions.IOStreams) *TablePrinter {
return &TablePrinter{
IOStreams: ioStreams,
}
}

// Print take an event channel and outputs the status events on the channel
// until the channel is closed .
func (t *tablePrinter) Print(ch <-chan event.Event, identifiers object.ObjMetadataSet,
func (t *TablePrinter) Print(ch <-chan event.Event, identifiers object.ObjMetadataSet,
cancelFunc collector.ObserverFunc) error {
coll := collector.NewResourceStatusCollector(identifiers)
stop := make(chan struct{})
Expand Down Expand Up @@ -76,11 +76,11 @@ var columns = []table.ColumnDefinition{

// Print prints the table of resources with their statuses until the
// provided stop channel is closed.
func (t *tablePrinter) runPrintLoop(coll *CollectorAdapter, stop <-chan struct{}) <-chan struct{} {
func (t *TablePrinter) runPrintLoop(coll *CollectorAdapter, stop <-chan struct{}) <-chan struct{} {
finished := make(chan struct{})

baseTablePrinter := table.BaseTablePrinter{
IOStreams: t.ioStreams,
IOStreams: t.IOStreams,
Columns: columns,
}

Expand Down

0 comments on commit 280f3e2

Please sign in to comment.