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

Implement PricingSourceSummary in all cloud providers

Signed-off-by: pokom <mark.poko@grafana.com>
pokom 3 лет назад
Родитель
Сommit
ca707ed159

+ 2 - 2
pkg/cloud/aliyunprovider.go

@@ -1332,6 +1332,6 @@ func determinePVRegion(pv *v1.PersistentVolume) string {
 	return ""
 }
 
-func (a *Alibaba) PricingSourceSummary() (interface{}, error) {
-	return a.Pricing, nil
+func (a *Alibaba) PricingSourceSummary() interface{} {
+	return a.Pricing
 }

+ 2 - 2
pkg/cloud/awsprovider.go

@@ -2301,7 +2301,7 @@ func (aws *AWS) Regions() []string {
 }
 
 // PricingSourceSummary returns the Pricing field from the AWS struct.
-func (aws *AWS) PricingSourceSummary() (interface{}, error) {
+func (aws *AWS) PricingSourceSummary() interface{} {
 	// encode the pricing source summary as a JSON string
-	return aws.Pricing, nil
+	return aws.Pricing
 }

+ 2 - 2
pkg/cloud/azureprovider.go

@@ -404,8 +404,8 @@ type Azure struct {
 	azureStorageConfig             *AzureStorageConfig
 }
 
-func (az *Azure) PricingSourceSummary() (interface{}, error) {
-	return az.Pricing, nil
+func (az *Azure) PricingSourceSummary() interface{} {
+	return az.Pricing
 }
 
 type azureKey struct {

+ 3 - 0
pkg/cloud/csvprovider.go

@@ -425,3 +425,6 @@ func (c *CSVProvider) Regions() []string {
 	return []string{}
 }
 
+func (c *CSVProvider) PricingSourceSummary() interface{} {
+	return c.Pricing
+}

+ 2 - 2
pkg/cloud/customprovider.go

@@ -34,8 +34,8 @@ type CustomProvider struct {
 	Config                  *ProviderConfig
 }
 
-func (cp *CustomProvider) PricingSourceSummary() (interface{}, error) {
-	return cp.Pricing, nil
+func (cp *CustomProvider) PricingSourceSummary() interface{} {
+	return cp.Pricing
 }
 
 type customProviderKey struct {

+ 2 - 2
pkg/cloud/gcpprovider.go

@@ -1578,6 +1578,6 @@ func getUsageType(labels map[string]string) string {
 	return "ondemand"
 }
 
-func (gcp *GCP) PricingSourceSummary() (interface{}, error) {
-	return gcp.Pricing, nil
+func (gcp *GCP) PricingSourceSummary() interface{} {
+	return gcp.Pricing
 }

+ 1 - 1
pkg/cloud/provider.go

@@ -338,7 +338,7 @@ type Provider interface {
 	ClusterManagementPricing() (string, float64, error)
 	CombinedDiscountForNode(string, bool, float64, float64) float64
 	Regions() []string
-	PricingSourceSummary() (interface{}, error)
+	PricingSourceSummary() interface{}
 }
 
 // ClusterName returns the name defined in cluster info, defaulting to the

+ 2 - 3
pkg/cloud/scalewayprovider.go

@@ -38,9 +38,8 @@ type Scaleway struct {
 	DownloadPricingDataLock sync.RWMutex
 }
 
-func (c *Scaleway) PricingSourceSummary() (interface{}, error) {
-	//TODO implement me
-	panic("implement me")
+func (c *Scaleway) PricingSourceSummary() interface{} {
+	return c.Pricing
 }
 
 func (c *Scaleway) DownloadPricingData() error {

+ 1 - 5
pkg/costmodel/router.go

@@ -696,11 +696,7 @@ func (a *Accesses) GetPricingSourceSummary(w http.ResponseWriter, r *http.Reques
 	w.Header().Set("Content-Type", "application/json")
 	w.Header().Set("Access-Control-Allow-Origin", "*")
 
-	data, err := a.CloudProvider.PricingSourceSummary()
-	if err != nil {
-		w.WriteHeader(http.StatusInternalServerError)
-		w.Write(WrapData(nil, err))
-	}
+	data := a.CloudProvider.PricingSourceSummary()
 	w.Write(WrapData(data, nil))
 }