Merge pull request #64883 from liggitt/legacy-printer

Automatic merge from submit-queue (batch tested with PRs 64285, 63660, 63661, 63662, 64883). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Fix up legacy printer table adapter

As server-side printing is more widespread, downstream consumers will start leaning on this adapter to transform client-side printers to server-side printers.

This PR:
* Set the name format correctly on column 0
* Tolerates case-differences in the column 0 name (many old printers used NAME)
* Set ListMeta continue/resourceVersion/selfLink correctly when adapting a legacy printer

/cc @smarterclayton 

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2018-06-21 01:19:30 -07:00 committed by GitHub
commit 56a2d2f578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 {