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

fix logging bug, do pricing fallbacks

AjayTripathy 7 лет назад
Родитель
Сommit
c59ea533be
2 измененных файлов с 25 добавлено и 22 удалено
  1. 0 4
      cloud/aws.json
  2. 25 18
      cloud/awsprovider.go

+ 0 - 4
cloud/aws.json

@@ -7,11 +7,7 @@
     "spotRAM": "0.000892",
     "spotLabel": "kops.k8s.io/instancegroup",
     "spotLabelValue": "spotinstance-nodes",
-<<<<<<< HEAD
-    "awsServiceKeyName": "AKIAXW6UVLRR7ZKG5V6U",
-=======
     "awsServiceKeyName": "AKIAXW6UVLRRTBCUKQFP",
->>>>>>> 23e77c851d0e7c66583c2a02abb4557781598929
     "awsServiceKeySecret": "",
     "awsSpotDataRegion":"us-east-2",
     "awsSpotDataBucket": "kc-test-spot",

+ 25 - 18
cloud/awsprovider.go

@@ -216,6 +216,22 @@ func (aws *AWS) isPreemptible(key string) bool {
 // DownloadPricingData fetches data from the AWS Pricing API
 func (aws *AWS) DownloadPricingData() error {
 
+	c, err := GetDefaultPricingData("aws.json")
+	if err != nil {
+		klog.V(1).Infof("Error downloading default pricing data: %s", err.Error())
+	}
+	aws.BaseCPUPrice = c.CPU
+	aws.BaseSpotCPUPrice = c.SpotCPU
+	aws.BaseSpotRAMPrice = c.SpotRAM
+	aws.SpotLabelName = c.SpotLabel
+	aws.SpotLabelValue = c.SpotLabelValue
+	aws.SpotDataBucket = c.SpotDataBucket
+	aws.SpotDataPrefix = c.SpotDataPrefix
+	aws.ProjectID = c.ProjectID
+	aws.SpotDataRegion = c.SpotDataRegion
+	aws.ServiceKeyName = c.ServiceKeyName
+	aws.ServiceKeySecret = c.ServiceKeySecret
+
 	nodeList, err := aws.Clientset.CoreV1().Nodes().List(metav1.ListOptions{})
 	if err != nil {
 		return err
@@ -309,21 +325,6 @@ func (aws *AWS) DownloadPricingData() error {
 	if err != nil {
 		return err
 	}
-	c, err := GetDefaultPricingData("aws.json")
-	if err != nil {
-		klog.V(1).Infof("Error downloading default pricing data: %s", err.Error())
-	}
-	aws.BaseCPUPrice = c.CPU
-	aws.BaseSpotCPUPrice = c.SpotCPU
-	aws.BaseSpotRAMPrice = c.SpotRAM
-	aws.SpotLabelName = c.SpotLabel
-	aws.SpotLabelValue = c.SpotLabelValue
-	aws.SpotDataBucket = c.SpotDataBucket
-	aws.SpotDataPrefix = c.SpotDataPrefix
-	aws.ProjectID = c.ProjectID
-	aws.SpotDataRegion = c.SpotDataRegion
-	aws.ServiceKeyName = c.ServiceKeyName
-	aws.ServiceKeySecret = c.ServiceKeySecret
 
 	sp, err := parseSpotData(aws.SpotDataBucket, aws.SpotDataPrefix, aws.ProjectID, aws.SpotDataRegion, aws.ServiceKeyName, aws.ServiceKeySecret)
 	if err != nil {
@@ -403,8 +404,14 @@ func (aws *AWS) NodePricing(k Key) (*Node, error) {
 			return nil, fmt.Errorf("Unable to find any Pricing data for \"%s\"", key)
 		}
 		return aws.createNode(terms, usageType, k)
-	} else {
-		return nil, fmt.Errorf("Invalid Pricing Key \"%s\"", key)
+	} else { // Fall back to base pricing if we can't find the key.
+		klog.V(1).Infof("Invalid Pricing Key \"%s\"", key)
+		return &Node{
+			Cost:             aws.BaseCPUPrice,
+			BaseCPUPrice:     aws.BaseCPUPrice,
+			UsageType:        usageType,
+			UsesBaseCPUPrice: true,
+		}, nil
 	}
 }
 
@@ -732,7 +739,7 @@ func parseSpotData(bucket string, prefix string, projectID string, region string
 	if err != nil {
 		return nil, err
 	}
-	klog.V(2).Infof("Found %d spot data files from today", len(lso.Contents))
+	klog.V(2).Infof("Found %d spot data files from today", len(lso2.Contents))
 
 	var keys []*string
 	for _, obj := range lso.Contents {