Browse Source

Merge pull request #135 from kubecost/AjayTripathy-sc-logging-improvements

Ajay tripathy sc logging improvements
Ajay Tripathy 6 years ago
parent
commit
2f5317902b
5 changed files with 24 additions and 0 deletions
  1. 8 0
      cloud/awsprovider.go
  2. 4 0
      cloud/azureprovider.go
  3. 8 0
      cloud/gcpprovider.go
  4. 1 0
      cloud/provider.go
  5. 3 0
      costmodel/cluster.go

+ 8 - 0
cloud/awsprovider.go

@@ -378,6 +378,10 @@ func (k *awsKey) Features() string {
 }
 
 func (aws *AWS) PVPricing(pvk PVKey) (*PV, error) {
+	if pvk.GetStorageClass() == "" {
+		klog.V(3).Infof("Disk in %s does not have a storageclass set, cannot look up pricing info.", pvk.Features())
+		return &PV{}, nil
+	}
 	pricing, ok := aws.Pricing[pvk.Features()]
 	if !ok {
 		klog.V(2).Infof("Persistent Volume pricing not found for %s", pvk.Features())
@@ -399,6 +403,10 @@ func (aws *AWS) GetPVKey(pv *v1.PersistentVolume, parameters map[string]string)
 	}
 }
 
+func (key *awsPVKey) GetStorageClass() string {
+	return key.StorageClassName
+}
+
 func (key *awsPVKey) Features() string {
 	storageClass := key.StorageClassName
 	if storageClass == "standard" {

+ 4 - 0
cloud/azureprovider.go

@@ -435,6 +435,10 @@ func (az *Azure) GetPVKey(pv *v1.PersistentVolume, parameters map[string]string)
 	}
 }
 
+func (key *azurePvKey) GetStorageClass() string {
+	return key.StorageClass
+}
+
 func (key *azurePvKey) Features() string {
 	storageClass := key.StorageClassParameters["type"]
 	if storageClass == "pd-ssd" {

+ 8 - 0
cloud/gcpprovider.go

@@ -694,6 +694,10 @@ func (gcp *GCP) DownloadPricingData() error {
 }
 
 func (gcp *GCP) PVPricing(pvk PVKey) (*PV, error) {
+	if pvk.GetStorageClass() == "" {
+		klog.V(3).Infof("Disk in %s does not have a storageclass set, cannot look up pricing info.", pvk.Features())
+		return &PV{}, nil
+	}
 	gcp.DownloadPricingDataLock.RLock()
 	defer gcp.DownloadPricingDataLock.RUnlock()
 	pricing, ok := gcp.Pricing[pvk.Features()]
@@ -710,6 +714,10 @@ type pvKey struct {
 	StorageClassParameters map[string]string
 }
 
+func (key *pvKey) GetStorageClass() string {
+	return key.StorageClass
+}
+
 func (gcp *GCP) GetPVKey(pv *v1.PersistentVolume, parameters map[string]string) PVKey {
 	return &pvKey{
 		Labels:                 pv.Labels,

+ 1 - 0
cloud/provider.go

@@ -62,6 +62,7 @@ type Key interface {
 
 type PVKey interface {
 	Features() string
+	GetStorageClass() string
 }
 
 // OutOfClusterAllocation represents a cloud provider cost not associated with kubernetes

+ 3 - 0
costmodel/cluster.go

@@ -90,6 +90,9 @@ func resultToTotal(qr interface{}) ([][]string, error) {
 	if !ok {
 		return nil, fmt.Errorf("Improperly formatted results from prometheus, result field is not a slice")
 	}
+	if len(results) == 0 {
+		return nil, fmt.Errorf("Not enough data available in the selected time range")
+	}
 	val, ok := results[0].(map[string]interface{})["value"]
 	totals := [][]string{}
 	if !ok {