Browse Source

add the ability to modify clustername

AjayTripathy 6 years ago
parent
commit
1d8c58e73e
4 changed files with 32 additions and 2 deletions
  1. 7 0
      cloud/awsprovider.go
  2. 7 0
      cloud/azureprovider.go
  3. 9 1
      cloud/gcpprovider.go
  4. 9 1
      cloud/provider.go

+ 7 - 0
cloud/awsprovider.go

@@ -756,6 +756,13 @@ func (aws *AWS) NodePricing(k Key) (*Node, error) {
 // ClusterInfo returns an object that represents the cluster. TODO: actually return the name of the cluster. Blocked on cluster federation.
 func (awsProvider *AWS) ClusterInfo() (map[string]string, error) {
 	defaultClusterName := "AWS Cluster #1"
+	c, err := awsProvider.GetConfig()
+	if c.ClusterName != "" {
+		m := make(map[string]string)
+		m["name"] = c.ClusterName
+		m["provider"] = "AWS"
+		return m, nil
+	}
 	makeStructure := func(clusterName string) (map[string]string, error) {
 		klog.V(2).Infof("Returning \"%s\" as ClusterName", clusterName)
 		m := make(map[string]string)

+ 7 - 0
cloud/azureprovider.go

@@ -456,6 +456,13 @@ func (*Azure) GetDisks() ([]byte, error) {
 func (az *Azure) ClusterInfo() (map[string]string, error) {
 	m := make(map[string]string)
 	m["name"] = "Azure Cluster #1"
+	c, err := az.GetConfig()
+	if err != nil {
+		return nil, err
+	}
+	if c.ClusterName != "" {
+		m["name"] = c.ClusterName
+	}
 	m["provider"] = "azure"
 	return m, nil
 

+ 9 - 1
cloud/gcpprovider.go

@@ -234,7 +234,7 @@ func (gcp *GCP) QuerySQL(query string) ([]*OutOfClusterAllocation, error) {
 }
 
 // ClusterName returns the name of a GKE cluster, as provided by metadata.
-func (*GCP) ClusterInfo() (map[string]string, error) {
+func (gcp *GCP) ClusterInfo() (map[string]string, error) {
 	metadataClient := metadata.NewClient(&http.Client{Transport: userAgentTransport{
 		userAgent: "kubecost",
 		base:      http.DefaultTransport,
@@ -245,6 +245,14 @@ func (*GCP) ClusterInfo() (map[string]string, error) {
 		return nil, err
 	}
 
+	c, err := gcp.GetConfig()
+	if err != nil {
+		klog.V(1).Infof("Error opening config: %s", err.Error())
+	}
+	if c.ClusterName != "" {
+		attribute = c.ClusterName
+	}
+
 	m := make(map[string]string)
 	m["name"] = attribute
 	m["provider"] = "GCP"

+ 9 - 1
cloud/provider.go

@@ -177,6 +177,7 @@ type CustomPricing struct {
 	AzureTenantID       string `json:"azureTenantID"`
 	CurrencyCode        string `json:"currencyCode"`
 	Discount            string `json:"discount"`
+	ClusterName         string `json:"clusterName"`
 }
 
 func SetCustomPricingField(obj *CustomPricing, name string, value string) error {
@@ -266,8 +267,15 @@ func (cprov *CustomProvider) UpdateConfig(r io.Reader, updateType string) (*Cust
 
 }
 
-func (*CustomProvider) ClusterInfo() (map[string]string, error) {
+func (c *CustomProvider) ClusterInfo() (map[string]string, error) {
+	conf, err := c.GetConfig()
+	if err != nil {
+		return nil, err
+	}
 	m := make(map[string]string)
+	if conf.ClusterName != "" {
+		m["name"] = conf.ClusterName
+	}
 	m["provider"] = "custom"
 	return m, nil
 }