Преглед на файлове

Merge pull request #718 from kubecost/AjayTripathy-fix-indexerror

fix indexing error for updated GCP API
Ajay Tripathy преди 5 години
родител
ревизия
bfd5fa1f1b
променени са 1 файла, в които са добавени 4 реда и са изтрити 4 реда
  1. 4 4
      pkg/cloud/gcpprovider.go

+ 4 - 4
pkg/cloud/gcpprovider.go

@@ -644,7 +644,7 @@ func (gcp *GCP) parsePage(r io.Reader, inputKeys map[string]Key, pvKeys map[stri
 				if instanceType == "ssd" && !strings.Contains(product.Description, "Regional") { // TODO: support regional
 					lastRateIndex := len(product.PricingInfo[0].PricingExpression.TieredRates) - 1
 					var nanos float64
-					if len(product.PricingInfo) > 0 {
+					if lastRateIndex > -1 && len(product.PricingInfo) > 0 {
 						nanos = product.PricingInfo[0].PricingExpression.TieredRates[lastRateIndex].UnitPrice.Nanos
 					} else {
 						continue
@@ -666,7 +666,7 @@ func (gcp *GCP) parsePage(r io.Reader, inputKeys map[string]Key, pvKeys map[stri
 				} else if instanceType == "pdstandard" && !strings.Contains(product.Description, "Regional") { // TODO: support regional
 					lastRateIndex := len(product.PricingInfo[0].PricingExpression.TieredRates) - 1
 					var nanos float64
-					if len(product.PricingInfo) > 0 {
+					if lastRateIndex > -1 && len(product.PricingInfo) > 0 {
 						nanos = product.PricingInfo[0].PricingExpression.TieredRates[lastRateIndex].UnitPrice.Nanos
 					} else {
 						continue
@@ -753,7 +753,7 @@ func (gcp *GCP) parsePage(r io.Reader, inputKeys map[string]Key, pvKeys map[stri
 					if gpuType != "" {
 						lastRateIndex := len(product.PricingInfo[0].PricingExpression.TieredRates) - 1
 						var nanos float64
-						if len(product.PricingInfo) > 0 {
+						if lastRateIndex > -1 && len(product.PricingInfo) > 0 {
 							nanos = product.PricingInfo[0].PricingExpression.TieredRates[lastRateIndex].UnitPrice.Nanos
 						} else {
 							continue
@@ -788,7 +788,7 @@ func (gcp *GCP) parsePage(r io.Reader, inputKeys map[string]Key, pvKeys map[stri
 						if ok || ok2 {
 							lastRateIndex := len(product.PricingInfo[0].PricingExpression.TieredRates) - 1
 							var nanos float64
-							if len(product.PricingInfo) > 0 {
+							if lastRateIndex > -1 && len(product.PricingInfo) > 0 {
 								nanos = product.PricingInfo[0].PricingExpression.TieredRates[lastRateIndex].UnitPrice.Nanos
 							} else {
 								continue