From a8b7c94620f055a478fe352b6158c6b321478921 Mon Sep 17 00:00:00 2001 From: Mike Dame Date: Tue, 12 Jun 2018 13:50:47 -0400 Subject: [PATCH] marshal bytes to return as string with `kubectl config view -o jsonpath` --- pkg/printers/jsonpath.go | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/pkg/printers/jsonpath.go b/pkg/printers/jsonpath.go index b8ea553f513..1e2e7b303c8 100644 --- a/pkg/printers/jsonpath.go +++ b/pkg/printers/jsonpath.go @@ -22,7 +22,6 @@ import ( "io" "reflect" - "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/util/jsonpath" "k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers" @@ -124,7 +123,9 @@ func (j *JSONPathPrinter) PrintObj(obj runtime.Object, w io.Writer) error { } var queryObj interface{} = obj - if meta.IsListType(obj) { + if unstructured, ok := obj.(runtime.Unstructured); ok { + queryObj = unstructured.UnstructuredContent() + } else { data, err := json.Marshal(obj) if err != nil { return err @@ -135,20 +136,6 @@ func (j *JSONPathPrinter) PrintObj(obj runtime.Object, w io.Writer) error { } } - if unknown, ok := obj.(*runtime.Unknown); ok { - data, err := json.Marshal(unknown) - if err != nil { - return err - } - queryObj = map[string]interface{}{} - if err := json.Unmarshal(data, &queryObj); err != nil { - return err - } - } - if unstructured, ok := obj.(runtime.Unstructured); ok { - queryObj = unstructured.UnstructuredContent() - } - if err := j.JSONPath.Execute(w, queryObj); err != nil { fmt.Fprintf(w, "Error executing template: %v. Printing more information for debugging the template:\n", err) fmt.Fprintf(w, "\ttemplate was:\n\t\t%v\n", j.rawTemplate)