AjayTripathy 6 anni fa
parent
commit
f1629a14b7
5 ha cambiato i file con 94 aggiunte e 53 eliminazioni
  1. 14 4
      cloud/awsprovider.go
  2. 14 4
      cloud/azureprovider.go
  3. 14 4
      cloud/customprovider.go
  4. 14 4
      cloud/gcpprovider.go
  5. 38 37
      cloud/provider.go

+ 14 - 4
cloud/awsprovider.go

@@ -307,16 +307,26 @@ func (aws *AWS) UpdateConfig(r io.Reader, updateType string) (*CustomPricing, er
 		c.ServiceKeySecret = a.ServiceKeySecret
 		c.ServiceKeySecret = a.ServiceKeySecret
 		c.ProjectID = a.AccountID
 		c.ProjectID = a.AccountID
 	} else {
 	} else {
-		a := make(map[string]string)
+		a := make(map[string]interface{})
 		err = json.NewDecoder(r).Decode(&a)
 		err = json.NewDecoder(r).Decode(&a)
 		if err != nil {
 		if err != nil {
 			return nil, err
 			return nil, err
 		}
 		}
 		for k, v := range a {
 		for k, v := range a {
 			kUpper := strings.Title(k) // Just so we consistently supply / receive the same values, uppercase the first letter.
 			kUpper := strings.Title(k) // Just so we consistently supply / receive the same values, uppercase the first letter.
-			err := SetCustomPricingField(c, kUpper, v)
-			if err != nil {
-				return nil, err
+			vstr, ok := v.(string)
+			if ok {
+				err := SetCustomPricingField(c, kUpper, vstr)
+				if err != nil {
+					return nil, err
+				}
+			} else {
+				sci := v.(map[string]interface{})
+				sc := make(map[string]string)
+				for k, val := range sci {
+					sc[k] = val.(string)
+				}
+				c.SharedCosts = sc //todo: support reflection/multiple map fields
 			}
 			}
 		}
 		}
 	}
 	}

+ 14 - 4
cloud/azureprovider.go

@@ -523,16 +523,26 @@ func (az *Azure) UpdateConfig(r io.Reader, updateType string) (*CustomPricing, e
 	if path == "" {
 	if path == "" {
 		path = "/models/"
 		path = "/models/"
 	}
 	}
-	a := make(map[string]string)
+	a := make(map[string]interface{})
 	err = json.NewDecoder(r).Decode(&a)
 	err = json.NewDecoder(r).Decode(&a)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
 	for k, v := range a {
 	for k, v := range a {
 		kUpper := strings.Title(k) // Just so we consistently supply / receive the same values, uppercase the first letter.
 		kUpper := strings.Title(k) // Just so we consistently supply / receive the same values, uppercase the first letter.
-		err := SetCustomPricingField(c, kUpper, v)
-		if err != nil {
-			return nil, err
+		vstr, ok := v.(string)
+		if ok {
+			err := SetCustomPricingField(c, kUpper, vstr)
+			if err != nil {
+				return nil, err
+			}
+		} else {
+			sci := v.(map[string]interface{})
+			sc := make(map[string]string)
+			for k, val := range sci {
+				sc[k] = val.(string)
+			}
+			c.SharedCosts = sc //todo: support reflection/multiple map fields
 		}
 		}
 	}
 	}
 	cj, err := json.Marshal(c)
 	cj, err := json.Marshal(c)

+ 14 - 4
cloud/customprovider.go

@@ -63,16 +63,26 @@ func (cp *CustomProvider) UpdateConfig(r io.Reader, updateType string) (*CustomP
 	if path == "" {
 	if path == "" {
 		path = "/models/"
 		path = "/models/"
 	}
 	}
-	a := make(map[string]string)
+	a := make(map[string]interface{})
 	err = json.NewDecoder(r).Decode(&a)
 	err = json.NewDecoder(r).Decode(&a)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
 	for k, v := range a {
 	for k, v := range a {
 		kUpper := strings.Title(k) // Just so we consistently supply / receive the same values, uppercase the first letter.
 		kUpper := strings.Title(k) // Just so we consistently supply / receive the same values, uppercase the first letter.
-		err := SetCustomPricingField(c, kUpper, v)
-		if err != nil {
-			return nil, err
+		vstr, ok := v.(string)
+		if ok {
+			err := SetCustomPricingField(c, kUpper, vstr)
+			if err != nil {
+				return nil, err
+			}
+		} else {
+			sci := v.(map[string]interface{})
+			sc := make(map[string]string)
+			for k, val := range sci {
+				sc[k] = val.(string)
+			}
+			c.SharedCosts = sc //todo: support reflection/multiple map fields
 		}
 		}
 	}
 	}
 
 

+ 14 - 4
cloud/gcpprovider.go

@@ -148,16 +148,26 @@ func (gcp *GCP) UpdateConfig(r io.Reader, updateType string) (*CustomPricing, er
 			return nil, err
 			return nil, err
 		}
 		}
 	} else {
 	} else {
-		a := make(map[string]string)
+		a := make(map[string]interface{})
 		err = json.NewDecoder(r).Decode(&a)
 		err = json.NewDecoder(r).Decode(&a)
 		if err != nil {
 		if err != nil {
 			return nil, err
 			return nil, err
 		}
 		}
 		for k, v := range a {
 		for k, v := range a {
 			kUpper := strings.Title(k) // Just so we consistently supply / receive the same values, uppercase the first letter.
 			kUpper := strings.Title(k) // Just so we consistently supply / receive the same values, uppercase the first letter.
-			err := SetCustomPricingField(c, kUpper, v)
-			if err != nil {
-				return nil, err
+			vstr, ok := v.(string)
+			if ok {
+				err := SetCustomPricingField(c, kUpper, vstr)
+				if err != nil {
+					return nil, err
+				}
+			} else {
+				sci := v.(map[string]interface{})
+				sc := make(map[string]string)
+				for k, val := range sci {
+					sc[k] = val.(string)
+				}
+				c.SharedCosts = sc //todo: support reflection/multiple map fields
 			}
 			}
 		}
 		}
 	}
 	}

