Explorar o código

Remove klog from csvprovider

Also changes info logs prefixed with ERROR to actually
be error logs.

This change was performed because we are trying to deprecate
klog and prefer the internal cost-model/pkg/log
Michael Dresser %!s(int64=5) %!d(string=hai) anos
pai
achega
f0ca42ef76
Modificáronse 1 ficheiros con 13 adicións e 14 borrados
  1. 13 14
      pkg/cloud/csvprovider.go

+ 13 - 14
pkg/cloud/csvprovider.go

@@ -19,7 +19,6 @@ import (
 	"github.com/aws/aws-sdk-go/service/s3"
 	"github.com/aws/aws-sdk-go/service/s3"
 	"github.com/kubecost/cost-model/pkg/log"
 	"github.com/kubecost/cost-model/pkg/log"
 	v1 "k8s.io/api/core/v1"
 	v1 "k8s.io/api/core/v1"
-	"k8s.io/klog"
 
 
 	"github.com/jszwec/csvutil"
 	"github.com/jszwec/csvutil"
 )
 )
@@ -90,7 +89,7 @@ func (c *CSVProvider) DownloadPricingData() error {
 		csvr, csverr = GetCsv(c.CSVLocation)
 		csvr, csverr = GetCsv(c.CSVLocation)
 	}
 	}
 	if csverr != nil {
 	if csverr != nil {
-		klog.Infof("Error reading csv at %s: %s", c.CSVLocation, csverr)
+		log.Infof("Error reading csv at %s: %s", c.CSVLocation, csverr)
 		c.Pricing = pricing
 		c.Pricing = pricing
 		c.NodeClassPricing = nodeclasspricing
 		c.NodeClassPricing = nodeclasspricing
 		c.NodeClassCount = nodeclasscount
 		c.NodeClassCount = nodeclasscount
@@ -118,20 +117,20 @@ func (c *CSVProvider) DownloadPricingData() error {
 		} else if err == csvutil.ErrFieldCount || (isCsvParseErr && csvParseErr.Err == csv.ErrFieldCount) {
 		} else if err == csvutil.ErrFieldCount || (isCsvParseErr && csvParseErr.Err == csv.ErrFieldCount) {
 			rec := dec.Record()
 			rec := dec.Record()
 			if len(rec) != 1 {
 			if len(rec) != 1 {
-				klog.V(2).Infof("Expected %d price info fields but received %d: %s", fieldsPerRecord, len(rec), rec)
+				log.Infof("Expected %d price info fields but received %d: %s", fieldsPerRecord, len(rec), rec)
 				continue
 				continue
 			}
 			}
 			if strings.Index(rec[0], "#") == 0 {
 			if strings.Index(rec[0], "#") == 0 {
 				continue
 				continue
 			} else {
 			} else {
-				klog.V(3).Infof("skipping non-CSV line: %s", rec)
+				log.Infof("skipping non-CSV line: %s", rec)
 				continue
 				continue
 			}
 			}
 		} else if err != nil {
 		} else if err != nil {
-			klog.V(2).Infof("Error during spot info decode: %+v", err)
+			log.Infof("Error during spot info decode: %+v", err)
 			continue
 			continue
 		}
 		}
-		klog.V(4).Infof("Found price info %+v", p)
+		log.Infof("Found price info %+v", p)
 		key := strings.ToLower(p.InstanceID)
 		key := strings.ToLower(p.InstanceID)
 		if p.Region != "" { // strip the casing from region and add to key.
 		if p.Region != "" { // strip the casing from region and add to key.
 			key = fmt.Sprintf("%s,%s", strings.ToLower(p.Region), strings.ToLower(p.InstanceID))
 			key = fmt.Sprintf("%s,%s", strings.ToLower(p.Region), strings.ToLower(p.InstanceID))
@@ -161,7 +160,7 @@ func (c *CSVProvider) DownloadPricingData() error {
 
 
 			c.NodeMapField = p.InstanceIDField
 			c.NodeMapField = p.InstanceIDField
 		} else {
 		} else {
-			klog.Infof("Unrecognized asset class %s, defaulting to node", p.AssetClass)
+			log.Infof("Unrecognized asset class %s, defaulting to node", p.AssetClass)
 			pricing[key] = &p
 			pricing[key] = &p
 			c.NodeMapField = p.InstanceIDField
 			c.NodeMapField = p.InstanceIDField
 		}
 		}
@@ -217,7 +216,7 @@ func (c *CSVProvider) NodePricing(key Key) (*Node, error) {
 	}
 	}
 	classKey := key.Features() // Use node attributes to try and do a class match
 	classKey := key.Features() // Use node attributes to try and do a class match
 	if cost, ok := c.NodeClassPricing[classKey]; ok {
 	if cost, ok := c.NodeClassPricing[classKey]; ok {
-		klog.Infof("Unable to find provider ID `%s`, using features:`%s`", key.ID(), key.Features())
+		log.Infof("Unable to find provider ID `%s`, using features:`%s`", key.ID(), key.Features())
 		return &Node{
 		return &Node{
 			Cost:        fmt.Sprintf("%f", cost),
 			Cost:        fmt.Sprintf("%f", cost),
 			PricingType: CsvClass,
 			PricingType: CsvClass,
@@ -233,7 +232,7 @@ func NodeValueFromMapField(m string, n *v1.Node, useRegion bool) string {
 		if region, ok := util.GetRegion(n.Labels); ok {
 		if region, ok := util.GetRegion(n.Labels); ok {
 			toReturn = region + ","
 			toReturn = region + ","
 		} else {
 		} else {
-			klog.Infof("[ERROR] Getting region based on labels failed")
+			log.Errorf("Getting region based on labels failed")
 		}
 		}
 	}
 	}
 	if len(mf) == 2 && mf[0] == "spec" && mf[1] == "providerID" {
 	if len(mf) == 2 && mf[0] == "spec" && mf[1] == "providerID" {
@@ -258,11 +257,11 @@ func NodeValueFromMapField(m string, n *v1.Node, useRegion bool) string {
 			akey := strings.Join(mf[2:len(mf)], "")
 			akey := strings.Join(mf[2:len(mf)], "")
 			return toReturn + n.Annotations[akey]
 			return toReturn + n.Annotations[akey]
 		} else {
 		} else {
-			klog.Infof("[ERROR] Unsupported InstanceIDField %s in CSV For Node", m)
+			log.Errorf("Unsupported InstanceIDField %s in CSV For Node", m)
 			return ""
 			return ""
 		}
 		}
 	} else {
 	} else {
-		klog.Infof("[ERROR] Unsupported InstanceIDField %s in CSV For Node", m)
+		log.Errorf("Unsupported InstanceIDField %s in CSV For Node", m)
 		return ""
 		return ""
 	}
 	}
 }
 }
@@ -279,7 +278,7 @@ func PVValueFromMapField(m string, n *v1.PersistentVolume) string {
 			akey := strings.Join(mf[2:len(mf)], "")
 			akey := strings.Join(mf[2:len(mf)], "")
 			return n.Annotations[akey]
 			return n.Annotations[akey]
 		} else {
 		} else {
-			klog.V(4).Infof("[ERROR] Unsupported InstanceIDField %s in CSV For PV", m)
+			log.Errorf("Unsupported InstanceIDField %s in CSV For PV", m)
 			return ""
 			return ""
 		}
 		}
 	} else if len(mf) > 2 && mf[0] == "spec" {
 	} else if len(mf) > 2 && mf[0] == "spec" {
@@ -291,7 +290,7 @@ func PVValueFromMapField(m string, n *v1.PersistentVolume) string {
 			return ""
 			return ""
 		}
 		}
 	} else {
 	} else {
-		klog.V(4).Infof("[ERROR] Unsupported InstanceIDField %s in CSV For PV", m)
+		log.Errorf("Unsupported InstanceIDField %s in CSV For PV", m)
 		return ""
 		return ""
 	}
 	}
 }
 }
@@ -342,7 +341,7 @@ func (c *CSVProvider) PVPricing(pvk PVKey) (*PV, error) {
 	defer c.DownloadPricingDataLock.RUnlock()
 	defer c.DownloadPricingDataLock.RUnlock()
 	pricing, ok := c.PricingPV[pvk.Features()]
 	pricing, ok := c.PricingPV[pvk.Features()]
 	if !ok {
 	if !ok {
-		klog.V(4).Infof("Persistent Volume pricing not found for %s: %s", pvk.GetStorageClass(), pvk.Features())
+		log.Infof("Persistent Volume pricing not found for %s: %s", pvk.GetStorageClass(), pvk.Features())
 		return &PV{}, nil
 		return &PV{}, nil
 	}
 	}
 	return &PV{
 	return &PV{