Parcourir la source

Avoid panic an AWS findCostForDisk (#1924)

Signed-off-by: Michael Dresser <michaelmdresser@gmail.com>
Michael Dresser il y a 3 ans
Parent
commit
1d101eba1b
1 fichiers modifiés avec 11 ajouts et 1 suppressions
  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
 	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)
 	price, err := strconv.ParseFloat(priceStr, 64)
 	if err != nil {
 	if err != nil {