Explorar o código

ensure provider id is set on in cluster storage costs on Azure clusters

Sean Holcomb %!s(int64=5) %!d(string=hai) anos
pai
achega
a21bbcdfae
Modificáronse 2 ficheiros con 21 adicións e 12 borrados
  1. 14 12
      pkg/cloud/azureprovider.go
  2. 7 0
      pkg/costmodel/cluster.go

+ 14 - 12
pkg/cloud/azureprovider.go

@@ -71,7 +71,7 @@ const AzureLayout = "2006-01-02"
 var loadedAzureSecret bool = false
 var loadedAzureSecret bool = false
 var azureSecret *AzureServiceKey = nil
 var azureSecret *AzureServiceKey = nil
 var loadedAzureStorageConfigSecret bool = false
 var loadedAzureStorageConfigSecret bool = false
-var azureStorageConfig *AzureStorageConfig= nil
+var azureStorageConfig *AzureStorageConfig = nil
 
 
 type regionParts []string
 type regionParts []string
 
 
@@ -191,7 +191,7 @@ type Azure struct {
 	DownloadPricingDataLock sync.RWMutex
 	DownloadPricingDataLock sync.RWMutex
 	Clientset               clustercache.ClusterCache
 	Clientset               clustercache.ClusterCache
 	Config                  *ProviderConfig
 	Config                  *ProviderConfig
-	ServiceAccountChecks        map[string]*ServiceAccountCheck
+	ServiceAccountChecks    map[string]*ServiceAccountCheck
 }
 }
 
 
 type azureKey struct {
 type azureKey struct {
@@ -221,8 +221,8 @@ func (k *azureKey) ID() string {
 
 
 // Represents an azure storage config
 // Represents an azure storage config
 type AzureStorageConfig struct {
 type AzureStorageConfig struct {
-	AccountName string `json:"azureStorageAccount"`
-	AccessKey string `json:"azureStorageAccessKey"`
+	AccountName   string `json:"azureStorageAccount"`
+	AccessKey     string `json:"azureStorageAccessKey"`
 	ContainerName string `json:"azureStorageContainer"`
 	ContainerName string `json:"azureStorageContainer"`
 }
 }
 
 
@@ -241,7 +241,6 @@ type AzureServiceKey struct {
 	ServiceKey     *AzureAppKey `json:"serviceKey"`
 	ServiceKey     *AzureAppKey `json:"serviceKey"`
 }
 }
 
 
-
 // Validity check on service key
 // Validity check on service key
 func (ask *AzureServiceKey) IsValid() bool {
 func (ask *AzureServiceKey) IsValid() bool {
 	return ask.SubscriptionID != "" &&
 	return ask.SubscriptionID != "" &&
@@ -300,7 +299,7 @@ func (az *Azure) getAzureStorageConfig(forceReload bool) (accessKey, accountName
 	}
 	}
 	// 1. Check for secret
 	// 1. Check for secret
 	s, _ := az.loadAzureStorageConfig(forceReload)
 	s, _ := az.loadAzureStorageConfig(forceReload)
-	if s != nil && s.AccessKey != "" && s.AccountName != ""  && s.ContainerName != ""{
+	if s != nil && s.AccessKey != "" && s.AccountName != "" && s.ContainerName != "" {
 
 
 		az.ServiceAccountChecks["hasStorage"] = &ServiceAccountCheck{
 		az.ServiceAccountChecks["hasStorage"] = &ServiceAccountCheck{
 			Message: "Azure Storage Config exists",
 			Message: "Azure Storage Config exists",
@@ -773,19 +772,25 @@ type azurePvKey struct {
 	StorageClass           string
 	StorageClass           string
 	StorageClassParameters map[string]string
 	StorageClassParameters map[string]string
 	DefaultRegion          string
 	DefaultRegion          string
+	ProviderId             string
 }
 }
 
 
 func (az *Azure) GetPVKey(pv *v1.PersistentVolume, parameters map[string]string, defaultRegion string) PVKey {
 func (az *Azure) GetPVKey(pv *v1.PersistentVolume, parameters map[string]string, defaultRegion string) PVKey {
+	providerID := ""
+	if pv.Spec.AzureDisk != nil {
+		providerID = pv.Spec.AzureDisk.DiskName
+	}
 	return &azurePvKey{
 	return &azurePvKey{
 		Labels:                 pv.Labels,
 		Labels:                 pv.Labels,
 		StorageClass:           pv.Spec.StorageClassName,
 		StorageClass:           pv.Spec.StorageClassName,
 		StorageClassParameters: parameters,
 		StorageClassParameters: parameters,
 		DefaultRegion:          defaultRegion,
 		DefaultRegion:          defaultRegion,
+		ProviderId:             providerID,
 	}
 	}
 }
 }
 
 
 func (key *azurePvKey) ID() string {
 func (key *azurePvKey) ID() string {
-	return ""
+	return key.ProviderId
 }
 }
 
 
 func (key *azurePvKey) GetStorageClass() string {
 func (key *azurePvKey) GetStorageClass() string {
@@ -945,7 +950,7 @@ func GetExternalAllocations(start string, end string, aggregators []string, filt
 	return oocAllocsArr, nil
 	return oocAllocsArr, nil
 }
 }
 
 
-func ParseCSV (reader *csv.Reader, start, end time.Time, oocAllocs map[string]*OutOfClusterAllocation, aggregators []string, filterType string, filterValue string, crossCluster bool) error {
+func ParseCSV(reader *csv.Reader, start, end time.Time, oocAllocs map[string]*OutOfClusterAllocation, aggregators []string, filterType string, filterValue string, crossCluster bool) error {
 	headers, _ := reader.Read()
 	headers, _ := reader.Read()
 
 
 	headerMap := map[string]int{}
 	headerMap := map[string]int{}
@@ -990,7 +995,7 @@ func ParseCSV (reader *csv.Reader, start, end time.Time, oocAllocs map[string]*O
 		}
 		}
 
 
 		if filterType != "kubernetes_" {
 		if filterType != "kubernetes_" {
-			if value, ok := itemTags[filterType];!ok || value != filterValue {
+			if value, ok := itemTags[filterType]; !ok || value != filterValue {
 				continue
 				continue
 			}
 			}
 		}
 		}
@@ -1014,13 +1019,10 @@ func ParseCSV (reader *csv.Reader, start, end time.Time, oocAllocs map[string]*O
 			oocAllocs[key] = ooc
 			oocAllocs[key] = ooc
 		}
 		}
 
 
-
 	}
 	}
 	return nil
 	return nil
 }
 }
 
 
-
-
 // UsageDateTime only contains date information and not time because of this filtering usageDate time is inclusive on start and exclusive on end
 // UsageDateTime only contains date information and not time because of this filtering usageDate time is inclusive on start and exclusive on end
 func isValidUsageDateTime(start, end, usageDateTime time.Time) bool {
 func isValidUsageDateTime(start, end, usageDateTime time.Time) bool {
 	return (usageDateTime.After(start) || usageDateTime.Equal(start)) && usageDateTime.Before(end)
 	return (usageDateTime.After(start) || usageDateTime.Equal(start)) && usageDateTime.Before(end)

+ 7 - 0
pkg/costmodel/cluster.go

@@ -369,6 +369,13 @@ func ClusterDisks(client prometheus.Client, provider cloud.Provider, duration, o
 	for _, disk := range diskMap {
 	for _, disk := range diskMap {
 		// Apply all remaining RAM to Idle
 		// Apply all remaining RAM to Idle
 		disk.Breakdown.Idle = 1.0 - (disk.Breakdown.System + disk.Breakdown.Other + disk.Breakdown.User)
 		disk.Breakdown.Idle = 1.0 - (disk.Breakdown.System + disk.Breakdown.Other + disk.Breakdown.User)
+
+		// Set provider Id to the name for reconciliation on Azure
+		if fmt.Sprintf("%T", provider) == "*provider.Azure"{
+			if disk.ProviderID == "" {
+				disk.ProviderID = disk.Name
+			}
+		}
 	}
 	}
 
 
 	return diskMap, nil
 	return diskMap, nil