فهرست منبع

When there is no matching node in the node list. just assume no GPU cost to avoid nil panic (#2474)

Signed-off-by: Alex Meijer <ameijer@kubecost.com>
Alex Meijer 2 سال پیش
والد
کامیت
eb135dadb0
1فایلهای تغییر یافته به همراه11 افزوده شده و 2 حذف شده
  1. 11 2
      pkg/costmodel/metrics.go

+ 11 - 2
pkg/costmodel/metrics.go

@@ -619,8 +619,17 @@ func (cmme *CostModelMetricsEmitter) Start() bool {
 				if len(costs.GPUReq) > 0 {
 					// allocation here is set to the request because shared GPU usage not yet supported.
 					// if VPGUs, request x (actual/virtual)
-					vgpu, verr := strconv.ParseFloat(nodes[nodeName].VGPU, 64)
-					gpu, err := strconv.ParseFloat(nodes[nodeName].GPU, 64)
+					vgpu := 0.0
+					gpu := 0.0
+					var err, verr error
+					if matchedNode, found := nodes[nodeName]; found {
+						vgpu, verr = strconv.ParseFloat(matchedNode.VGPU, 64)
+						gpu, err = strconv.ParseFloat(matchedNode.GPU, 64)
+					} else {
+						log.Tracef("cost data for node %s had GPUReq, but there was no cost data available for the node", nodeName)
+						log.Trace("defaulting GPU to 0 cost")
+					}
+
 					gpualloc := costs.GPUReq[0].Value
 					if verr != nil && err != nil && vgpu != 0 {
 						gpualloc = gpualloc * (gpu / vgpu)