From ec02f7b282e127b6f8c1a8ba8c933d24cbec1e7c Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Tue, 24 Oct 2017 11:43:06 -0400 Subject: [PATCH] UPSTREAM: 51750: output `` for colums not found --- .../kubernetes/pkg/printers/customcolumn.go | 6 +++--- .../pkg/printers/customcolumn_test.go | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/vendor/k8s.io/kubernetes/pkg/printers/customcolumn.go b/vendor/k8s.io/kubernetes/pkg/printers/customcolumn.go index eec16ea18aa1..bba5bc4ced58 100644 --- a/vendor/k8s.io/kubernetes/pkg/printers/customcolumn.go +++ b/vendor/k8s.io/kubernetes/pkg/printers/customcolumn.go @@ -176,7 +176,7 @@ func (s *CustomColumnsPrinter) PrintObj(obj runtime.Object, out io.Writer) error } parsers := make([]*jsonpath.JSONPath, len(s.Columns)) for ix := range s.Columns { - parsers[ix] = jsonpath.New(fmt.Sprintf("column%d", ix)) + parsers[ix] = jsonpath.New(fmt.Sprintf("column%d", ix)).AllowMissingKeys(true) if err := parsers[ix].Parse(s.Columns[ix].FieldSpec); err != nil { return err } @@ -226,10 +226,10 @@ func (s *CustomColumnsPrinter) printOneObject(obj runtime.Object, parsers []*jso if err != nil { return err } + valueStrings := []string{} if len(values) == 0 || len(values[0]) == 0 { - fmt.Fprintf(out, "\t") + valueStrings = append(valueStrings, "") } - valueStrings := []string{} for arrIx := range values { for valIx := range values[arrIx] { valueStrings = append(valueStrings, fmt.Sprintf("%v", values[arrIx][valIx].Interface())) diff --git a/vendor/k8s.io/kubernetes/pkg/printers/customcolumn_test.go b/vendor/k8s.io/kubernetes/pkg/printers/customcolumn_test.go index dc1e72101c45..94f915c0d9f3 100644 --- a/vendor/k8s.io/kubernetes/pkg/printers/customcolumn_test.go +++ b/vendor/k8s.io/kubernetes/pkg/printers/customcolumn_test.go @@ -284,6 +284,26 @@ bar obj: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}, TypeMeta: metav1.TypeMeta{APIVersion: "baz"}}, expectedOutput: `NAME API_VERSION foo baz +`, + }, + { + columns: []printers.Column{ + { + Header: "NAME", + FieldSpec: "{.metadata.name}", + }, + { + Header: "API_VERSION", + FieldSpec: "{.apiVersion}", + }, + { + Header: "NOT_FOUND", + FieldSpec: "{.notFound}", + }, + }, + obj: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}, TypeMeta: metav1.TypeMeta{APIVersion: "baz"}}, + expectedOutput: `NAME API_VERSION NOT_FOUND +foo baz `, }, }