Merge pull request #70740 from mfpierre/fix-kubectl-get-sort-out-of-range

Fix index out of range error when sorting kubectl get
pull/58/head
k8s-ci-robot 2018-11-24 12:19:06 -08:00 committed by GitHub
commit 1e50c57113
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -314,11 +314,14 @@ type RuntimeSorter struct {
}
func (r *RuntimeSorter) Sort() error {
if len(r.objects) <= 1 {
// a list is only considered "sorted" if there are 0 or 1 items in it
// AND (if 1 item) the item is not a Table object
// a list is only considered "sorted" if there are 0 or 1 items in it
// AND (if 1 item) the item is not a Table object
if len(r.objects) == 0 {
return nil
}
if len(r.objects) == 1 {
_, isTable := r.objects[0].(*metav1beta1.Table)
if len(r.objects) == 0 || !isTable {
if !isTable {
return nil
}
}

View File

@ -560,6 +560,15 @@ func TestRuntimeSorter(t *testing.T) {
expect string
expectError string
}{
{
name: "ensure sorter works with an empty object list",
field: "metadata.name",
objs: []runtime.Object{},
op: func(sorter *RuntimeSorter, objs []runtime.Object, out io.Writer) error {
return nil
},
expect: "",
},
{
name: "ensure sorter returns original position",
field: "metadata.name",