Sean Holcomb 5 лет назад
Родитель
Сommit
2ea98f7dfe

+ 3 - 3
pkg/costmodel/allocation.go

@@ -390,10 +390,10 @@ func (cm *CostModel) ComputeAllocation(start, end time.Time, resolution time.Dur
 					alloc.PVCost += cost / count
 
 					// record the amount of total PVBytes Hours attributable to a given PV
-					if alloc.Properties.PVBreakDown == nil {
-						alloc.Properties.PVBreakDown = map[string]kubecost.PVUsage{}
+					if alloc.Properties.PVBreakdown == nil {
+						alloc.Properties.PVBreakdown = map[string]kubecost.PVUsage{}
 					}
-					alloc.Properties.PVBreakDown[pvc.Volume.Name] = kubecost.PVUsage{
+					alloc.Properties.PVBreakdown[pvc.Volume.Name] = kubecost.PVUsage{
 						ByteHours: pvc.Bytes * hrs / count,
 						Cost:      cost / count,
 					}

+ 3 - 3
pkg/kubecost/allocation.go

@@ -1615,14 +1615,14 @@ func (a *Allocation) reconcileNodes(nodeByProviderID map[string]*Node) {
 }
 
 func (a *Allocation) reconcileDisks(diskByName map[string]*Disk) {
-	pvBreakDown := a.Properties.PVBreakDown
-	if pvBreakDown == nil {
+	pvBreakdown := a.Properties.PVBreakdown
+	if pvBreakdown == nil {
 		// No PV usage to reconcile
 		return
 	}
 	// Set PV Adjustment for allocation to 0 for idempotency
 	a.PVCostAdjustment = 0.0
-	for pvName, pvUsage := range pvBreakDown {
+	for pvName, pvUsage := range pvBreakdown {
 		disk, ok := diskByName[pvName]
 		if !ok {
 			// Failed to find disk in assets

+ 2 - 2
pkg/kubecost/allocation_test.go

@@ -701,8 +701,8 @@ func generateAllocationSet(start time.Time) *AllocationSet {
 	a22pqr6.Properties.Services = []string{"service1"}
 
 	// PV BreakDown
-	a22mno4.Properties.PVBreakDown = map[string]PVUsage{"disk1": {Cost: 2.5, ByteHours: 2.5 * gb}, "disk2": {Cost: 5, ByteHours: 5 * gb}}
-	a22mno5.Properties.PVBreakDown = map[string]PVUsage{"disk1": {Cost: 2.5, ByteHours: 2.5 * gb}, "disk2": {Cost: 5, ByteHours: 5 * gb}}
+	a22mno4.Properties.PVBreakdown = map[string]PVUsage{"disk1": {Cost: 2.5, ByteHours: 2.5 * gb}, "disk2": {Cost: 5, ByteHours: 5 * gb}}
+	a22mno5.Properties.PVBreakdown = map[string]PVUsage{"disk1": {Cost: 2.5, ByteHours: 2.5 * gb}, "disk2": {Cost: 5, ByteHours: 5 * gb}}
 
 	return NewAllocationSet(start, start.Add(day),
 		// idle

+ 20 - 1
pkg/kubecost/allocationprops.go

@@ -74,7 +74,7 @@ type AllocationProperties struct {
 	ProviderID     string                `json:"providerID,omitempty"`
 	Labels         AllocationLabels      `json:"allocationLabels,omitempty"`
 	Annotations    AllocationAnnotations `json:"allocationAnnotations,omitempty"`
-	PVBreakDown    map[string]PVUsage    `json:"pvBreakDown,omitempty"`
+	PVBreakdown    map[string]PVUsage    `json:"pvBreakDown,omitempty"`
 }
 
 // AllocationLabels is a schema-free mapping of key/value pairs that can be
@@ -125,6 +125,12 @@ func (p *AllocationProperties) Clone() *AllocationProperties {
 	}
 	clone.Annotations = annotations
 
+	pvBreakdown := make(map[string]PVUsage)
+	for k, v := range p.PVBreakdown {
+		pvBreakdown[k] = v
+	}
+	clone.PVBreakdown = pvBreakdown
+
 	return clone
 }
 
@@ -191,6 +197,19 @@ func (p *AllocationProperties) Equal(that *AllocationProperties) bool {
 		return false
 	}
 
+	pPVBreakdown := p.PVBreakdown
+	thatPVBreakdown := that.PVBreakdown
+	if len(pPVBreakdown) == len(thatPVBreakdown) {
+		for k, pv := range pPVBreakdown {
+			tv, ok := thatPVBreakdown[k]
+			if !ok || tv != pv {
+				return false
+			}
+		}
+	} else {
+		return false
+	}
+
 	pServices := p.Services
 	thatServices := that.Services
 	if len(pServices) == len(thatServices) {