mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 15:05:20 +00:00
fix sort-by output problem
This commit is contained in:
@@ -32,7 +32,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubectl/plugins"
|
||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||
"k8s.io/kubernetes/pkg/printers"
|
||||
printersinternal "k8s.io/kubernetes/pkg/printers/internalversion"
|
||||
)
|
||||
|
||||
type ring2Factory struct {
|
||||
@@ -103,16 +102,6 @@ func (f *ring2Factory) PrinterForMapping(cmd *cobra.Command, isLocal bool, outpu
|
||||
|
||||
printer = printers.NewVersionedPrinter(printer, mapping.ObjectConvertor, version, mapping.GroupVersionKind.GroupVersion())
|
||||
|
||||
} else {
|
||||
// We add handlers to the printer in case it is printers.HumanReadablePrinter.
|
||||
// printers.AddHandlers expects concrete type of printers.HumanReadablePrinter
|
||||
// as its parameter because of this we have to do a type check on printer and
|
||||
// extract out concrete HumanReadablePrinter from it. We are then able to attach
|
||||
// handlers on it.
|
||||
if humanReadablePrinter, ok := printer.(*printers.HumanReadablePrinter); ok {
|
||||
printersinternal.AddHandlers(humanReadablePrinter)
|
||||
printer = humanReadablePrinter
|
||||
}
|
||||
}
|
||||
|
||||
return printer, nil
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubectl"
|
||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||
"k8s.io/kubernetes/pkg/printers"
|
||||
printersinternal "k8s.io/kubernetes/pkg/printers/internalversion"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -126,6 +127,13 @@ func PrinterForCommand(cmd *cobra.Command, outputOpts *printers.OutputOptions, m
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// we try to convert to HumanReadablePrinter, if return ok, it must be no generic
|
||||
// we execute AddHandlers() here before maybeWrapSortingPrinter so that we don't
|
||||
// need to convert to delegatePrinter again then invoke AddHandlers()
|
||||
if humanReadablePrinter, ok := printer.(*printers.HumanReadablePrinter); ok {
|
||||
printersinternal.AddHandlers(humanReadablePrinter)
|
||||
}
|
||||
|
||||
return maybeWrapSortingPrinter(cmd, printer), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user