Skip to content

Commit dbc7788

Browse files
committed
fix NaN brought by core
1 parent 087bd39 commit dbc7788

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

describe/node.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package describe
22

33
import (
44
"fmt"
5+
"math"
56
"os"
67
"strings"
78

@@ -45,6 +46,10 @@ func describeNodes(nodes []*corepb.Node) {
4546
// NodeResources describes a list of NodeResource
4647
// output format can be json or yaml or table
4748
func NodeResources(resources ...*corepb.NodeResource) {
49+
for _, resource := range resources {
50+
checkNaNForResource(resource)
51+
}
52+
4853
switch {
4954
case isJSON():
5055
describeAsJSON(resources)
@@ -55,6 +60,21 @@ func NodeResources(resources ...*corepb.NodeResource) {
5560
}
5661
}
5762

63+
func checkNaNForResource(resource *corepb.NodeResource) {
64+
if math.IsNaN(resource.VolumePercent) {
65+
resource.VolumePercent = 0
66+
}
67+
if math.IsNaN(resource.MemoryPercent) {
68+
resource.MemoryPercent = 0
69+
}
70+
if math.IsNaN(resource.StoragePercent) {
71+
resource.StoragePercent = 0
72+
}
73+
if math.IsNaN(resource.CpuPercent) {
74+
resource.CpuPercent = 0
75+
}
76+
}
77+
5878
func describeNodeResources(resources []*corepb.NodeResource) {
5979
t := table.NewWriter()
6080
t.SetOutputMirror(os.Stdout)

0 commit comments

Comments
 (0)