Skip to content

Commit df44178

Browse files
author
xiejingru
authored
bugfix of populating nodes stats (#256)
1 parent be844e3 commit df44178

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

spec/v1/node.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ func (view *NodeView) populateNodeStats(timeout time.Duration) (err error) {
357357
if stats := view.Report.NodeStats; stats != nil {
358358
for _, s := range stats {
359359
s.Percent = map[string]string{}
360+
if s.Capacity == nil {
361+
s.Capacity = map[string]string{}
362+
}
363+
if s.Usage == nil {
364+
s.Usage = map[string]string{}
365+
}
360366
memory := string(coreV1.ResourceMemory)
361367
if s.Percent[memory], err = s.processResourcePercent(s, memory, populateMemoryResource); err != nil {
362368
return errors.Trace(err)
@@ -383,7 +389,10 @@ func (view *NodeView) populateNodeStats(timeout time.Duration) (err error) {
383389
}
384390

385391
func populateGPUStats(s *NodeStats, extension interface{}) {
386-
stats, _ := extension.(map[string]interface{})
392+
stats, ok := extension.(map[string]interface{})
393+
if !ok {
394+
return
395+
}
387396
if val, ok := stats[KeyGPUUsedMemory]; ok {
388397
used, _ := val.(float64)
389398
s.Usage[ResourceGPU] = strconv.FormatFloat(used, 'f', -1, 64)

0 commit comments

Comments
 (0)