mirror of https://github.com/k3s-io/k3s
Merge pull request #63312 from deads2k/cli-44-encoder
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 unnecessary encoder Followups to https://github.com/kubernetes/kubernetes/pull/63105pull/8/head
commit
b52ebfa28e
|
@ -66,7 +66,6 @@ func (f *HumanPrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrint
|
|||
return nil, printers.NoCompatiblePrinterError{Options: f}
|
||||
}
|
||||
|
||||
encoder := scheme.Codecs.LegacyCodec(scheme.Registry.RegisteredGroupVersions()...)
|
||||
decoder := scheme.Codecs.UniversalDecoder()
|
||||
|
||||
showKind := false
|
||||
|
@ -84,7 +83,7 @@ func (f *HumanPrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrint
|
|||
columnLabels = *f.ColumnLabels
|
||||
}
|
||||
|
||||
p := printers.NewHumanReadablePrinter(encoder, decoder, printers.PrintOptions{
|
||||
p := printers.NewHumanReadablePrinter(decoder, printers.PrintOptions{
|
||||
Kind: f.Kind,
|
||||
WithKind: showKind,
|
||||
NoHeaders: f.NoHeaders,
|
||||
|
|
|
@ -296,7 +296,8 @@ func (o *RollingUpdateOptions) Run() error {
|
|||
|
||||
uncastVersionedObj, err := legacyscheme.Scheme.ConvertToVersion(infos[0].Object, v1.SchemeGroupVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
glog.V(4).Infof("Object %T is not a ReplicationController", infos[0].Object)
|
||||
return fmt.Errorf("%s contains a %v not a ReplicationController", filename, infos[0].Object.GetObjectKind().GroupVersionKind())
|
||||
}
|
||||
switch t := uncastVersionedObj.(type) {
|
||||
case *v1.ReplicationController:
|
||||
|
|
|
@ -245,7 +245,7 @@ func SuggestApiResources(parent string) string {
|
|||
func ValidArgList(f ClientAccessFactory) []string {
|
||||
validArgs := []string{}
|
||||
|
||||
humanReadablePrinter := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{})
|
||||
humanReadablePrinter := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{})
|
||||
printersinternal.AddHandlers(humanReadablePrinter)
|
||||
validArgs = humanReadablePrinter.HandledResources()
|
||||
|
||||
|
|
|
@ -71,11 +71,10 @@ var _ PrintHandler = &HumanReadablePrinter{}
|
|||
|
||||
// NewHumanReadablePrinter creates a HumanReadablePrinter.
|
||||
// If encoder and decoder are provided, an attempt to convert unstructured types to internal types is made.
|
||||
func NewHumanReadablePrinter(encoder runtime.Encoder, decoder runtime.Decoder, options PrintOptions) *HumanReadablePrinter {
|
||||
func NewHumanReadablePrinter(decoder runtime.Decoder, options PrintOptions) *HumanReadablePrinter {
|
||||
printer := &HumanReadablePrinter{
|
||||
handlerMap: make(map[reflect.Type]*handlerEntry),
|
||||
options: options,
|
||||
encoder: encoder,
|
||||
decoder: decoder,
|
||||
}
|
||||
return printer
|
||||
|
@ -297,7 +296,7 @@ func (h *HumanReadablePrinter) PrintObj(obj runtime.Object, output io.Writer) er
|
|||
|
||||
// check if the object is unstructured. If so, let's attempt to convert it to a type we can understand before
|
||||
// trying to print, since the printers are keyed by type. This is extremely expensive.
|
||||
if h.encoder != nil && h.decoder != nil {
|
||||
if h.decoder != nil {
|
||||
obj, _ = decodeUnknownObject(obj, h.decoder)
|
||||
}
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ func TestPrintUnstructuredObject(t *testing.T) {
|
|||
|
||||
for _, test := range tests {
|
||||
out.Reset()
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, test.options).With(AddDefaultHandlers)
|
||||
printer := printers.NewHumanReadablePrinter(nil, test.options).With(AddDefaultHandlers)
|
||||
printer.PrintObj(test.object, out)
|
||||
|
||||
matches, err := regexp.MatchString(test.expected, out.String())
|
||||
|
@ -388,7 +388,7 @@ func ErrorPrintHandler(obj *TestPrintType, w io.Writer, options printers.PrintOp
|
|||
|
||||
func TestCustomTypePrinting(t *testing.T) {
|
||||
columns := []string{"Data"}
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{})
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{})
|
||||
printer.Handler(columns, nil, PrintCustomType)
|
||||
|
||||
obj := TestPrintType{"test object"}
|
||||
|
@ -405,7 +405,7 @@ func TestCustomTypePrinting(t *testing.T) {
|
|||
|
||||
func TestPrintHandlerError(t *testing.T) {
|
||||
columns := []string{"Data"}
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{})
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{})
|
||||
printer.Handler(columns, nil, ErrorPrintHandler)
|
||||
obj := TestPrintType{"test object"}
|
||||
buffer := &bytes.Buffer{}
|
||||
|
@ -416,7 +416,7 @@ func TestPrintHandlerError(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUnknownTypePrinting(t *testing.T) {
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{})
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{})
|
||||
buffer := &bytes.Buffer{}
|
||||
err := printer.PrintObj(&TestUnknownType{}, buffer)
|
||||
if err == nil {
|
||||
|
@ -635,10 +635,10 @@ func TestPrinters(t *testing.T) {
|
|||
jsonpathPrinter = printers.NewVersionedPrinter(jsonpathPrinter, legacyscheme.Scheme, legacyscheme.Scheme, v1.SchemeGroupVersion)
|
||||
|
||||
allPrinters := map[string]printers.ResourcePrinter{
|
||||
"humanReadable": printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
|
||||
"humanReadable": printers.NewHumanReadablePrinter(nil, printers.PrintOptions{
|
||||
NoHeaders: true,
|
||||
}),
|
||||
"humanReadableHeaders": printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{}),
|
||||
"humanReadableHeaders": printers.NewHumanReadablePrinter(nil, printers.PrintOptions{}),
|
||||
"json": &printers.JSONPrinter{},
|
||||
"yaml": &printers.YAMLPrinter{},
|
||||
"template": templatePrinter,
|
||||
|
@ -683,7 +683,7 @@ func TestPrinters(t *testing.T) {
|
|||
|
||||
func TestPrintEventsResultSorted(t *testing.T) {
|
||||
// Arrange
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{})
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{})
|
||||
AddHandlers(printer)
|
||||
|
||||
obj := api.EventList{
|
||||
|
@ -728,7 +728,7 @@ func TestPrintEventsResultSorted(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrintNodeStatus(t *testing.T) {
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{})
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{})
|
||||
AddHandlers(printer)
|
||||
table := []struct {
|
||||
node api.Node
|
||||
|
@ -818,7 +818,7 @@ func TestPrintNodeStatus(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrintNodeRole(t *testing.T) {
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{})
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{})
|
||||
AddHandlers(printer)
|
||||
table := []struct {
|
||||
node api.Node
|
||||
|
@ -863,7 +863,7 @@ func TestPrintNodeRole(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrintNodeOSImage(t *testing.T) {
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{
|
||||
ColumnLabels: []string{},
|
||||
Wide: true,
|
||||
})
|
||||
|
@ -908,7 +908,7 @@ func TestPrintNodeOSImage(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrintNodeKernelVersion(t *testing.T) {
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{
|
||||
ColumnLabels: []string{},
|
||||
Wide: true,
|
||||
})
|
||||
|
@ -953,7 +953,7 @@ func TestPrintNodeKernelVersion(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrintNodeContainerRuntimeVersion(t *testing.T) {
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{
|
||||
ColumnLabels: []string{},
|
||||
Wide: true,
|
||||
})
|
||||
|
@ -998,7 +998,7 @@ func TestPrintNodeContainerRuntimeVersion(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrintNodeName(t *testing.T) {
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{
|
||||
Wide: true,
|
||||
})
|
||||
AddHandlers(printer)
|
||||
|
@ -1035,7 +1035,7 @@ func TestPrintNodeName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrintNodeExternalIP(t *testing.T) {
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{
|
||||
Wide: true,
|
||||
})
|
||||
AddHandlers(printer)
|
||||
|
@ -1083,7 +1083,7 @@ func TestPrintNodeExternalIP(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrintNodeInternalIP(t *testing.T) {
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{
|
||||
Wide: true,
|
||||
})
|
||||
AddHandlers(printer)
|
||||
|
@ -1485,7 +1485,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
|
|||
for i, test := range table {
|
||||
if test.isNamespaced {
|
||||
// Expect output to include namespace when requested.
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{
|
||||
WithNamespace: true,
|
||||
})
|
||||
AddHandlers(printer)
|
||||
|
@ -1500,7 +1500,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
|
|||
}
|
||||
} else {
|
||||
// Expect error when trying to get all namespaces for un-namespaced object.
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
|
||||
printer := printers.NewHumanReadablePrinter(nil, printers.PrintOptions{
|
||||
WithNamespace: true,
|
||||
})
|
||||
buffer := &bytes.Buffer{}
|
||||
|
@ -1578,7 +1578,7 @@ func TestPrintPodTable(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
buf := &bytes.Buffer{}
|
||||
p := printers.NewHumanReadablePrinter(nil, nil, test.opts).With(AddHandlers).AddTabWriter(false)
|
||||
p := printers.NewHumanReadablePrinter(nil, test.opts).With(AddHandlers).AddTabWriter(false)
|
||||
if err := p.PrintObj(table, buf); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue