Kaynağa Gözat

Avoid panic an AWS findCostForDisk (#1924)

Signed-off-by: Michael Dresser <michaelmdresser@gmail.com>
Michael Dresser 3 yıl önce
ebeveyn
işleme
1d101eba1b
1 değiştirilmiş dosya ile 11 ekleme ve 1 silme
  1. 11 1
      pkg/cloud/aws/provider.go

+ 11 - 1
pkg/cloud/aws/provider.go

@@ -1779,7 +1779,17 @@ func (aws *AWS) findCostForDisk(disk *ec2Types.Volume) (*float64, error) {
 
 	key := "us-east-2" + "," + class
 
-	priceStr := aws.Pricing[key].PV.Cost
+	pricing, ok := aws.Pricing[key]
+	if !ok {
+		return nil, fmt.Errorf("no pricing data for key '%s'", key)
+	}
+	if pricing == nil {
+		return nil, fmt.Errorf("nil pricing data for key '%s'", key)
+	}
+	if pricing.PV == nil {
+		return nil, fmt.Errorf("pricing for key '%s' has nil PV", key)
+	}
+	priceStr := pricing.PV.Cost
 
 	price, err := strconv.ParseFloat(priceStr, 64)
 	if err != nil {