Kaynağa Gözat

clean up - move function, check err code

Signed-off-by: Alex Meijer <ameijer@kubecost.com>
Alex Meijer 3 yıl önce
ebeveyn
işleme
d5785d946f
1 değiştirilmiş dosya ile 29 ekleme ve 26 silme
  1. 29 26
      pkg/cloud/awsprovider.go

+ 29 - 26
pkg/cloud/awsprovider.go

@@ -906,7 +906,10 @@ func (aws *AWS) DownloadPricingData() error {
 	if err != nil {
 		return err
 	}
-	aws.populatePricing(resp, inputkeys)
+	err = aws.populatePricing(resp, inputkeys)
+	if err != nil {
+		return err
+	}
 	log.Infof("Finished downloading \"%s\"", pricingURL)
 
 	if !aws.SpotRefreshEnabled() {
@@ -936,31 +939,6 @@ func (aws *AWS) DownloadPricingData() error {
 	return nil
 }
 
-func (aws *AWS) refreshSpotPricing(force bool) {
-	aws.SpotPricingLock.Lock()
-	defer aws.SpotPricingLock.Unlock()
-
-	now := time.Now().UTC()
-	updateTime := now.Add(-SpotRefreshDuration)
-
-	// Return if there was an update time set and an hour hasn't elapsed
-	if !force && aws.SpotPricingUpdatedAt != nil && aws.SpotPricingUpdatedAt.After(updateTime) {
-		return
-	}
-
-	sp, err := aws.parseSpotData(aws.SpotDataBucket, aws.SpotDataPrefix, aws.ProjectID, aws.SpotDataRegion)
-	if err != nil {
-		log.Warnf("Skipping AWS spot data download: %s", err.Error())
-		aws.SpotPricingError = err
-		return
-	}
-	aws.SpotPricingError = nil
-
-	// update time last updated
-	aws.SpotPricingUpdatedAt = &now
-	aws.SpotPricingByInstanceID = sp
-}
-
 func (aws *AWS) populatePricing(resp *http.Response, inputkeys map[string]bool) error {
 	aws.Pricing = make(map[string]*AWSProductTerms)
 	skusToKeys := make(map[string]string)
@@ -1109,6 +1087,31 @@ func (aws *AWS) populatePricing(resp *http.Response, inputkeys map[string]bool)
 	return nil
 }
 
+func (aws *AWS) refreshSpotPricing(force bool) {
+	aws.SpotPricingLock.Lock()
+	defer aws.SpotPricingLock.Unlock()
+
+	now := time.Now().UTC()
+	updateTime := now.Add(-SpotRefreshDuration)
+
+	// Return if there was an update time set and an hour hasn't elapsed
+	if !force && aws.SpotPricingUpdatedAt != nil && aws.SpotPricingUpdatedAt.After(updateTime) {
+		return
+	}
+
+	sp, err := aws.parseSpotData(aws.SpotDataBucket, aws.SpotDataPrefix, aws.ProjectID, aws.SpotDataRegion)
+	if err != nil {
+		log.Warnf("Skipping AWS spot data download: %s", err.Error())
+		aws.SpotPricingError = err
+		return
+	}
+	aws.SpotPricingError = nil
+
+	// update time last updated
+	aws.SpotPricingUpdatedAt = &now
+	aws.SpotPricingByInstanceID = sp
+}
+
 // Stubbed NetworkPricing for AWS. Pull directly from aws.json for now
 func (aws *AWS) NetworkPricing() (*Network, error) {
 	cpricing, err := aws.Config.GetCustomPricingData()