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

Merge pull request #64389 from yue9944882/top-nodes-print-missing-metrics

Automatic merge from submit-queue (batch tested with PRs 64882, 64692, 64389, 60626, 64840). 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>. print nodes for those metrics is somehow unreachable **What this PR does / why we need it**: When we use `kubectl top nodes`, some nodes will be ignored when their metrics cannot be fetched from metrics serve. It might be misleading for users. This PR helps print the missing nodes like: ``` NAME CPU(cores) CPU% MEMORY(bytes) MEMORY% missing-nodes - - - - ``` **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #63986 **Special notes for your reviewer**: **Release note**: ```release-note Fixes missing nodes lines when kubectl top nodes ```
parents bb6270bd 64ec4009
...@@ -76,6 +76,12 @@ func (printer *TopCmdPrinter) PrintNodeMetrics(metrics []metricsapi.NodeMetrics, ...@@ -76,6 +76,12 @@ func (printer *TopCmdPrinter) PrintNodeMetrics(metrics []metricsapi.NodeMetrics,
Metrics: usage, Metrics: usage,
Available: availableResources[m.Name], Available: availableResources[m.Name],
}) })
delete(availableResources, m.Name)
}
// print lines for nodes of which the metrics is unreachable.
for nodeName := range availableResources {
printMissingMetricsNodeLine(w, nodeName)
} }
return nil return nil
} }
...@@ -171,6 +177,18 @@ func printMetricsLine(out io.Writer, metrics *ResourceMetricsInfo) { ...@@ -171,6 +177,18 @@ func printMetricsLine(out io.Writer, metrics *ResourceMetricsInfo) {
fmt.Fprint(out, "\n") fmt.Fprint(out, "\n")
} }
func printMissingMetricsNodeLine(out io.Writer, nodeName string) {
printValue(out, nodeName)
unknownMetricsStatus := "<unknown>"
for i := 0; i < len(MeasuredResources); i++ {
printValue(out, unknownMetricsStatus)
printValue(out, "\t")
printValue(out, unknownMetricsStatus)
printValue(out, "\t")
}
fmt.Fprint(out, "\n")
}
func printValue(out io.Writer, value interface{}) { func printValue(out io.Writer, value interface{}) {
fmt.Fprintf(out, "%v\t", value) fmt.Fprintf(out, "%v\t", value)
} }
......
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