mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 08:17:26 +00:00
Merge pull request #59309 from zhangxiaoyu-zidif/fix-node-describe
Automatic merge from submit-queue (batch tested with PRs 59539, 59309). 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>. fix describe when allocatable CPU/Memory is 0 **What this PR does / why we need it**: **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 # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
6827c3cf47
@ -2917,10 +2917,18 @@ func describeNodeResource(nodeNonTerminatedPodsList *api.PodList, node *api.Node
|
|||||||
w.Write(LEVEL_1, "------------\t----------\t---------------\t-------------\n")
|
w.Write(LEVEL_1, "------------\t----------\t---------------\t-------------\n")
|
||||||
reqs, limits := getPodsTotalRequestsAndLimits(nodeNonTerminatedPodsList)
|
reqs, limits := getPodsTotalRequestsAndLimits(nodeNonTerminatedPodsList)
|
||||||
cpuReqs, cpuLimits, memoryReqs, memoryLimits := reqs[api.ResourceCPU], limits[api.ResourceCPU], reqs[api.ResourceMemory], limits[api.ResourceMemory]
|
cpuReqs, cpuLimits, memoryReqs, memoryLimits := reqs[api.ResourceCPU], limits[api.ResourceCPU], reqs[api.ResourceMemory], limits[api.ResourceMemory]
|
||||||
fractionCpuReqs := float64(cpuReqs.MilliValue()) / float64(allocatable.Cpu().MilliValue()) * 100
|
fractionCpuReqs := float64(0)
|
||||||
fractionCpuLimits := float64(cpuLimits.MilliValue()) / float64(allocatable.Cpu().MilliValue()) * 100
|
fractionCpuLimits := float64(0)
|
||||||
fractionMemoryReqs := float64(memoryReqs.Value()) / float64(allocatable.Memory().Value()) * 100
|
if allocatable.Cpu().MilliValue() != 0 {
|
||||||
fractionMemoryLimits := float64(memoryLimits.Value()) / float64(allocatable.Memory().Value()) * 100
|
fractionCpuReqs = float64(cpuReqs.MilliValue()) / float64(allocatable.Cpu().MilliValue()) * 100
|
||||||
|
fractionCpuLimits = float64(cpuLimits.MilliValue()) / float64(allocatable.Cpu().MilliValue()) * 100
|
||||||
|
}
|
||||||
|
fractionMemoryReqs := float64(0)
|
||||||
|
fractionMemoryLimits := float64(0)
|
||||||
|
if allocatable.Memory().Value() != 0 {
|
||||||
|
fractionMemoryReqs = float64(memoryReqs.Value()) / float64(allocatable.Memory().Value()) * 100
|
||||||
|
fractionMemoryLimits = float64(memoryLimits.Value()) / float64(allocatable.Memory().Value()) * 100
|
||||||
|
}
|
||||||
w.Write(LEVEL_1, "%s (%d%%)\t%s (%d%%)\t%s (%d%%)\t%s (%d%%)\n",
|
w.Write(LEVEL_1, "%s (%d%%)\t%s (%d%%)\t%s (%d%%)\t%s (%d%%)\n",
|
||||||
cpuReqs.String(), int64(fractionCpuReqs), cpuLimits.String(), int64(fractionCpuLimits),
|
cpuReqs.String(), int64(fractionCpuReqs), cpuLimits.String(), int64(fractionCpuLimits),
|
||||||
memoryReqs.String(), int64(fractionMemoryReqs), memoryLimits.String(), int64(fractionMemoryLimits))
|
memoryReqs.String(), int64(fractionMemoryReqs), memoryLimits.String(), int64(fractionMemoryLimits))
|
||||||
|
Loading…
Reference in New Issue
Block a user