+ 38 - 37
cloud/provider.go

@@ -110,43 +110,44 @@ type OutOfClusterAllocation struct {
 }
 }
 
 
 type CustomPricing struct {
 type CustomPricing struct {
-	Provider              string `json:"provider"`
-	Description           string `json:"description"`
-	CPU                   string `json:"CPU"`
-	SpotCPU               string `json:"spotCPU"`
-	RAM                   string `json:"RAM"`
-	SpotRAM               string `json:"spotRAM"`
-	GPU                   string `json:"GPU"`
-	SpotGPU               string `json:"spotGPU"`
-	Storage               string `json:"storage"`
-	ZoneNetworkEgress     string `json:"zoneNetworkEgress"`
-	RegionNetworkEgress   string `json:"regionNetworkEgress"`
-	InternetNetworkEgress string `json:"internetNetworkEgress"`
-	SpotLabel             string `json:"spotLabel,omitempty"`
-	SpotLabelValue        string `json:"spotLabelValue,omitempty"`
-	GpuLabel              string `json:"gpuLabel,omitempty"`
-	GpuLabelValue         string `json:"gpuLabelValue,omitempty"`
-	ServiceKeyName        string `json:"awsServiceKeyName,omitempty"`
-	ServiceKeySecret      string `json:"awsServiceKeySecret,omitempty"`
-	SpotDataRegion        string `json:"awsSpotDataRegion,omitempty"`
-	SpotDataBucket        string `json:"awsSpotDataBucket,omitempty"`
-	SpotDataPrefix        string `json:"awsSpotDataPrefix,omitempty"`
-	ProjectID             string `json:"projectID,omitempty"`
-	AthenaBucketName      string `json:"athenaBucketName"`
-	AthenaRegion          string `json:"athenaRegion"`
-	AthenaDatabase        string `json:"athenaDatabase"`
-	AthenaTable           string `json:"athenaTable"`
-	BillingDataDataset    string `json:"billingDataDataset,omitempty"`
-	CustomPricesEnabled   string `json:"customPricesEnabled"`
-	AzureSubscriptionID   string `json:"azureSubscriptionID"`
-	AzureClientID         string `json:"azureClientID"`
-	AzureClientSecret     string `json:"azureClientSecret"`
-	AzureTenantID         string `json:"azureTenantID"`
-	AzureBillingRegion    string `json:"azureBillingRegion"`
-	CurrencyCode          string `json:"currencyCode"`
-	Discount              string `json:"discount"`
-	NegotiatedDiscount    string `json:"negotiatedDiscount"`
-	ClusterName           string `json:"clusterName"`
+	Provider              string            `json:"provider"`
+	Description           string            `json:"description"`
+	CPU                   string            `json:"CPU"`
+	SpotCPU               string            `json:"spotCPU"`
+	RAM                   string            `json:"RAM"`
+	SpotRAM               string            `json:"spotRAM"`
+	GPU                   string            `json:"GPU"`
+	SpotGPU               string            `json:"spotGPU"`
+	Storage               string            `json:"storage"`
+	ZoneNetworkEgress     string            `json:"zoneNetworkEgress"`
+	RegionNetworkEgress   string            `json:"regionNetworkEgress"`
+	InternetNetworkEgress string            `json:"internetNetworkEgress"`
+	SpotLabel             string            `json:"spotLabel,omitempty"`
+	SpotLabelValue        string            `json:"spotLabelValue,omitempty"`
+	GpuLabel              string            `json:"gpuLabel,omitempty"`
+	GpuLabelValue         string            `json:"gpuLabelValue,omitempty"`
+	ServiceKeyName        string            `json:"awsServiceKeyName,omitempty"`
+	ServiceKeySecret      string            `json:"awsServiceKeySecret,omitempty"`
+	SpotDataRegion        string            `json:"awsSpotDataRegion,omitempty"`
+	SpotDataBucket        string            `json:"awsSpotDataBucket,omitempty"`
+	SpotDataPrefix        string            `json:"awsSpotDataPrefix,omitempty"`
+	ProjectID             string            `json:"projectID,omitempty"`
+	AthenaBucketName      string            `json:"athenaBucketName"`
+	AthenaRegion          string            `json:"athenaRegion"`
+	AthenaDatabase        string            `json:"athenaDatabase"`
+	AthenaTable           string            `json:"athenaTable"`
+	BillingDataDataset    string            `json:"billingDataDataset,omitempty"`
+	CustomPricesEnabled   string            `json:"customPricesEnabled"`
+	AzureSubscriptionID   string            `json:"azureSubscriptionID"`
+	AzureClientID         string            `json:"azureClientID"`
+	AzureClientSecret     string            `json:"azureClientSecret"`
+	AzureTenantID         string            `json:"azureTenantID"`
+	AzureBillingRegion    string            `json:"azureBillingRegion"`
+	CurrencyCode          string            `json:"currencyCode"`
+	Discount              string            `json:"discount"`
+	NegotiatedDiscount    string            `json:"negotiatedDiscount"`
+	SharedCosts           map[string]string `json:"sharedCost"`
+	ClusterName           string            `json:"clusterName"`
 }
 }
 
 
 // Provider represents a k8s provider.
 // Provider represents a k8s provider.