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

fixing panic when service key is not given in system disk retrieval code also letting PV pricing and node pricing default if not gathered by erroring out

Signed-off-by: Alan Rodrigues <alanr5691@yahoo.com>
Alan Rodrigues 3 лет назад
Родитель
Сommit
41d9227cd8
1 измененных файлов с 21 добавлено и 20 удалено
  1. 21 20
      pkg/cloud/aliyunprovider.go

+ 21 - 20
pkg/cloud/aliyunprovider.go

@@ -481,8 +481,8 @@ func (alibaba *Alibaba) NodePricing(key Key) (*Node, error) {
 
 	pricing, ok := alibaba.Pricing[keyFeature]
 	if !ok {
-		log.Warnf("Node pricing information not found for node with feature: %s", keyFeature)
-		return &Node{}, nil
+		log.Errorf("Node pricing information not found for node with feature: %s", keyFeature)
+		return nil, fmt.Errorf("Node pricing information not found for node with feature: %s letting it use default values", keyFeature)
 	}
 
 	log.Debugf("returning the node price for the node with feature: %s", keyFeature)
@@ -501,8 +501,8 @@ func (alibaba *Alibaba) PVPricing(pvk PVKey) (*PV, error) {
 	pricing, ok := alibaba.Pricing[keyFeature]
 
 	if !ok {
-		log.Warnf("Persistent Volume pricing not found for PV with feature: %s", keyFeature)
-		return &PV{}, nil
+		log.Errorf("Persistent Volume pricing not found for PV with feature: %s", keyFeature)
+		return nil, fmt.Errorf("Persistent Volume pricing not found for PV with feature: %s letting it use default values", keyFeature)
 	}
 
 	log.Debugf("returning the PV price for the node with feature: %s", keyFeature)
@@ -762,15 +762,24 @@ func (alibaba *Alibaba) GetKey(mapValue map[string]string, node *v1.Node) Key {
 
 	var aak *credentials.AccessKeyCredential
 	var err error
-	var skipSystemDiskRetrieval, ok bool
+	var ok bool
 	var client *sdk.Client
 	var signer *signers.AccessKeySigner
 
+	optimizedKeyword := ""
+	if slimK8sNode.IsIoOptimized {
+		optimizedKeyword = ALIBABA_OPTIMIZE_KEYWORD
+	} else {
+		optimizedKeyword = ALIBABA_NON_OPTIMIZE_KEYWORD
+	}
+
+	var diskCategory, diskSizeInGiB, diskPerformanceLevel string
+
 	if !alibaba.accessKeyisLoaded() {
 		aak, err = alibaba.GetAlibabaAccessKey()
 		if err != nil {
 			log.Warnf("unable to set the signer for node with providerID %s to retrieve the key skipping SystemDisk Retrieval with err: %v", slimK8sNode.ProviderID, err)
-			skipSystemDiskRetrieval = true
+			return NewAlibabaNodeKey(slimK8sNode, optimizedKeyword, diskCategory, diskSizeInGiB, diskPerformanceLevel)
 		}
 	} else {
 		aak = alibaba.accessKey
@@ -778,28 +787,20 @@ func (alibaba *Alibaba) GetKey(mapValue map[string]string, node *v1.Node) Key {
 
 	signer = signers.NewAccessKeySigner(aak)
 
+	if aak == nil {
+		log.Warnf("unable to retrieve the Alibaba API keys for node with providerID %s hence skipping SystemDisk Retrieval", slimK8sNode.ProviderID)
+		return NewAlibabaNodeKey(slimK8sNode, optimizedKeyword, diskCategory, diskSizeInGiB, diskPerformanceLevel)
+	}
+
 	if client, ok = alibaba.clients[slimK8sNode.RegionID]; !ok {
 		client, err = sdk.NewClientWithAccessKey(slimK8sNode.RegionID, aak.AccessKeyId, aak.AccessKeySecret)
 		if err != nil {
 			log.Warnf("unable to set the client  for node with providerID %s to retrieve the key skipping SystemDisk Retrieval with err: %v", slimK8sNode.ProviderID, err)
-			skipSystemDiskRetrieval = true
+			return NewAlibabaNodeKey(slimK8sNode, optimizedKeyword, diskCategory, diskSizeInGiB, diskPerformanceLevel)
 		}
 		alibaba.clients[slimK8sNode.RegionID] = client
 	}
 
-	optimizedKeyword := ""
-	if slimK8sNode.IsIoOptimized {
-		optimizedKeyword = ALIBABA_OPTIMIZE_KEYWORD
-	} else {
-		optimizedKeyword = ALIBABA_NON_OPTIMIZE_KEYWORD
-	}
-
-	var diskCategory, diskSizeInGiB, diskPerformanceLevel string
-
-	if skipSystemDiskRetrieval {
-		return NewAlibabaNodeKey(slimK8sNode, optimizedKeyword, diskCategory, diskSizeInGiB, diskPerformanceLevel)
-	}
-
 	instanceID := getInstanceIDFromProviderID(slimK8sNode.ProviderID)
 	slimK8sNode.SystemDisk = getSystemDiskInfoOfANode(instanceID, slimK8sNode.RegionID, client, signer)