|
|
@@ -382,6 +382,7 @@ type Azure struct {
|
|
|
Clientset clustercache.ClusterCache
|
|
|
Config *ProviderConfig
|
|
|
ServiceAccountChecks map[string]*ServiceAccountCheck
|
|
|
+ RateCardPricingError error
|
|
|
}
|
|
|
|
|
|
type azureKey struct {
|
|
|
@@ -731,6 +732,7 @@ func (az *Azure) DownloadPricingData() error {
|
|
|
|
|
|
config, err := az.GetConfig()
|
|
|
if err != nil {
|
|
|
+ az.RateCardPricingError = err
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
@@ -747,6 +749,7 @@ func (az *Azure) DownloadPricingData() error {
|
|
|
credentialsConfig := auth.NewClientCredentialsConfig(config.AzureClientID, config.AzureClientSecret, config.AzureTenantID)
|
|
|
a, err := credentialsConfig.Authorizer()
|
|
|
if err != nil {
|
|
|
+ az.RateCardPricingError = err
|
|
|
return err
|
|
|
}
|
|
|
authorizer = a
|
|
|
@@ -758,6 +761,7 @@ func (az *Azure) DownloadPricingData() error {
|
|
|
if err != nil { // Failed to create authorizer from environment, try from file
|
|
|
a, err := auth.NewAuthorizerFromFile(azure.PublicCloud.ResourceManagerEndpoint)
|
|
|
if err != nil {
|
|
|
+ az.RateCardPricingError = err
|
|
|
return err
|
|
|
}
|
|
|
authorizer = a
|
|
|
@@ -784,19 +788,17 @@ func (az *Azure) DownloadPricingData() error {
|
|
|
klog.Infof("Using ratecard query %s", rateCardFilter)
|
|
|
result, err := rcClient.Get(context.TODO(), rateCardFilter)
|
|
|
if err != nil {
|
|
|
+ az.RateCardPricingError = err
|
|
|
return err
|
|
|
}
|
|
|
allPrices := make(map[string]*AzurePricing)
|
|
|
regions, err := getRegions("compute", sClient, providersClient, config.AzureSubscriptionID)
|
|
|
if err != nil {
|
|
|
+ az.RateCardPricingError = err
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- c, err := az.GetConfig()
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- baseCPUPrice := c.CPU
|
|
|
+ baseCPUPrice := config.CPU
|
|
|
|
|
|
for _, v := range *result.Meters {
|
|
|
meterName := *v.MeterName
|
|
|
@@ -915,6 +917,7 @@ func (az *Azure) DownloadPricingData() error {
|
|
|
}
|
|
|
|
|
|
az.Pricing = allPrices
|
|
|
+ az.RateCardPricingError = nil
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
@@ -1379,8 +1382,29 @@ func (az *Azure) ServiceAccountStatus() *ServiceAccountStatus {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+const rateCardPricingSource = "Rate Card API"
|
|
|
+
|
|
|
+// PricingSourceStatus returns the status of the rate card api
|
|
|
func (az *Azure) PricingSourceStatus() map[string]*PricingSource {
|
|
|
- return make(map[string]*PricingSource)
|
|
|
+ sources := make(map[string]*PricingSource)
|
|
|
+ errMsg := ""
|
|
|
+ if az.RateCardPricingError != nil {
|
|
|
+ errMsg = az.RateCardPricingError.Error()
|
|
|
+ }
|
|
|
+ rcps := &PricingSource {
|
|
|
+ Name: rateCardPricingSource,
|
|
|
+ Error: errMsg,
|
|
|
+ }
|
|
|
+ if rcps.Error != "" {
|
|
|
+ rcps.Available = false
|
|
|
+ } else if len(az.Pricing) == 0 {
|
|
|
+ rcps.Error = "No Pricing Data Available"
|
|
|
+ rcps.Available = false
|
|
|
+ }else {
|
|
|
+ rcps.Available = true
|
|
|
+ }
|
|
|
+ sources[rateCardPricingSource] = rcps
|
|
|
+ return sources
|
|
|
}
|
|
|
|
|
|
func (*Azure) ClusterManagementPricing() (string, float64, error) {
|