2
0
Эх сурвалжийг харах

Merge branch 'develop' into logyball/make-ui-base-url-dynamic

logan 3 жил өмнө
parent
commit
62089248da

+ 7 - 0
pkg/cloud/aliyunprovider.go

@@ -1331,3 +1331,10 @@ func determinePVRegion(pv *v1.PersistentVolume) string {
 	}
 	return ""
 }
+
+// PricingSourceSummary returns the pricing source summary for the provider.
+// The summary represents what was _parsed_ from the pricing source, not
+// everything that was _available_ in the pricing source.
+func (a *Alibaba) PricingSourceSummary() interface{} {
+	return a.Pricing
+}

+ 9 - 1
pkg/cloud/awsprovider.go

@@ -114,7 +114,7 @@ func (aws *AWS) PricingSourceStatus() map[string]*PricingSource {
 
 }
 
-// How often spot data is refreshed
+// SpotRefreshDuration represents how much time must pass before we refresh
 const SpotRefreshDuration = 15 * time.Minute
 
 var awsRegions = []string{
@@ -2299,3 +2299,11 @@ func (aws *AWS) CombinedDiscountForNode(instanceType string, isPreemptible bool,
 func (aws *AWS) Regions() []string {
 	return awsRegions
 }
+
+// PricingSourceSummary returns the pricing source summary for the provider.
+// The summary represents what was _parsed_ from the pricing source, not
+// everything that was _available_ in the pricing source.
+func (aws *AWS) PricingSourceSummary() interface{} {
+	// encode the pricing source summary as a JSON string
+	return aws.Pricing
+}

+ 7 - 0
pkg/cloud/azureprovider.go

@@ -404,6 +404,13 @@ type Azure struct {
 	azureStorageConfig             *AzureStorageConfig
 }
 
+// PricingSourceSummary returns the pricing source summary for the provider.
+// The summary represents what was _parsed_ from the pricing source, not
+// everything that was _available_ in the pricing source.
+func (az *Azure) PricingSourceSummary() interface{} {
+	return az.Pricing
+}
+
 type azureKey struct {
 	Labels        map[string]string
 	GPULabel      string

+ 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
+}

+ 7 - 0
pkg/cloud/customprovider.go

@@ -34,6 +34,13 @@ type CustomProvider struct {
 	Config                  *ProviderConfig
 }
 
+// PricingSourceSummary returns the pricing source summary for the provider.
+// The summary represents what was _parsed_ from the pricing source, not what
+// was returned from the relevant API.
+func (cp *CustomProvider) PricingSourceSummary() interface{} {
+	return cp.Pricing
+}
+
 type customProviderKey struct {
 	SpotLabel      string
 	SpotLabelValue string

+ 8 - 1
pkg/cloud/gcpprovider.go

@@ -28,7 +28,7 @@ import (
 	"cloud.google.com/go/bigquery"
 	"cloud.google.com/go/compute/metadata"
 	"golang.org/x/oauth2/google"
-	compute "google.golang.org/api/compute/v1"
+	"google.golang.org/api/compute/v1"
 	v1 "k8s.io/api/core/v1"
 )
 
@@ -1577,3 +1577,10 @@ func getUsageType(labels map[string]string) string {
 	}
 	return "ondemand"
 }
+
+// PricingSourceSummary returns the pricing source summary for the provider.
+// The summary represents what was _parsed_ from the pricing source, not
+// everything that was _available_ in the pricing source.
+func (gcp *GCP) PricingSourceSummary() interface{} {
+	return gcp.Pricing
+}

+ 4 - 2
pkg/cloud/provider.go

@@ -346,6 +346,7 @@ type Provider interface {
 	ClusterManagementPricing() (string, float64, error)
 	CombinedDiscountForNode(string, bool, float64, float64) float64
 	Regions() []string
+	PricingSourceSummary() interface{}
 }
 
 // ClusterName returns the name defined in cluster info, defaulting to the
@@ -486,7 +487,7 @@ func NewProvider(cache clustercache.ClusterCache, apiKey string, config *config.
 			},
 		}, nil
 	case kubecost.GCPProvider:
-		log.Info("metadata reports we are in GCE")
+		log.Info("Found ProviderID starting with \"gce\", using GCP Provider")
 		if apiKey == "" {
 			return nil, errors.New("Supply a GCP Key to start getting data")
 		}
@@ -561,7 +562,8 @@ func getClusterProperties(node *v1.Node) clusterProperties {
 		accountID:      "",
 		projectID:      "",
 	}
-	if metadata.OnGCE() {
+	// The second conditional is mainly if you're running opencost outside of GCE, say in a local environment.
+	if metadata.OnGCE() || strings.HasPrefix(providerID, "gce") {
 		cp.provider = kubecost.GCPProvider
 		cp.configFileName = "gcp.json"
 		cp.projectID = parseGCPProjectID(providerID)

+ 7 - 0
pkg/cloud/scalewayprovider.go

@@ -38,6 +38,13 @@ type Scaleway struct {
 	DownloadPricingDataLock sync.RWMutex
 }
 
+// PricingSourceSummary returns the pricing source summary for the provider.
+// The summary represents what was _parsed_ from the pricing source, not
+// everything that was _available_ in the pricing source.
+func (c *Scaleway) PricingSourceSummary() interface{} {
+	return c.Pricing
+}
+
 func (c *Scaleway) DownloadPricingData() error {
 	c.DownloadPricingDataLock.Lock()
 	defer c.DownloadPricingDataLock.Unlock()

+ 9 - 0
pkg/costmodel/router.go

@@ -692,6 +692,14 @@ func (a *Accesses) GetPricingSourceCounts(w http.ResponseWriter, _ *http.Request
 	w.Write(WrapData(a.Model.GetPricingSourceCounts()))
 }
 
+func (a *Accesses) GetPricingSourceSummary(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
+	w.Header().Set("Content-Type", "application/json")
+	w.Header().Set("Access-Control-Allow-Origin", "*")
+
+	data := a.CloudProvider.PricingSourceSummary()
+	w.Write(WrapData(data, nil))
+}
+
 func (a *Accesses) GetPrometheusMetadata(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
 	w.Header().Set("Content-Type", "application/json")
 	w.Header().Set("Access-Control-Allow-Origin", "*")
@@ -1757,6 +1765,7 @@ func Initialize(additionalConfigWatchers ...*watcher.ConfigMapWatcher) *Accesses
 	a.Router.GET("/clusterInfoMap", a.GetClusterInfoMap)
 	a.Router.GET("/serviceAccountStatus", a.GetServiceAccountStatus)
 	a.Router.GET("/pricingSourceStatus", a.GetPricingSourceStatus)
+	a.Router.GET("/pricingSourceSummary", a.GetPricingSourceSummary)
 	a.Router.GET("/pricingSourceCounts", a.GetPricingSourceCounts)
 
 	// endpoints migrated from server