Browse Source

Merge pull request #1020 from kubecost/master

Master
Ajay Tripathy 4 năm trước cách đây
mục cha
commit
742f9c6149
4 tập tin đã thay đổi với 36 bổ sung1 xóa
  1. 2 0
      configs/pricing_schema_pv.csv
  2. 3 0
      pkg/costmodel/router.go
  3. 1 1
      pkg/env/costmodelenv.go
  4. 30 0
      test/cloud_test.go

+ 2 - 0
configs/pricing_schema_pv.csv

@@ -0,0 +1,2 @@
+EndTimestamp,InstanceID,Region,AssetClass,InstanceIDField,InstanceType,MarketPriceHourly,Version
+2019-04-17 23:34:22 UTC,pvc-08e1f205-d7a9-4430-90fc-7b3965a18c4d,,pv,metadata.name,,0.1337,

+ 3 - 0
pkg/costmodel/router.go

@@ -1092,6 +1092,9 @@ func (a *Accesses) GetPod(w http.ResponseWriter, r *http.Request, ps httprouter.
 	// TODO: ClusterCache API could probably afford to have some better filtering
 	allPods := a.ClusterCache.GetAllPods()
 	for _, pod := range allPods {
+		for _, container := range pod.Spec.Containers {
+			container.Env = make([]v1.EnvVar, 0)
+		}
 		if pod.Namespace == podNamespace && pod.Name == podName {
 			body, err := json.Marshal(pod)
 			if err != nil {

+ 1 - 1
pkg/env/costmodelenv.go

@@ -128,7 +128,7 @@ func GetPricingConfigmapName() string {
 // GetAWSAccessKeyID returns the environment variable value for AWSAccessKeyIDEnvVar which represents
 // the AWS access key for authentication
 func GetAppVersion() string {
-	return Get(AppVersionEnvVar, "1.89.0-rc.0")
+	return Get(AppVersionEnvVar, "1.89.0-rc.1")
 }
 
 // IsEmitNamespaceAnnotationsMetric returns true if cost-model is configured to emit the kube_namespace_annotations metric

+ 30 - 0
test/cloud_test.go

@@ -93,6 +93,36 @@ func TestNodeValueFromMapField(t *testing.T) {
 
 }
 
+func TestPVPriceFromCSV(t *testing.T) {
+	nameWant := "pvc-08e1f205-d7a9-4430-90fc-7b3965a18c4d"
+	pv := &v1.PersistentVolume{}
+	pv.Name = nameWant
+
+	confMan := config.NewConfigFileManager(&config.ConfigFileManagerOpts{
+		LocalConfigPath: "./",
+	})
+
+	wantPrice := "0.1337"
+	c := &cloud.CSVProvider{
+		CSVLocation: "../configs/pricing_schema_pv.csv",
+		CustomProvider: &cloud.CustomProvider{
+			Config: cloud.NewProviderConfig(confMan, "../configs/default.json"),
+		},
+	}
+	c.DownloadPricingData()
+	k := c.GetPVKey(pv, make(map[string]string), "")
+	resPV, err := c.PVPricing(k)
+	if err != nil {
+		t.Errorf("Error in NodePricing: %s", err.Error())
+	} else {
+		gotPrice := resPV.Cost
+		if gotPrice != wantPrice {
+			t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
+		}
+	}
+
+}
+
 func TestNodePriceFromCSV(t *testing.T) {
 	providerIDWant := "providerid"
 	nameWant := "gke-standard-cluster-1-pool-1-91dc432d-cg69"