Преглед изворни кода

fixing merge conflict with Asset field cleanup PR and if storage class dont match set it to default of __unknown__ storage class

Signed-off-by: Alan Rodrigues <alanr5691@yahoo.com>
Alan Rodrigues пре 3 година
родитељ
комит
0c279b435a
3 измењених фајлова са 35 додато и 34 уклоњено
  1. 15 14
      pkg/kubecost/asset.go
  2. 1 1
      pkg/kubecost/asset_json.go
  3. 19 19
      pkg/kubecost/kubecost_codecs.go

+ 15 - 14
pkg/kubecost/asset.go

@@ -1059,12 +1059,12 @@ func (cm *ClusterManagement) String() string {
 
 
 // Disk represents an in-cluster disk Asset
 // Disk represents an in-cluster disk Asset
 type Disk struct {
 type Disk struct {
-	labels       AssetLabels
-	properties   *AssetProperties
-	start        time.Time
-	end          time.Time
-	window       Window
-	adjustment   float64
+	Labels       AssetLabels
+	Properties   *AssetProperties
+	Start        time.Time
+	End          time.Time
+	Window       Window
+	Adjustment   float64
 	Cost         float64
 	Cost         float64
 	ByteHours    float64
 	ByteHours    float64
 	Local        float64
 	Local        float64
@@ -1262,20 +1262,21 @@ func (d *Disk) add(that *Disk) {
 
 
 	d.ByteHours += that.ByteHours
 	d.ByteHours += that.ByteHours
 
 
-	if that.StorageClass != UnknownStorageClass {
-		d.StorageClass = that.StorageClass
+	// If storage class don't match default it to Unknown storage class
+	if d.StorageClass != that.StorageClass {
+		d.StorageClass = UnknownStorageClass
 	}
 	}
 }
 }
 
 
 // Clone returns a cloned instance of the Asset
 // Clone returns a cloned instance of the Asset
 func (d *Disk) Clone() Asset {
 func (d *Disk) Clone() Asset {
 	return &Disk{
 	return &Disk{
-		properties:   d.properties.Clone(),
-		labels:       d.labels.Clone(),
-		start:        d.start,
-		end:          d.end,
-		window:       d.window.Clone(),
-		adjustment:   d.adjustment,
+		Properties:   d.Properties.Clone(),
+		Labels:       d.Labels.Clone(),
+		Start:        d.Start,
+		End:          d.End,
+		Window:       d.Window.Clone(),
+		Adjustment:   d.Adjustment,
 		Cost:         d.Cost,
 		Cost:         d.Cost,
 		ByteHours:    d.ByteHours,
 		ByteHours:    d.ByteHours,
 		Local:        d.Local,
 		Local:        d.Local,

+ 1 - 1
pkg/kubecost/asset_json.go

@@ -260,7 +260,7 @@ func (d *Disk) MarshalJSON() ([]byte, error) {
 	jsonEncodeFloat64(buffer, "byteHours", d.ByteHours, ",")
 	jsonEncodeFloat64(buffer, "byteHours", d.ByteHours, ",")
 	jsonEncodeFloat64(buffer, "bytes", d.Bytes(), ",")
 	jsonEncodeFloat64(buffer, "bytes", d.Bytes(), ",")
 	jsonEncode(buffer, "breakdown", d.Breakdown, ",")
 	jsonEncode(buffer, "breakdown", d.Breakdown, ",")
-	jsonEncodeFloat64(buffer, "adjustment", d.Adjustment(), ",")
+	jsonEncodeFloat64(buffer, "adjustment", d.Adjustment, ",")
 	jsonEncodeFloat64(buffer, "totalCost", d.TotalCost(), ",")
 	jsonEncodeFloat64(buffer, "totalCost", d.TotalCost(), ",")
 	jsonEncodeString(buffer, "storageClass", d.StorageClass, "")
 	jsonEncodeString(buffer, "storageClass", d.StorageClass, "")
 	buffer.WriteString("}")
 	buffer.WriteString("}")

+ 19 - 19
pkg/kubecost/kubecost_codecs.go

@@ -33,6 +33,9 @@ const (
 )
 )
 
 
 const (
 const (
+	// AssetsCodecVersion is used for any resources listed in the Assets version set
+	AssetsCodecVersion uint8 = 17
+
 	// AllocationCodecVersion is used for any resources listed in the Allocation version set
 	// AllocationCodecVersion is used for any resources listed in the Allocation version set
 	AllocationCodecVersion uint8 = 15
 	AllocationCodecVersion uint8 = 15
 
 
@@ -41,9 +44,6 @@ const (
 
 
 	// DefaultCodecVersion is used for any resources listed in the Default version set
 	// DefaultCodecVersion is used for any resources listed in the Default version set
 	DefaultCodecVersion uint8 = 15
 	DefaultCodecVersion uint8 = 15
-
-	// AssetsCodecVersion is used for any resources listed in the Assets version set
-	AssetsCodecVersion uint8 = 17
 )
 )
 
 
 //--------------------------------------------------------------------------
 //--------------------------------------------------------------------------
@@ -4887,14 +4887,14 @@ func (target *Disk) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
 	buff.WriteUInt8(AssetsCodecVersion) // version
 	buff.WriteUInt8(AssetsCodecVersion) // version
 
 
 	// --- [begin][write][alias](AssetLabels) ---
 	// --- [begin][write][alias](AssetLabels) ---
-	if map[string]string(target.labels) == nil {
+	if map[string]string(target.Labels) == nil {
 		buff.WriteUInt8(uint8(0)) // write nil byte
 		buff.WriteUInt8(uint8(0)) // write nil byte
 	} else {
 	} else {
 		buff.WriteUInt8(uint8(1)) // write non-nil byte
 		buff.WriteUInt8(uint8(1)) // write non-nil byte
 
 
 		// --- [begin][write][map](map[string]string) ---
 		// --- [begin][write][map](map[string]string) ---
-		buff.WriteInt(len(map[string]string(target.labels))) // map length
-		for v, z := range map[string]string(target.labels) {
+		buff.WriteInt(len(map[string]string(target.Labels))) // map length
+		for v, z := range map[string]string(target.Labels) {
 			if ctx.IsStringTable() {
 			if ctx.IsStringTable() {
 				a := ctx.Table.AddOrGet(v)
 				a := ctx.Table.AddOrGet(v)
 				buff.WriteInt(a) // write table index
 				buff.WriteInt(a) // write table index
@@ -4913,14 +4913,14 @@ func (target *Disk) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
 	}
 	}
 	// --- [end][write][alias](AssetLabels) ---
 	// --- [end][write][alias](AssetLabels) ---
 
 
-	if target.properties == nil {
+	if target.Properties == nil {
 		buff.WriteUInt8(uint8(0)) // write nil byte
 		buff.WriteUInt8(uint8(0)) // write nil byte
 	} else {
 	} else {
 		buff.WriteUInt8(uint8(1)) // write non-nil byte
 		buff.WriteUInt8(uint8(1)) // write non-nil byte
 
 
 		// --- [begin][write][struct](AssetProperties) ---
 		// --- [begin][write][struct](AssetProperties) ---
 		buff.WriteInt(0) // [compatibility, unused]
 		buff.WriteInt(0) // [compatibility, unused]
-		errA := target.properties.MarshalBinaryWithContext(ctx)
+		errA := target.Properties.MarshalBinaryWithContext(ctx)
 		if errA != nil {
 		if errA != nil {
 			return errA
 			return errA
 		}
 		}
@@ -4928,7 +4928,7 @@ func (target *Disk) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
 
 
 	}
 	}
 	// --- [begin][write][reference](time.Time) ---
 	// --- [begin][write][reference](time.Time) ---
-	c, errB := target.start.MarshalBinary()
+	c, errB := target.Start.MarshalBinary()
 	if errB != nil {
 	if errB != nil {
 		return errB
 		return errB
 	}
 	}
@@ -4937,7 +4937,7 @@ func (target *Disk) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
 	// --- [end][write][reference](time.Time) ---
 	// --- [end][write][reference](time.Time) ---
 
 
 	// --- [begin][write][reference](time.Time) ---
 	// --- [begin][write][reference](time.Time) ---
-	d, errC := target.end.MarshalBinary()
+	d, errC := target.End.MarshalBinary()
 	if errC != nil {
 	if errC != nil {
 		return errC
 		return errC
 	}
 	}
@@ -4947,13 +4947,13 @@ func (target *Disk) MarshalBinaryWithContext(ctx *EncodingContext) (err error) {
 
 
 	// --- [begin][write][struct](Window) ---
 	// --- [begin][write][struct](Window) ---
 	buff.WriteInt(0) // [compatibility, unused]
 	buff.WriteInt(0) // [compatibility, unused]
-	errD := target.window.MarshalBinaryWithContext(ctx)
+	errD := target.Window.MarshalBinaryWithContext(ctx)
 	if errD != nil {
 	if errD != nil {
 		return errD
 		return errD
 	}
 	}
 	// --- [end][write][struct](Window) ---
 	// --- [end][write][struct](Window) ---
 
 
-	buff.WriteFloat64(target.adjustment) // write float64
+	buff.WriteFloat64(target.Adjustment) // write float64
 	buff.WriteFloat64(target.Cost)       // write float64
 	buff.WriteFloat64(target.Cost)       // write float64
 	buff.WriteFloat64(target.ByteHours)  // write float64
 	buff.WriteFloat64(target.ByteHours)  // write float64
 	buff.WriteFloat64(target.Local)      // write float64
 	buff.WriteFloat64(target.Local)      // write float64
@@ -5071,11 +5071,11 @@ func (target *Disk) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)
 		// --- [end][read][map](map[string]string) ---
 		// --- [end][read][map](map[string]string) ---
 
 
 	}
 	}
-	target.labels = AssetLabels(a)
+	target.Labels = AssetLabels(a)
 	// --- [end][read][alias](AssetLabels) ---
 	// --- [end][read][alias](AssetLabels) ---
 
 
 	if buff.ReadUInt8() == uint8(0) {
 	if buff.ReadUInt8() == uint8(0) {
-		target.properties = nil
+		target.Properties = nil
 	} else {
 	} else {
 		// --- [begin][read][struct](AssetProperties) ---
 		// --- [begin][read][struct](AssetProperties) ---
 		l := &AssetProperties{}
 		l := &AssetProperties{}
@@ -5084,7 +5084,7 @@ func (target *Disk) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)
 		if errA != nil {
 		if errA != nil {
 			return errA
 			return errA
 		}
 		}
-		target.properties = l
+		target.Properties = l
 		// --- [end][read][struct](AssetProperties) ---
 		// --- [end][read][struct](AssetProperties) ---
 
 
 	}
 	}
@@ -5096,7 +5096,7 @@ func (target *Disk) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)
 	if errB != nil {
 	if errB != nil {
 		return errB
 		return errB
 	}
 	}
-	target.start = *m
+	target.Start = *m
 	// --- [end][read][reference](time.Time) ---
 	// --- [end][read][reference](time.Time) ---
 
 
 	// --- [begin][read][reference](time.Time) ---
 	// --- [begin][read][reference](time.Time) ---
@@ -5107,7 +5107,7 @@ func (target *Disk) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)
 	if errC != nil {
 	if errC != nil {
 		return errC
 		return errC
 	}
 	}
-	target.end = *p
+	target.End = *p
 	// --- [end][read][reference](time.Time) ---
 	// --- [end][read][reference](time.Time) ---
 
 
 	// --- [begin][read][struct](Window) ---
 	// --- [begin][read][struct](Window) ---
@@ -5117,11 +5117,11 @@ func (target *Disk) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)
 	if errD != nil {
 	if errD != nil {
 		return errD
 		return errD
 	}
 	}
-	target.window = *s
+	target.Window = *s
 	// --- [end][read][struct](Window) ---
 	// --- [end][read][struct](Window) ---
 
 
 	t := buff.ReadFloat64() // read float64
 	t := buff.ReadFloat64() // read float64
-	target.adjustment = t
+	target.Adjustment = t
 
 
 	u := buff.ReadFloat64() // read float64
 	u := buff.ReadFloat64() // read float64
 	target.Cost = u
 	target.Cost = u