diff --git a/pkg/printers/tableprinter.go b/pkg/printers/tableprinter.go index 09b75a8cf36..8f6f072aa2f 100644 --- a/pkg/printers/tableprinter.go +++ b/pkg/printers/tableprinter.go @@ -35,8 +35,13 @@ import ( var _ ResourcePrinter = &HumanReadablePrinter{} +type printHandler struct { + columnDefinitions []metav1beta1.TableColumnDefinition + printFunc reflect.Value +} + var ( - statusHandlerEntry = &handlerEntry{ + statusHandlerEntry = &printHandler{ columnDefinitions: statusColumnDefinitions, printFunc: reflect.ValueOf(printStatus), } @@ -47,7 +52,7 @@ var ( {Name: "Message", Type: "string"}, } - defaultHandlerEntry = &handlerEntry{ + defaultHandlerEntry = &printHandler{ columnDefinitions: objectMetaColumnDefinitions, printFunc: reflect.ValueOf(printObjectMeta), } @@ -142,7 +147,7 @@ func (h *HumanReadablePrinter) PrintObj(obj runtime.Object, output io.Writer) er // Could not find print handler for "obj"; use the default or status print handler. // Print with the default or status handler, and use the columns from the last time - var handler *handlerEntry + var handler *printHandler if _, isStatus := obj.(*metav1.Status); isStatus { handler = statusHandlerEntry } else { @@ -380,7 +385,7 @@ func decorateTable(table *metav1beta1.Table, options PrintOptions) error { // printRowsForHandlerEntry prints the incremental table output (headers if the current type is // different from lastType) including all the rows in the object. It returns the current type // or an error, if any. -func printRowsForHandlerEntry(output io.Writer, handler *handlerEntry, eventType string, obj runtime.Object, options PrintOptions, includeHeaders bool) error { +func printRowsForHandlerEntry(output io.Writer, handler *printHandler, eventType string, obj runtime.Object, options PrintOptions, includeHeaders bool) error { var results []reflect.Value args := []reflect.Value{reflect.ValueOf(obj), reflect.ValueOf(options)} diff --git a/pkg/printers/tableprinter_test.go b/pkg/printers/tableprinter_test.go index d89122ec1d5..2e131abeddd 100644 --- a/pkg/printers/tableprinter_test.go +++ b/pkg/printers/tableprinter_test.go @@ -41,7 +41,7 @@ func testPrintNamespace(obj *corev1.Namespace, options PrintOptions) ([]metav1be row := metav1beta1.TableRow{ Object: runtime.RawExtension{Object: obj}, } - row.Cells = append(row.Cells, obj.Name, obj.Status.Phase, "") + row.Cells = append(row.Cells, obj.Name, obj.Status.Phase, "") return []metav1beta1.TableRow{row}, nil } @@ -50,7 +50,7 @@ func TestPrintRowsForHandlerEntry(t *testing.T) { testCase := []struct { name string - h *handlerEntry + h *printHandler opt PrintOptions eventType string obj runtime.Object @@ -60,7 +60,7 @@ func TestPrintRowsForHandlerEntry(t *testing.T) { }{ { name: "no tablecolumndefinition and includeheader flase", - h: &handlerEntry{ + h: &printHandler{ columnDefinitions: []metav1beta1.TableColumnDefinition{}, printFunc: printFunc, }, @@ -69,11 +69,11 @@ func TestPrintRowsForHandlerEntry(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: "test"}, }, includeHeader: false, - expectOut: "test\t\t\n", + expectOut: "test\t\t\n", }, { name: "no tablecolumndefinition and includeheader true", - h: &handlerEntry{ + h: &printHandler{ columnDefinitions: []metav1beta1.TableColumnDefinition{}, printFunc: printFunc, }, @@ -82,11 +82,11 @@ func TestPrintRowsForHandlerEntry(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: "test"}, }, includeHeader: true, - expectOut: "\ntest\t\t\n", + expectOut: "\ntest\t\t\n", }, { name: "have tablecolumndefinition and includeheader true", - h: &handlerEntry{ + h: &printHandler{ columnDefinitions: testNamespaceColumnDefinitions, printFunc: printFunc, }, @@ -95,11 +95,11 @@ func TestPrintRowsForHandlerEntry(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: "test"}, }, includeHeader: true, - expectOut: "NAME\tSTATUS\tAGE\ntest\t\t\n", + expectOut: "NAME\tSTATUS\tAGE\ntest\t\t\n", }, { name: "with event type", - h: &handlerEntry{ + h: &printHandler{ columnDefinitions: testNamespaceColumnDefinitions, printFunc: printFunc, }, @@ -109,11 +109,11 @@ func TestPrintRowsForHandlerEntry(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: "test"}, }, includeHeader: true, - expectOut: "EVENT\tNAME\tSTATUS\tAGE\nADDED \ttest\t\t\n", + expectOut: "EVENT\tNAME\tSTATUS\tAGE\nADDED \ttest\t\t\n", }, { name: "print namespace and withnamespace true, should not print header", - h: &handlerEntry{ + h: &printHandler{ columnDefinitions: testNamespaceColumnDefinitions, printFunc: printFunc, },