Răsfoiți Sursa

Merge pull request #773 from kubecost/sean/chinese-pricing-for-nodes

Add check for Chinese prices on Node creation
Sean Holcomb 5 ani în urmă
părinte
comite
40592ae63f
1 a modificat fișierele cu 18 adăugiri și 10 ștergeri
  1. 18 10
      pkg/cloud/awsprovider.go

+ 18 - 10
pkg/cloud/awsprovider.go

@@ -854,11 +854,11 @@ func (aws *AWS) DownloadPricingData() error {
 							cost = offerTerm.PriceDimensions[sku.(string)+OnDemandRateCodeCn+HourlyRateCodeCn].PricePerUnit.CNY
 						}
 						if strings.Contains(key, "EBS:VolumeP-IOPS.piops") {
-						// If the specific UsageType is the per IO cost used on io1 volumes
-						// we need to add the per IO cost to the io1 PV cost
+							// If the specific UsageType is the per IO cost used on io1 volumes
+							// we need to add the per IO cost to the io1 PV cost
 
-						// Add the per IO cost to the PV object for the io1 volume type
-						aws.Pricing[key].PV.CostPerIO = cost
+							// Add the per IO cost to the PV object for the io1 volume type
+							aws.Pricing[key].PV.CostPerIO = cost
 						} else if strings.Contains(key, "EBS:Volume") {
 							// If volume, we need to get hourly cost and add it to the PV object
 							costFloat, _ := strconv.ParseFloat(cost, 64)
@@ -1071,11 +1071,20 @@ func (aws *AWS) createNode(terms *AWSProductTerms, usageType string, k Key) (*No
 		}, nil
 
 	}
+	var cost string
 	c, ok := terms.OnDemand.PriceDimensions[terms.Sku+OnDemandRateCode+HourlyRateCode]
-	if !ok {
-		return nil, fmt.Errorf("Could not fetch data for \"%s\"", k.ID())
+	if ok {
+		cost = c.PricePerUnit.USD
+	} else {
+		// Check for Chinese pricing before throwing error
+		c, ok = terms.OnDemand.PriceDimensions[terms.Sku+OnDemandRateCodeCn+HourlyRateCodeCn]
+		if ok {
+			cost = c.PricePerUnit.CNY
+		} else {
+			return nil, fmt.Errorf("Could not fetch data for \"%s\"", k.ID())
+		}
 	}
-	cost := c.PricePerUnit.USD
+
 	return &Node{
 		Cost:         cost,
 		VCPU:         terms.VCpu,
@@ -1589,7 +1598,7 @@ func (a *AWS) QueryAthenaPaginated(query string) (*athena.GetQueryResultsInput,
 	resultsBucket := customPricing.AthenaBucketName
 	database := customPricing.AthenaDatabase
 	c := &aws.Config{
-		Region: region,
+		Region:              region,
 		STSRegionalEndpoint: endpoints.RegionalSTSEndpoint,
 	}
 	s := session.Must(session.NewSession(c))
@@ -1659,7 +1668,7 @@ func (a *AWS) QueryAthenaBillingData(query string) (*athena.GetQueryResultsOutpu
 	resultsBucket := customPricing.AthenaBucketName
 	database := customPricing.AthenaDatabase
 	c := &aws.Config{
-		Region: region,
+		Region:              region,
 		STSRegionalEndpoint: endpoints.RegionalSTSEndpoint,
 	}
 	s := session.Must(session.NewSession(c))
@@ -1929,7 +1938,6 @@ func (aws *AWS) ShowAthenaColumns() (map[string]bool, error) {
 	return columnSet, nil
 }
 
-
 // ExternalAllocations represents tagged assets outside the scope of kubernetes.
 // "start" and "end" are dates of the format YYYY-MM-DD
 // "aggregator" is the tag used to determine how to allocate those assets, ie namespace, pod, etc.