mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Merge pull request #53560 from dixudx/sort_kubectl_top_metrics
Automatic merge from submit-queue (batch tested with PRs 53565, 53560). 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>. sort top pod and top node output by namespace/name **What this PR does / why we need it**: **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #53513 **Special notes for your reviewer**: /assign @smarterclayton **Release note**: ```release-note kubectl top pod and node should sort by namespace / name so that results don't jump around. ```
This commit is contained in:
commit
50377e88ea
@ -19,6 +19,7 @@ package metricsutil
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"sort"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
@ -58,6 +59,10 @@ func (printer *TopCmdPrinter) PrintNodeMetrics(metrics []metricsapi.NodeMetrics,
|
||||
w := printers.GetNewTabWriter(printer.out)
|
||||
defer w.Flush()
|
||||
|
||||
sort.Slice(metrics, func(i, j int) bool {
|
||||
return metrics[i].Name < metrics[j].Name
|
||||
})
|
||||
|
||||
printColumnNames(w, NodeColumns)
|
||||
var usage api.ResourceList
|
||||
for _, m := range metrics {
|
||||
@ -87,6 +92,14 @@ func (printer *TopCmdPrinter) PrintPodMetrics(metrics []metricsapi.PodMetrics, p
|
||||
if printContainers {
|
||||
printValue(w, PodColumn)
|
||||
}
|
||||
|
||||
sort.Slice(metrics, func(i, j int) bool {
|
||||
if withNamespace && metrics[i].Namespace != metrics[j].Namespace {
|
||||
return metrics[i].Namespace < metrics[j].Namespace
|
||||
}
|
||||
return metrics[i].Name < metrics[j].Name
|
||||
})
|
||||
|
||||
printColumnNames(w, PodColumns)
|
||||
for _, m := range metrics {
|
||||
err := printSinglePodMetrics(w, &m, printContainers, withNamespace)
|
||||
|
Loading…
Reference in New Issue
Block a user