mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 18:02:01 +00:00
Merge pull request #81848 from seans3/split-handler-entry
Split defaultPrintHandler from handlerEntry in table printing
This commit is contained in:
commit
28e800245e
@ -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)}
|
||||
|
@ -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, "<unknow>")
|
||||
row.Cells = append(row.Cells, obj.Name, obj.Status.Phase, "<unknown>")
|
||||
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<unknow>\n",
|
||||
expectOut: "test\t\t<unknown>\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<unknow>\n",
|
||||
expectOut: "\ntest\t\t<unknown>\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<unknow>\n",
|
||||
expectOut: "NAME\tSTATUS\tAGE\ntest\t\t<unknown>\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<unknow>\n",
|
||||
expectOut: "EVENT\tNAME\tSTATUS\tAGE\nADDED \ttest\t\t<unknown>\n",
|
||||
},
|
||||
{
|
||||
name: "print namespace and withnamespace true, should not print header",
|
||||
h: &handlerEntry{
|
||||
h: &printHandler{
|
||||
columnDefinitions: testNamespaceColumnDefinitions,
|
||||
printFunc: printFunc,
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user