Unverified Commit b0214c13 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #63728 from deads2k/cli-57-remove-decoder

Automatic merge from submit-queue. 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>. remove decoder from name printing The extra decoding step inside of name printing isn't useful. It's only current utility is when the content inside of the list is a runtime.Unknown. However, when you're making use of this printer in a CLI, you've read the content in via a builder or a scheme directly. You would logically set this decoder based on that same scheme. If you were unable to decode using the scheme before, you'll simple be unable to do it again here. Near as I can tell, this would only be useful if objects weren't decoded before printing. There is a unit test that ensures this remains. I'd like to see if any practical tests (cmd, e2e) rely on it. @smarterclayton @liggitt not many people would have written it to begin with. One of you? @kubernetes/sig-cli-maintainers ```release-note NONE ```
parents f4e909d6 dfa5bfd3
...@@ -40,7 +40,6 @@ go_library( ...@@ -40,7 +40,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library", "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
"//vendor/k8s.io/client-go/util/jsonpath:go_default_library", "//vendor/k8s.io/client-go/util/jsonpath:go_default_library",
], ],
......
...@@ -390,10 +390,25 @@ func TestNamePrinter(t *testing.T) { ...@@ -390,10 +390,25 @@ func TestNamePrinter(t *testing.T) {
}, },
Items: []runtime.RawExtension{ Items: []runtime.RawExtension{
{ {
Raw: []byte(`{"kind": "Pod", "apiVersion": "v1", "metadata": { "name": "foo"}}`), Object: &v1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
},
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
},
},
}, },
{ {
Raw: []byte(`{"kind": "Pod", "apiVersion": "v1", "metadata": { "name": "bar"}}`), Object: &unstructured.Unstructured{
Object: map[string]interface{}{
"kind": "Pod",
"apiVersion": "v1",
"metadata": map[string]interface{}{
"name": "bar",
},
},
},
}, },
}, },
}, },
...@@ -574,8 +589,7 @@ func TestPrinters(t *testing.T) { ...@@ -574,8 +589,7 @@ func TestPrinters(t *testing.T) {
"template2": templatePrinter2, "template2": templatePrinter2,
"jsonpath": jsonpathPrinter, "jsonpath": jsonpathPrinter,
"name": &printers.NamePrinter{ "name": &printers.NamePrinter{
Typer: legacyscheme.Scheme, Typer: legacyscheme.Scheme,
Decoders: []runtime.Decoder{legacyscheme.Codecs.UniversalDecoder(), unstructured.UnstructuredJSONScheme},
}, },
} }
objects := map[string]runtime.Object{ objects := map[string]runtime.Object{
......
...@@ -26,7 +26,6 @@ import ( ...@@ -26,7 +26,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
) )
// NamePrinter is an implementation of ResourcePrinter which outputs "resource/name" pair of an object. // NamePrinter is an implementation of ResourcePrinter which outputs "resource/name" pair of an object.
...@@ -39,8 +38,7 @@ type NamePrinter struct { ...@@ -39,8 +38,7 @@ type NamePrinter struct {
// finalized "successful" message. // finalized "successful" message.
Operation string Operation string
Decoders []runtime.Decoder Typer runtime.ObjectTyper
Typer runtime.ObjectTyper
} }
// PrintObj is an implementation of ResourcePrinter.PrintObj which decodes the object // PrintObj is an implementation of ResourcePrinter.PrintObj which decodes the object
...@@ -58,9 +56,6 @@ func (p *NamePrinter) PrintObj(obj runtime.Object, w io.Writer) error { ...@@ -58,9 +56,6 @@ func (p *NamePrinter) PrintObj(obj runtime.Object, w io.Writer) error {
if err != nil { if err != nil {
return err return err
} }
if errs := runtime.DecodeList(items, p.Decoders...); len(errs) > 0 {
return utilerrors.NewAggregate(errs)
}
for _, obj := range items { for _, obj := range items {
if err := p.PrintObj(obj, w); err != nil { if err := p.PrintObj(obj, w); err != nil {
return err return err
......
...@@ -22,7 +22,6 @@ import ( ...@@ -22,7 +22,6 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/kubectl/scheme" "k8s.io/kubernetes/pkg/kubectl/scheme"
...@@ -50,11 +49,9 @@ func (f *NamePrintFlags) Complete(successTemplate string) error { ...@@ -50,11 +49,9 @@ func (f *NamePrintFlags) Complete(successTemplate string) error {
// Returns false if the specified outputFormat does not match a supported format. // Returns false if the specified outputFormat does not match a supported format.
// Supported format types can be found in pkg/printers/printers.go // Supported format types can be found in pkg/printers/printers.go
func (f *NamePrintFlags) ToPrinter(outputFormat string) (ResourcePrinter, error) { func (f *NamePrintFlags) ToPrinter(outputFormat string) (ResourcePrinter, error) {
decoders := []runtime.Decoder{scheme.Codecs.UniversalDecoder(), unstructured.UnstructuredJSONScheme}
namePrinter := &NamePrinter{ namePrinter := &NamePrinter{
Operation: f.Operation, Operation: f.Operation,
Typer: scheme.Scheme, Typer: scheme.Scheme,
Decoders: decoders,
} }
outputFormat = strings.ToLower(outputFormat) outputFormat = strings.ToLower(outputFormat)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment