Просмотр исходного кода

add spot nodes to pricing dirrectly

Sean Holcomb 4 лет назад
Родитель
Сommit
cebd0b746b
1 измененных файлов с 17 добавлено и 14 удалено
  1. 17 14
      pkg/cloud/azureprovider.go

+ 17 - 14
pkg/cloud/azureprovider.go

@@ -836,6 +836,15 @@ func (az *Azure) DownloadPricingData() error {
 	return nil
 }
 
+func (az *Azure) addPricing(features string, azurePricing *AzurePricing) {
+	az.DownloadPricingDataLock.RLock()
+	defer az.DownloadPricingDataLock.RUnlock()
+	if az.Pricing == nil {
+		az.Pricing = map[string]*AzurePricing{}
+	}
+	az.Pricing[features] = azurePricing
+}
+
 // AllNodePricing returns the Azure pricing objects stored
 func (az *Azure) AllNodePricing() (interface{}, error) {
 	az.DownloadPricingDataLock.RLock()
@@ -876,23 +885,17 @@ func (az *Azure) NodePricing(key Key) (*Node, error) {
 			if azKey.isValidGPUNode() {
 				gpu = "1"
 			}
-			allPrices, err := az.AllNodePricing()
-			if err == nil {
-				allPrices.(map[string]*AzurePricing)[spotFeatures] = &AzurePricing{
-					Node: &Node{
-						Cost:      spotCost,
-						UsageType: "spot",
-						GPU:       gpu,
-					},
-				}
-				az.Pricing = allPrices.(map[string]*AzurePricing)
-			}
-
-			return &Node{
+			spotNode := &Node{
 				Cost:      spotCost,
 				UsageType: "spot",
 				GPU:       gpu,
-			}, nil
+			}
+			
+			az.addPricing(spotFeatures, &AzurePricing{
+				Node: spotNode,
+			})
+
+			return spotNode, nil
 		}
 	}