Fix up legacy printer table adapter

This commit is contained in:
Jordan Liggitt 2018-06-07 13:20:04 -04:00
parent f54593b740
commit 86c2158bb0
No known key found for this signature in database
GPG Key ID: 39928704103C7229
2 changed files with 22 additions and 7 deletions

View File

@ -114,17 +114,25 @@ func (h *HumanReadablePrinter) EnsurePrintHeaders() {
// See ValidatePrintHandlerFunc for required method signature.
func (h *HumanReadablePrinter) Handler(columns, columnsWithWide []string, printFunc interface{}) error {
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{
Name: column,
Type: "string",
Name: column,
Description: column,
Type: "string",
Format: format,
})
}
for _, column := range columnsWithWide {
columnDefinitions = append(columnDefinitions, metav1beta1.TableColumnDefinition{
Name: column,
Type: "string",
Priority: 1,
Name: column,
Description: column,
Type: "string",
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)}
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
// for this.
args[0] = reflect.ValueOf(obj)

View File

@ -1312,7 +1312,7 @@ func (t *Tester) testListTableConversion(obj runtime.Object, assignFn AssignFunc
if len(columns) == 0 {
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])
}
for j, column := range columns {