mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Fix up legacy printer table adapter
This commit is contained in:
parent
f54593b740
commit
86c2158bb0
@ -114,15 +114,23 @@ func (h *HumanReadablePrinter) EnsurePrintHeaders() {
|
|||||||
// See ValidatePrintHandlerFunc for required method signature.
|
// See ValidatePrintHandlerFunc for required method signature.
|
||||||
func (h *HumanReadablePrinter) Handler(columns, columnsWithWide []string, printFunc interface{}) error {
|
func (h *HumanReadablePrinter) Handler(columns, columnsWithWide []string, printFunc interface{}) error {
|
||||||
var columnDefinitions []metav1beta1.TableColumnDefinition
|
var columnDefinitions []metav1beta1.TableColumnDefinition
|
||||||
for _, column := range columns {
|
for i, column := range columns {
|
||||||
|
format := ""
|
||||||
|
if i == 0 && strings.EqualFold(column, "name") {
|
||||||
|
format = "name"
|
||||||
|
}
|
||||||
|
|
||||||
columnDefinitions = append(columnDefinitions, metav1beta1.TableColumnDefinition{
|
columnDefinitions = append(columnDefinitions, metav1beta1.TableColumnDefinition{
|
||||||
Name: column,
|
Name: column,
|
||||||
|
Description: column,
|
||||||
Type: "string",
|
Type: "string",
|
||||||
|
Format: format,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for _, column := range columnsWithWide {
|
for _, column := range columnsWithWide {
|
||||||
columnDefinitions = append(columnDefinitions, metav1beta1.TableColumnDefinition{
|
columnDefinitions = append(columnDefinitions, metav1beta1.TableColumnDefinition{
|
||||||
Name: column,
|
Name: column,
|
||||||
|
Description: column,
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Priority: 1,
|
Priority: 1,
|
||||||
})
|
})
|
||||||
@ -631,6 +639,13 @@ func (h *HumanReadablePrinter) legacyPrinterToTable(obj runtime.Object, handler
|
|||||||
args := []reflect.Value{reflect.ValueOf(obj), reflect.ValueOf(buf), reflect.ValueOf(options)}
|
args := []reflect.Value{reflect.ValueOf(obj), reflect.ValueOf(buf), reflect.ValueOf(options)}
|
||||||
|
|
||||||
if meta.IsListType(obj) {
|
if meta.IsListType(obj) {
|
||||||
|
listInterface, ok := obj.(metav1.ListInterface)
|
||||||
|
if ok {
|
||||||
|
table.ListMeta.SelfLink = listInterface.GetSelfLink()
|
||||||
|
table.ListMeta.ResourceVersion = listInterface.GetResourceVersion()
|
||||||
|
table.ListMeta.Continue = listInterface.GetContinue()
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: this uses more memory than it has to, as we refactor printers we should remove the need
|
// TODO: this uses more memory than it has to, as we refactor printers we should remove the need
|
||||||
// for this.
|
// for this.
|
||||||
args[0] = reflect.ValueOf(obj)
|
args[0] = reflect.ValueOf(obj)
|
||||||
|
@ -1312,7 +1312,7 @@ func (t *Tester) testListTableConversion(obj runtime.Object, assignFn AssignFunc
|
|||||||
if len(columns) == 0 {
|
if len(columns) == 0 {
|
||||||
t.Errorf("unexpected number of columns: %v", len(columns))
|
t.Errorf("unexpected number of columns: %v", len(columns))
|
||||||
}
|
}
|
||||||
if columns[0].Name != "Name" || columns[0].Type != "string" || columns[0].Format != "name" {
|
if !strings.EqualFold(columns[0].Name, "Name") || columns[0].Type != "string" || columns[0].Format != "name" {
|
||||||
t.Errorf("expect column 0 to be the name column: %#v", columns[0])
|
t.Errorf("expect column 0 to be the name column: %#v", columns[0])
|
||||||
}
|
}
|
||||||
for j, column := range columns {
|
for j, column := range columns {
|
||||||
|
Loading…
Reference in New Issue
Block a user