Jelajahi Sumber

Merge branch 'develop' of https://github.com/kubecost/cost-model into develop

Ajay Tripathy 5 tahun lalu
induk
melakukan
b946a977ba
3 mengubah file dengan 12 tambahan dan 4 penghapusan
  1. 8 0
      pkg/cloud/csvprovider.go
  2. 1 1
      pkg/cloud/gcpprovider.go
  3. 3 3
      pkg/costmodel/aggregation.go

+ 8 - 0
pkg/cloud/csvprovider.go

@@ -278,6 +278,14 @@ func PVValueFromMapField(m string, n *v1.PersistentVolume) string {
 			klog.V(4).Infof("[ERROR] Unsupported InstanceIDField %s in CSV For PV", m)
 			return ""
 		}
+	} else if len(mf) > 2 && mf[0] == "spec" {
+		if mf[1] == "capacity" && mf[2] == "storage" {
+			skey := n.Spec.Capacity["storage"]
+			return skey.String()
+		} else {
+			klog.V(4).Infof("[ERROR] Unsupported InstanceIDField %s in CSV For PV", m)
+			return ""
+		}
 	} else {
 		klog.V(4).Infof("[ERROR] Unsupported InstanceIDField %s in CSV For PV", m)
 		return ""

+ 1 - 1
pkg/cloud/gcpprovider.go

@@ -644,7 +644,7 @@ func (gcp *GCP) parsePage(r io.Reader, inputKeys map[string]Key, pvKeys map[stri
 				if instanceType == "ssd" && !strings.Contains(product.Description, "Regional") { // TODO: support regional
 					lastRateIndex := len(product.PricingInfo[0].PricingExpression.TieredRates) - 1
 					var nanos float64
-					if len(product.PricingInfo) > 0 {
+					if lastRateIndex > -1 && len(product.PricingInfo) > 0 {
 						nanos = product.PricingInfo[0].PricingExpression.TieredRates[lastRateIndex].UnitPrice.Nanos
 					} else {
 						continue

+ 3 - 3
pkg/costmodel/aggregation.go

@@ -2012,13 +2012,13 @@ func (a *Accesses) AggregateCostModelHandler(w http.ResponseWriter, r *http.Requ
 
 	// aggregation subfield is required when aggregation field is "label"
 	if (field == "label" || field == "annotation") && len(subfields) == 0 {
-		WriteError(w, BadRequest("Missing aggregation field parameter"))
+		WriteError(w, BadRequest("Missing aggregation subfield parameter"))
 		return
 	}
 
-	// enforce one of four available rate options
+	// enforce one of the available rate options
 	if opts.Rate != "" && opts.Rate != "hourly" && opts.Rate != "daily" && opts.Rate != "monthly" {
-		WriteError(w, BadRequest("Missing aggregation field parameter"))
+		WriteError(w, BadRequest("Rate parameter only supports: hourly, daily, monthly or empty"))
 		return
 	}