Browse Source

Merge pull request #567 from kubecost/cw-lb-index-out-of-range-hotfix

add array length check before accessing lb.IngressIPAddresses
Calvin Wang 5 years ago
parent
commit
08688a866d
1 changed files with 4 additions and 1 deletions
  1. 4 1
      pkg/costmodel/metrics.go

+ 4 - 1
pkg/costmodel/metrics.go

@@ -518,7 +518,10 @@ func StartCostModelMetricRecording(a *Accesses) bool {
 				keyParts := getLabelStringsFromKey(lbKey)
 				namespace := keyParts[0]
 				serviceName := keyParts[1]
-				ingressIP := lb.IngressIPAddresses[0] // assumes one ingress IP per load balancer
+				ingressIP := ""
+				if len(lb.IngressIPAddresses) > 0 {
+					ingressIP = lb.IngressIPAddresses[0] // assumes one ingress IP per load balancer
+				}
 				a.LBCostRecorder.WithLabelValues(ingressIP, namespace, serviceName).Set(lb.Cost)
 
 				labelKey := getKeyFromLabelStrings(namespace, serviceName)