mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +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{}
|
var _ ResourcePrinter = &HumanReadablePrinter{}
|
||||||
|
|
||||||
|
type printHandler struct {
|
||||||
|
columnDefinitions []metav1beta1.TableColumnDefinition
|
||||||
|
printFunc reflect.Value
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
statusHandlerEntry = &handlerEntry{
|
statusHandlerEntry = &printHandler{
|
||||||
columnDefinitions: statusColumnDefinitions,
|
columnDefinitions: statusColumnDefinitions,
|
||||||
printFunc: reflect.ValueOf(printStatus),
|
printFunc: reflect.ValueOf(printStatus),
|
||||||
}
|
}
|
||||||
@ -47,7 +52,7 @@ var (
|
|||||||
{Name: "Message", Type: "string"},
|
{Name: "Message", Type: "string"},
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultHandlerEntry = &handlerEntry{
|
defaultHandlerEntry = &printHandler{
|
||||||
columnDefinitions: objectMetaColumnDefinitions,
|
columnDefinitions: objectMetaColumnDefinitions,
|
||||||
printFunc: reflect.ValueOf(printObjectMeta),
|
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.
|
// 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
|
// 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 {
|
if _, isStatus := obj.(*metav1.Status); isStatus {
|
||||||
handler = statusHandlerEntry
|
handler = statusHandlerEntry
|
||||||
} else {
|
} 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
|
// 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
|
// different from lastType) including all the rows in the object. It returns the current type
|
||||||
// or an error, if any.
|
// 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
|
var results []reflect.Value
|
||||||
|
|
||||||
args := []reflect.Value{reflect.ValueOf(obj), reflect.ValueOf(options)}
|
args := []reflect.Value{reflect.ValueOf(obj), reflect.ValueOf(options)}
|
||||||
|
@ -41,7 +41,7 @@ func testPrintNamespace(obj *corev1.Namespace, options PrintOptions) ([]metav1be
|
|||||||
row := metav1beta1.TableRow{
|
row := metav1beta1.TableRow{
|
||||||
Object: runtime.RawExtension{Object: obj},
|
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
|
return []metav1beta1.TableRow{row}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ func TestPrintRowsForHandlerEntry(t *testing.T) {
|
|||||||
|
|
||||||
testCase := []struct {
|
testCase := []struct {
|
||||||
name string
|
name string
|
||||||
h *handlerEntry
|
h *printHandler
|
||||||
opt PrintOptions
|
opt PrintOptions
|
||||||
eventType string
|
eventType string
|
||||||
obj runtime.Object
|
obj runtime.Object
|
||||||
@ -60,7 +60,7 @@ func TestPrintRowsForHandlerEntry(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "no tablecolumndefinition and includeheader flase",
|
name: "no tablecolumndefinition and includeheader flase",
|
||||||
h: &handlerEntry{
|
h: &printHandler{
|
||||||
columnDefinitions: []metav1beta1.TableColumnDefinition{},
|
columnDefinitions: []metav1beta1.TableColumnDefinition{},
|
||||||
printFunc: printFunc,
|
printFunc: printFunc,
|
||||||
},
|
},
|
||||||
@ -69,11 +69,11 @@ func TestPrintRowsForHandlerEntry(t *testing.T) {
|
|||||||
ObjectMeta: metav1.ObjectMeta{Name: "test"},
|
ObjectMeta: metav1.ObjectMeta{Name: "test"},
|
||||||
},
|
},
|
||||||
includeHeader: false,
|
includeHeader: false,
|
||||||
expectOut: "test\t\t<unknow>\n",
|
expectOut: "test\t\t<unknown>\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "no tablecolumndefinition and includeheader true",
|
name: "no tablecolumndefinition and includeheader true",
|
||||||
h: &handlerEntry{
|
h: &printHandler{
|
||||||
columnDefinitions: []metav1beta1.TableColumnDefinition{},
|
columnDefinitions: []metav1beta1.TableColumnDefinition{},
|
||||||
printFunc: printFunc,
|
printFunc: printFunc,
|
||||||
},
|
},
|
||||||
@ -82,11 +82,11 @@ func TestPrintRowsForHandlerEntry(t *testing.T) {
|
|||||||
ObjectMeta: metav1.ObjectMeta{Name: "test"},
|
ObjectMeta: metav1.ObjectMeta{Name: "test"},
|
||||||
},
|
},
|
||||||
includeHeader: true,
|
includeHeader: true,
|
||||||
expectOut: "\ntest\t\t<unknow>\n",
|
expectOut: "\ntest\t\t<unknown>\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "have tablecolumndefinition and includeheader true",
|
name: "have tablecolumndefinition and includeheader true",
|
||||||
h: &handlerEntry{
|
h: &printHandler{
|
||||||
columnDefinitions: testNamespaceColumnDefinitions,
|
columnDefinitions: testNamespaceColumnDefinitions,
|
||||||
printFunc: printFunc,
|
printFunc: printFunc,
|
||||||
},
|
},
|
||||||
@ -95,11 +95,11 @@ func TestPrintRowsForHandlerEntry(t *testing.T) {
|
|||||||
ObjectMeta: metav1.ObjectMeta{Name: "test"},
|
ObjectMeta: metav1.ObjectMeta{Name: "test"},
|
||||||
},
|
},
|
||||||
includeHeader: true,
|
includeHeader: true,
|
||||||
expectOut: "NAME\tSTATUS\tAGE\ntest\t\t<unknow>\n",
|
expectOut: "NAME\tSTATUS\tAGE\ntest\t\t<unknown>\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "with event type",
|
name: "with event type",
|
||||||
h: &handlerEntry{
|
h: &printHandler{
|
||||||
columnDefinitions: testNamespaceColumnDefinitions,
|
columnDefinitions: testNamespaceColumnDefinitions,
|
||||||
printFunc: printFunc,
|
printFunc: printFunc,
|
||||||
},
|
},
|
||||||
@ -109,11 +109,11 @@ func TestPrintRowsForHandlerEntry(t *testing.T) {
|
|||||||
ObjectMeta: metav1.ObjectMeta{Name: "test"},
|
ObjectMeta: metav1.ObjectMeta{Name: "test"},
|
||||||
},
|
},
|
||||||
includeHeader: true,
|
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",
|
name: "print namespace and withnamespace true, should not print header",
|
||||||
h: &handlerEntry{
|
h: &printHandler{
|
||||||
columnDefinitions: testNamespaceColumnDefinitions,
|
columnDefinitions: testNamespaceColumnDefinitions,
|
||||||
printFunc: printFunc,
|
printFunc: printFunc,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user