add flag --no-headers
to kubectl top ...
This commit is contained in:
@@ -53,7 +53,7 @@ func NewTopCmdPrinter(out io.Writer) *TopCmdPrinter {
|
||||
return &TopCmdPrinter{out: out}
|
||||
}
|
||||
|
||||
func (printer *TopCmdPrinter) PrintNodeMetrics(metrics []metricsapi.NodeMetrics, availableResources map[string]v1.ResourceList) error {
|
||||
func (printer *TopCmdPrinter) PrintNodeMetrics(metrics []metricsapi.NodeMetrics, availableResources map[string]v1.ResourceList, noHeaders bool) error {
|
||||
if len(metrics) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -63,8 +63,9 @@ func (printer *TopCmdPrinter) PrintNodeMetrics(metrics []metricsapi.NodeMetrics,
|
||||
sort.Slice(metrics, func(i, j int) bool {
|
||||
return metrics[i].Name < metrics[j].Name
|
||||
})
|
||||
|
||||
printColumnNames(w, NodeColumns)
|
||||
if !noHeaders {
|
||||
printColumnNames(w, NodeColumns)
|
||||
}
|
||||
var usage v1.ResourceList
|
||||
for _, m := range metrics {
|
||||
err := scheme.Scheme.Convert(&m.Usage, &usage, nil)
|
||||
@@ -86,18 +87,20 @@ func (printer *TopCmdPrinter) PrintNodeMetrics(metrics []metricsapi.NodeMetrics,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (printer *TopCmdPrinter) PrintPodMetrics(metrics []metricsapi.PodMetrics, printContainers bool, withNamespace bool) error {
|
||||
func (printer *TopCmdPrinter) PrintPodMetrics(metrics []metricsapi.PodMetrics, printContainers bool, withNamespace bool, noHeaders bool) error {
|
||||
if len(metrics) == 0 {
|
||||
return nil
|
||||
}
|
||||
w := printers.GetNewTabWriter(printer.out)
|
||||
defer w.Flush()
|
||||
|
||||
if withNamespace {
|
||||
printValue(w, NamespaceColumn)
|
||||
}
|
||||
if printContainers {
|
||||
printValue(w, PodColumn)
|
||||
if !noHeaders {
|
||||
if withNamespace {
|
||||
printValue(w, NamespaceColumn)
|
||||
}
|
||||
if printContainers {
|
||||
printValue(w, PodColumn)
|
||||
}
|
||||
printColumnNames(w, PodColumns)
|
||||
}
|
||||
|
||||
sort.Slice(metrics, func(i, j int) bool {
|
||||
@@ -106,8 +109,6 @@ func (printer *TopCmdPrinter) PrintPodMetrics(metrics []metricsapi.PodMetrics, p
|
||||
}
|
||||
return metrics[i].Name < metrics[j].Name
|
||||
})
|
||||
|
||||
printColumnNames(w, PodColumns)
|
||||
for _, m := range metrics {
|
||||
err := printSinglePodMetrics(w, &m, printContainers, withNamespace)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user