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

Add checks and refactor for better naming conventions

Sean Holcomb пре 5 година
родитељ
комит
688105f068
4 измењених фајлова са 130 додато и 130 уклоњено
  1. 2 2
      pkg/costmodel/costmodel.go
  2. 28 28
      pkg/kubecost/allocation.go
  3. 94 94
      pkg/kubecost/allocation_test.go
  4. 6 6
      pkg/kubecost/kubecost_codecs.go

+ 2 - 2
pkg/costmodel/costmodel.go

@@ -1057,7 +1057,7 @@ func (cm *CostModel) GetNodeCost(cp costAnalyzerCloud.Provider) (map[string]*cos
 
 			cpuToRAMRatio := defaultCPU / defaultRAM
 			if math.IsNaN(cpuToRAMRatio) {
-				klog.V(1).Infof("[Warning] cpuToRAMRatio[defaultCPU: %f / defaultRam: %f] is NaN. Setting to 0.", defaultCPU, defaultRAM)
+				klog.V(1).Infof("[Warning] cpuToRAMRatio[defaultCPU: %f / defaultRAM: %f] is NaN. Setting to 0.", defaultCPU, defaultRAM)
 				cpuToRAMRatio = 0
 			}
 
@@ -1137,7 +1137,7 @@ func (cm *CostModel) GetNodeCost(cp costAnalyzerCloud.Provider) (map[string]*cos
 
 			cpuToRAMRatio := defaultCPU / defaultRAM
 			if math.IsNaN(cpuToRAMRatio) {
-				klog.V(1).Infof("[Warning] cpuToRAMRatio[defaultCPU: %f / defaultRam: %f] is NaN. Setting to 0.", defaultCPU, defaultRAM)
+				klog.V(1).Infof("[Warning] cpuToRAMRatio[defaultCPU: %f / defaultRAM: %f] is NaN. Setting to 0.", defaultCPU, defaultRAM)
 				cpuToRAMRatio = 0
 			}
 

+ 28 - 28
pkg/kubecost/allocation.go

@@ -59,10 +59,10 @@ type Allocation struct {
 	CPUCoreRequestAverage  float64               `json:"cpuCoreRequestAverage"`
 	CPUCoreUsageAverage    float64               `json:"cpuCoreUsageAverage"`
 	CPUCost                float64               `json:"cpuCost"`
-	CPUAdjustment          float64               `json:"cpuAdjustment"`
+	CPUCostAdjustment      float64               `json:"cpuCostAdjustment"`
 	GPUHours               float64               `json:"gpuHours"`
 	GPUCost                float64               `json:"gpuCost"`
-	GPUAdjustment          float64               `json:"gpuAdjustment"`
+	GPUCostAdjustment      float64               `json:"gpuCostAdjustment"`
 	NetworkCost            float64               `json:"networkCost"`
 	LoadBalancerCost       float64               `json:"loadBalancerCost"`
 	PVByteHours            float64               `json:"pvByteHours"`
@@ -71,7 +71,7 @@ type Allocation struct {
 	RAMBytesRequestAverage float64               `json:"ramByteRequestAverage"`
 	RAMBytesUsageAverage   float64               `json:"ramByteUsageAverage"`
 	RAMCost                float64               `json:"ramCost"`
-	RAMAdjustment          float64               `json:"ramAdjustment"`
+	RAMCostAdjustment      float64               `json:"ramCostAdjustment"`
 	SharedCost             float64               `json:"sharedCost"`
 	ExternalCost           float64               `json:"externalCost"`
 
@@ -147,10 +147,10 @@ func (a *Allocation) Clone() *Allocation {
 		CPUCoreRequestAverage:  a.CPUCoreRequestAverage,
 		CPUCoreUsageAverage:    a.CPUCoreUsageAverage,
 		CPUCost:                a.CPUCost,
-		CPUAdjustment:          a.CPUAdjustment,
+		CPUCostAdjustment:      a.CPUCostAdjustment,
 		GPUHours:               a.GPUHours,
 		GPUCost:                a.GPUCost,
-		GPUAdjustment:          a.GPUAdjustment,
+		GPUCostAdjustment:      a.GPUCostAdjustment,
 		NetworkCost:            a.NetworkCost,
 		LoadBalancerCost:       a.LoadBalancerCost,
 		PVByteHours:            a.PVByteHours,
@@ -159,7 +159,7 @@ func (a *Allocation) Clone() *Allocation {
 		RAMBytesRequestAverage: a.RAMBytesRequestAverage,
 		RAMBytesUsageAverage:   a.RAMBytesUsageAverage,
 		RAMCost:                a.RAMCost,
-		RAMAdjustment:          a.RAMAdjustment,
+		RAMCostAdjustment:      a.RAMCostAdjustment,
 		SharedCost:             a.SharedCost,
 		ExternalCost:           a.ExternalCost,
 		RawAllocationOnly:      a.RawAllocationOnly.Clone(),
@@ -208,7 +208,7 @@ func (a *Allocation) Equal(that *Allocation) bool {
 	if !util.IsApproximately(a.CPUCost, that.CPUCost) {
 		return false
 	}
-	if !util.IsApproximately(a.CPUAdjustment, that.CPUAdjustment) {
+	if !util.IsApproximately(a.CPUCostAdjustment, that.CPUCostAdjustment) {
 		return false
 	}
 	if !util.IsApproximately(a.GPUHours, that.GPUHours) {
@@ -217,7 +217,7 @@ func (a *Allocation) Equal(that *Allocation) bool {
 	if !util.IsApproximately(a.GPUCost, that.GPUCost) {
 		return false
 	}
-	if !util.IsApproximately(a.GPUAdjustment, that.GPUAdjustment) {
+	if !util.IsApproximately(a.GPUCostAdjustment, that.GPUCostAdjustment) {
 		return false
 	}
 	if !util.IsApproximately(a.NetworkCost, that.NetworkCost) {
@@ -238,7 +238,7 @@ func (a *Allocation) Equal(that *Allocation) bool {
 	if !util.IsApproximately(a.RAMCost, that.RAMCost) {
 		return false
 	}
-	if !util.IsApproximately(a.RAMAdjustment, that.RAMAdjustment) {
+	if !util.IsApproximately(a.RAMCostAdjustment, that.RAMCostAdjustment) {
 		return false
 	}
 	if !util.IsApproximately(a.SharedCost, that.SharedCost) {
@@ -273,15 +273,15 @@ func (a *Allocation) TotalCost() float64 {
 }
 
 func (a *Allocation) CPUTotalCost() float64 {
-	return a.CPUCost + a.CPUAdjustment
+	return a.CPUCost + a.CPUCostAdjustment
 }
 
 func (a *Allocation) GPUTotalCost() float64 {
-	return a.GPUCost + a.GPUAdjustment
+	return a.GPUCost + a.GPUCostAdjustment
 }
 
 func (a *Allocation) RAMTotalCost() float64 {
-	return a.RAMCost + a.RAMAdjustment
+	return a.RAMCost + a.RAMCostAdjustment
 }
 
 // CPUEfficiency is the ratio of usage to request. If there is no request and
@@ -372,12 +372,12 @@ func (a *Allocation) MarshalJSON() ([]byte, error) {
 	jsonEncodeFloat64(buffer, "cpuCoreUsageAverage", a.CPUCoreUsageAverage, ",")
 	jsonEncodeFloat64(buffer, "cpuCoreHours", a.CPUCoreHours, ",")
 	jsonEncodeFloat64(buffer, "cpuCost", a.CPUCost, ",")
-	jsonEncodeFloat64(buffer, "cpuAdjustment", a.CPUAdjustment, ",")
+	jsonEncodeFloat64(buffer, "cpuCostAdjustment", a.CPUCostAdjustment, ",")
 	jsonEncodeFloat64(buffer, "cpuEfficiency", a.CPUEfficiency(), ",")
 	jsonEncodeFloat64(buffer, "gpuCount", a.GPUs(), ",")
 	jsonEncodeFloat64(buffer, "gpuHours", a.GPUHours, ",")
 	jsonEncodeFloat64(buffer, "gpuCost", a.GPUCost, ",")
-	jsonEncodeFloat64(buffer, "gpuAdjustment", a.GPUAdjustment, ",")
+	jsonEncodeFloat64(buffer, "gpuCostAdjustment", a.GPUCostAdjustment, ",")
 	jsonEncodeFloat64(buffer, "networkCost", a.NetworkCost, ",")
 	jsonEncodeFloat64(buffer, "loadBalancerCost", a.LoadBalancerCost, ",")
 	jsonEncodeFloat64(buffer, "pvBytes", a.PVBytes(), ",")
@@ -388,7 +388,7 @@ func (a *Allocation) MarshalJSON() ([]byte, error) {
 	jsonEncodeFloat64(buffer, "ramByteUsageAverage", a.RAMBytesUsageAverage, ",")
 	jsonEncodeFloat64(buffer, "ramByteHours", a.RAMByteHours, ",")
 	jsonEncodeFloat64(buffer, "ramCost", a.RAMCost, ",")
-	jsonEncodeFloat64(buffer, "ramAdjustment", a.RAMAdjustment, ",")
+	jsonEncodeFloat64(buffer, "ramCostAdjustment", a.RAMCostAdjustment, ",")
 	jsonEncodeFloat64(buffer, "ramEfficiency", a.RAMEfficiency(), ",")
 	jsonEncodeFloat64(buffer, "sharedCost", a.SharedCost, ",")
 	jsonEncodeFloat64(buffer, "externalCost", a.ExternalCost, ",")
@@ -519,9 +519,9 @@ func (a *Allocation) add(that *Allocation) {
 	a.ExternalCost += that.ExternalCost
 
 	// Sum all cumulative adjustment fields
-	a.CPUAdjustment += that.CPUAdjustment
-	a.RAMAdjustment += that.RAMAdjustment
-	a.GPUAdjustment += that.GPUAdjustment
+	a.CPUCostAdjustment += that.CPUCostAdjustment
+	a.RAMCostAdjustment += that.RAMCostAdjustment
+	a.GPUCostAdjustment += that.GPUCostAdjustment
 
 	// Any data that is in a "raw allocation only" is not valid in any
 	// sort of cumulative Allocation (like one that is added).
@@ -1188,7 +1188,7 @@ func computeIdleCoeffs(options *AllocationAggregationOptions, as *AllocationSet,
 		} else {
 			coeffs[clusterID][name]["cpu"] += alloc.CPUTotalCost()
 			coeffs[clusterID][name]["gpu"] += alloc.GPUTotalCost()
-			coeffs[clusterID][name]["ram"] += alloc.RAMCost
+			coeffs[clusterID][name]["ram"] += alloc.RAMTotalCost()
 
 			totals[clusterID]["cpu"] += alloc.CPUTotalCost()
 			totals[clusterID]["gpu"] += alloc.GPUTotalCost()
@@ -1504,9 +1504,9 @@ func (as *AllocationSet) ComputeIdleAllocations(assetSet *AssetSet) (map[string]
 	return idleAllocs, nil
 }
 
-// ReconcileAllocations calculate the exact cost of Allocation by resource(cpu, ram, gpu etc) based on Asset(s) on which
+// Reconcile calculate the exact cost of Allocation by resource(cpu, ram, gpu etc) based on Asset(s) on which
 // the Allocation depends.
-func (as *AllocationSet) ReconcileAllocations(assetSet *AssetSet) error {
+func (as *AllocationSet) Reconcile(assetSet *AssetSet) error {
 	if as == nil {
 		return fmt.Errorf("cannot reconcile allocation for nil AllocationSet")
 	}
@@ -1520,10 +1520,10 @@ func (as *AllocationSet) ReconcileAllocations(assetSet *AssetSet) error {
 	}
 
 	// Build map of Assets with type Node by their ProviderId so that they can be matched to Allocations to determine
-	// proper CPU GPU and Ram prices
+	// proper CPU GPU and RAM prices
 	nodeByProviderID := map[string]*Node{}
 	assetSet.Each(func(key string, a Asset) {
-		if node, ok := a.(*Node); ok {
+		if node, ok := a.(*Node); ok && node.properties.ProviderID != "" {
 			nodeByProviderID[node.properties.ProviderID] = node
 		}
 	})
@@ -1534,7 +1534,7 @@ func (as *AllocationSet) ReconcileAllocations(assetSet *AssetSet) error {
 
 		// Reconcile with node Assets
 		node, ok := nodeByProviderID[providerId]
-		if !ok {
+		if !ok || providerId == "" {
 			// Failed to find node for allocation
 			return
 		}
@@ -1574,7 +1574,7 @@ func (as *AllocationSet) ReconcileAllocations(assetSet *AssetSet) error {
 		if node.RAMByteHours != 0 {
 			ramUsageProportion = a.RAMByteHours / node.RAMByteHours
 		} else {
-			log.Warningf("Missing Ram Byte Hours for node Provider ID: %s", providerId)
+			log.Warningf("Missing RAM Byte Hours for node Provider ID: %s", providerId)
 		}
 		gpuUsageProportion := 0.0
 		if node.GPUHours != 0 {
@@ -1587,9 +1587,9 @@ func (as *AllocationSet) ReconcileAllocations(assetSet *AssetSet) error {
 		allocRAMCost := ramUsageProportion * ramCost
 		allocGPUCost := gpuUsageProportion * gpuCost
 
-		a.CPUAdjustment = allocCPUCost - a.CPUCost
-		a.RAMAdjustment = allocRAMCost - a.RAMCost
-		a.GPUAdjustment = allocGPUCost - a.GPUCost
+		a.CPUCostAdjustment = allocCPUCost - a.CPUCost
+		a.RAMCostAdjustment = allocRAMCost - a.RAMCost
+		a.GPUCostAdjustment = allocGPUCost - a.GPUCost
 	})
 
 	return nil

+ 94 - 94
pkg/kubecost/allocation_test.go

@@ -112,17 +112,17 @@ func TestAllocation_Add(t *testing.T) {
 		CPUCoreRequestAverage:  2.0,
 		CPUCoreUsageAverage:    1.0,
 		CPUCost:                2.0 * hrs1 * cpuPrice,
-		CPUAdjustment:          3.0,
+		CPUCostAdjustment:      3.0,
 		GPUHours:               1.0 * hrs1,
 		GPUCost:                1.0 * hrs1 * gpuPrice,
-		GPUAdjustment:          2.0,
+		GPUCostAdjustment:      2.0,
 		PVByteHours:            100.0 * gib * hrs1,
 		PVCost:                 100.0 * hrs1 * pvPrice,
 		RAMByteHours:           8.0 * gib * hrs1,
 		RAMBytesRequestAverage: 8.0 * gib,
 		RAMBytesUsageAverage:   4.0 * gib,
 		RAMCost:                8.0 * hrs1 * ramPrice,
-		RAMAdjustment:          1.0,
+		RAMCostAdjustment:      1.0,
 		SharedCost:             2.00,
 		ExternalCost:           1.00,
 		RawAllocationOnly:      &RawAllocationOnlyData{},
@@ -176,20 +176,20 @@ func TestAllocation_Add(t *testing.T) {
 	if !util.IsApproximately(a1.CPUCost+a2.CPUCost, act.CPUCost) {
 		t.Fatalf("Allocation.Add: expected %f; actual %f", a1.CPUCost+a2.CPUCost, act.CPUCost)
 	}
-	if !util.IsApproximately(a1.CPUAdjustment+a2.CPUAdjustment, act.CPUAdjustment) {
-		t.Fatalf("Allocation.Add: expected %f; actual %f", a1.CPUAdjustment+a2.CPUAdjustment, act.CPUAdjustment)
+	if !util.IsApproximately(a1.CPUCostAdjustment+a2.CPUCostAdjustment, act.CPUCostAdjustment) {
+		t.Fatalf("Allocation.Add: expected %f; actual %f", a1.CPUCostAdjustment+a2.CPUCostAdjustment, act.CPUCostAdjustment)
 	}
 	if !util.IsApproximately(a1.GPUCost+a2.GPUCost, act.GPUCost) {
 		t.Fatalf("Allocation.Add: expected %f; actual %f", a1.GPUCost+a2.GPUCost, act.GPUCost)
 	}
-	if !util.IsApproximately(a1.GPUAdjustment+a2.GPUAdjustment, act.GPUAdjustment) {
-		t.Fatalf("Allocation.Add: expected %f; actual %f", a1.GPUAdjustment+a2.GPUAdjustment, act.GPUAdjustment)
+	if !util.IsApproximately(a1.GPUCostAdjustment+a2.GPUCostAdjustment, act.GPUCostAdjustment) {
+		t.Fatalf("Allocation.Add: expected %f; actual %f", a1.GPUCostAdjustment+a2.GPUCostAdjustment, act.GPUCostAdjustment)
 	}
 	if !util.IsApproximately(a1.RAMCost+a2.RAMCost, act.RAMCost) {
 		t.Fatalf("Allocation.Add: expected %f; actual %f", a1.RAMCost+a2.RAMCost, act.RAMCost)
 	}
-	if !util.IsApproximately(a1.RAMAdjustment+a2.RAMAdjustment, act.RAMAdjustment) {
-		t.Fatalf("Allocation.Add: expected %f; actual %f", a1.RAMAdjustment+a2.RAMAdjustment, act.RAMAdjustment)
+	if !util.IsApproximately(a1.RAMCostAdjustment+a2.RAMCostAdjustment, act.RAMCostAdjustment) {
+		t.Fatalf("Allocation.Add: expected %f; actual %f", a1.RAMCostAdjustment+a2.RAMCostAdjustment, act.RAMCostAdjustment)
 	}
 	if !util.IsApproximately(a1.PVCost+a2.PVCost, act.PVCost) {
 		t.Fatalf("Allocation.Add: expected %f; actual %f", a1.PVCost+a2.PVCost, act.PVCost)
@@ -281,17 +281,17 @@ func TestAllocation_Share(t *testing.T) {
 		CPUCoreRequestAverage:  2.0,
 		CPUCoreUsageAverage:    1.0,
 		CPUCost:                2.0 * hrs1 * cpuPrice,
-		CPUAdjustment:          3.0,
+		CPUCostAdjustment:      3.0,
 		GPUHours:               1.0 * hrs1,
 		GPUCost:                1.0 * hrs1 * gpuPrice,
-		GPUAdjustment:          2.0,
+		GPUCostAdjustment:      2.0,
 		PVByteHours:            100.0 * gib * hrs1,
 		PVCost:                 100.0 * hrs1 * pvPrice,
 		RAMByteHours:           8.0 * gib * hrs1,
 		RAMBytesRequestAverage: 8.0 * gib,
 		RAMBytesUsageAverage:   4.0 * gib,
 		RAMCost:                8.0 * hrs1 * ramPrice,
-		RAMAdjustment:          1.0,
+		RAMCostAdjustment:      1.0,
 		SharedCost:             2.00,
 		ExternalCost:           1.00,
 	}
@@ -440,10 +440,10 @@ func TestAllocation_MarshalJSON(t *testing.T) {
 		CPUCoreRequestAverage:  2.0,
 		CPUCoreUsageAverage:    1.0,
 		CPUCost:                2.0 * hrs * cpuPrice,
-		CPUAdjustment:          3.0,
+		CPUCostAdjustment:      3.0,
 		GPUHours:               1.0 * hrs,
 		GPUCost:                1.0 * hrs * gpuPrice,
-		GPUAdjustment:          2.0,
+		GPUCostAdjustment:      2.0,
 		NetworkCost:            0.05,
 		LoadBalancerCost:       0.02,
 		PVByteHours:            100.0 * gib * hrs,
@@ -452,7 +452,7 @@ func TestAllocation_MarshalJSON(t *testing.T) {
 		RAMBytesRequestAverage: 8.0 * gib,
 		RAMBytesUsageAverage:   4.0 * gib,
 		RAMCost:                8.0 * hrs * ramPrice,
-		RAMAdjustment:          1.0,
+		RAMCostAdjustment:      1.0,
 		SharedCost:             2.00,
 		ExternalCost:           1.00,
 		RawAllocationOnly:      &RawAllocationOnlyData{},
@@ -1771,9 +1771,9 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 				// RAM	|    44	    |	  6	     |     11 	  |	  1
 				// GPU	|    11	    |	 24      |     1 	  |	  1
 				"cluster1/namespace1/pod1/container1": {
-					CPUAdjustment: 5.25,
-					RAMAdjustment: -4.333333,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 5.25,
+					RAMCostAdjustment: -4.333333,
+					GPUCostAdjustment: -0.583333,
 				},
 				// ADJUSTMENT_RATE: 0.90909090909
 				// Type | NODE_COST | NODE_HOURs | ALLOC_COST | ALLOC_HOURS
@@ -1781,29 +1781,29 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 				// RAM	|    44	    |	  6	     |     1 	  |	  1
 				// GPU	|    11	    |	 24      |     1 	  |	  1
 				"cluster1/namespace1/pod-abc/container2": {
-					CPUAdjustment: 5.25,
-					RAMAdjustment: 5.666667,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 5.25,
+					RAMCostAdjustment: 5.666667,
+					GPUCostAdjustment: -0.583333,
 				},
 				"cluster1/namespace1/pod-def/container3": {
-					CPUAdjustment: 5.25,
-					RAMAdjustment: 5.666667,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 5.25,
+					RAMCostAdjustment: 5.666667,
+					GPUCostAdjustment: -0.583333,
 				},
 				"cluster1/namespace2/pod-ghi/container4": {
-					CPUAdjustment: 5.25,
-					RAMAdjustment: 5.666667,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 5.25,
+					RAMCostAdjustment: 5.666667,
+					GPUCostAdjustment: -0.583333,
 				},
 				"cluster1/namespace2/pod-ghi/container5": {
-					CPUAdjustment: 5.25,
-					RAMAdjustment: 5.666667,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 5.25,
+					RAMCostAdjustment: 5.666667,
+					GPUCostAdjustment: -0.583333,
 				},
 				"cluster1/namespace2/pod-jkl/container6": {
-					CPUAdjustment: 5.25,
-					RAMAdjustment: 5.666667,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 5.25,
+					RAMCostAdjustment: 5.666667,
+					GPUCostAdjustment: -0.583333,
 				},
 				// ADJUSTMENT_RATE: 1.0
 				// Type | NODE_COST | NODE_HOURs | ALLOC_COST | ALLOC_HOURS
@@ -1811,14 +1811,14 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 				// RAM	|    15	    |	  3	     |     1 	  |	  1
 				// GPU	|    0	    |	  0      |     1 	  |	  1
 				"cluster2/namespace2/pod-mno/container4": {
-					CPUAdjustment: 4.0,
-					RAMAdjustment: 4.0,
-					GPUAdjustment: -1.0,
+					CPUCostAdjustment: 4.0,
+					RAMCostAdjustment: 4.0,
+					GPUCostAdjustment: -1.0,
 				},
 				"cluster2/namespace2/pod-mno/container5": {
-					CPUAdjustment: 4.0,
-					RAMAdjustment: 4.0,
-					GPUAdjustment: -1.0,
+					CPUCostAdjustment: 4.0,
+					RAMCostAdjustment: 4.0,
+					GPUCostAdjustment: -1.0,
 				},
 				// ADJUSTMENT_RATE: 1.0
 				// Type | NODE_COST | NODE_HOURs | ALLOC_COST | ALLOC_HOURS
@@ -1826,14 +1826,14 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 				// RAM	|    15	    |	  2	     |     1 	  |	  1
 				// GPU	|    0	    |	  0      |     1 	  |	  1
 				"cluster2/namespace2/pod-pqr/container6": {
-					CPUAdjustment: 5.666667,
-					RAMAdjustment: 6.5,
-					GPUAdjustment: -1.0,
+					CPUCostAdjustment: 5.666667,
+					RAMCostAdjustment: 6.5,
+					GPUCostAdjustment: -1.0,
 				},
 				"cluster2/namespace3/pod-stu/container7": {
-					CPUAdjustment: 5.666667,
-					RAMAdjustment: 6.5,
-					GPUAdjustment: -1.0,
+					CPUCostAdjustment: 5.666667,
+					RAMCostAdjustment: 6.5,
+					GPUCostAdjustment: -1.0,
 				},
 				// ADJUSTMENT_RATE: 1.0
 				// Type | NODE_COST | NODE_HOURs | ALLOC_COST | ALLOC_HOURS
@@ -1841,14 +1841,14 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 				// RAM	|    10	    |	  2	     |     1 	  |	  1
 				// GPU	|    10	    |	 24      |     1 	  |	  1
 				"cluster2/namespace3/pod-vwx/container8": {
-					CPUAdjustment: 4.0,
-					RAMAdjustment: 4.0,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 4.0,
+					RAMCostAdjustment: 4.0,
+					GPUCostAdjustment: -0.583333,
 				},
 				"cluster2/namespace3/pod-vwx/container9": {
-					CPUAdjustment: 4.0,
-					RAMAdjustment: 4.0,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 4.0,
+					RAMCostAdjustment: 4.0,
+					GPUCostAdjustment: -0.583333,
 				},
 			},
 		},
@@ -1862,9 +1862,9 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 				// RAM	|     4	    |	  6	     |    11 	  |	  1
 				// GPU	|     1	    |	 24      |     1 	  |	  1
 				"cluster1/namespace1/pod1/container1": {
-					CPUAdjustment: 5.25,
-					RAMAdjustment: -4.333333,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 5.25,
+					RAMCostAdjustment: -4.333333,
+					GPUCostAdjustment: -0.583333,
 				},
 				// ADJUSTMENT_RATE: 10
 				// Type | NODE_COST | NODE_HOURs | ALLOC_COST | ALLOC_HOURS
@@ -1872,29 +1872,29 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 				// RAM	|     4	    |	  6	     |     1 	  |	  1
 				// GPU	|     1	    |	 24      |     1 	  |	  1
 				"cluster1/namespace1/pod-abc/container2": {
-					CPUAdjustment: 5.25,
-					RAMAdjustment: 5.6666667,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 5.25,
+					RAMCostAdjustment: 5.6666667,
+					GPUCostAdjustment: -0.583333,
 				},
 				"cluster1/namespace1/pod-def/container3": {
-					CPUAdjustment: 5.25,
-					RAMAdjustment: 5.6666667,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 5.25,
+					RAMCostAdjustment: 5.6666667,
+					GPUCostAdjustment: -0.583333,
 				},
 				"cluster1/namespace2/pod-ghi/container4": {
-					CPUAdjustment: 5.25,
-					RAMAdjustment: 5.6666667,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 5.25,
+					RAMCostAdjustment: 5.6666667,
+					GPUCostAdjustment: -0.583333,
 				},
 				"cluster1/namespace2/pod-ghi/container5": {
-					CPUAdjustment: 5.25,
-					RAMAdjustment: 5.6666667,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 5.25,
+					RAMCostAdjustment: 5.6666667,
+					GPUCostAdjustment: -0.583333,
 				},
 				"cluster1/namespace2/pod-jkl/container6": {
-					CPUAdjustment: 5.25,
-					RAMAdjustment: 5.6666667,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 5.25,
+					RAMCostAdjustment: 5.6666667,
+					GPUCostAdjustment: -0.583333,
 				},
 				// ADJUSTMENT_RATE: 1.0
 				// Type | NODE_COST | NODE_HOURs | ALLOC_COST | ALLOC_HOURS
@@ -1902,14 +1902,14 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 				// RAM	|    15	    |	  3	     |     1 	  |	  1
 				// GPU	|    0	    |	  0      |     1 	  |	  1
 				"cluster2/namespace2/pod-mno/container4": {
-					CPUAdjustment: 4.0,
-					RAMAdjustment: 4.0,
-					GPUAdjustment: -1.0,
+					CPUCostAdjustment: 4.0,
+					RAMCostAdjustment: 4.0,
+					GPUCostAdjustment: -1.0,
 				},
 				"cluster2/namespace2/pod-mno/container5": {
-					CPUAdjustment: 4.0,
-					RAMAdjustment: 4.0,
-					GPUAdjustment: -1.0,
+					CPUCostAdjustment: 4.0,
+					RAMCostAdjustment: 4.0,
+					GPUCostAdjustment: -1.0,
 				},
 				// ADJUSTMENT_RATE: 1.0
 				// Type | NODE_COST | NODE_HOURs | ALLOC_COST | ALLOC_HOURS
@@ -1917,14 +1917,14 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 				// RAM	|    15	    |	  2	     |     1 	  |	  1
 				// GPU	|    0	    |	  0      |     1 	  |	  1
 				"cluster2/namespace2/pod-pqr/container6": {
-					CPUAdjustment: 5.666667,
-					RAMAdjustment: 6.5,
-					GPUAdjustment: -1.0,
+					CPUCostAdjustment: 5.666667,
+					RAMCostAdjustment: 6.5,
+					GPUCostAdjustment: -1.0,
 				},
 				"cluster2/namespace3/pod-stu/container7": {
-					CPUAdjustment: 5.666667,
-					RAMAdjustment: 6.5,
-					GPUAdjustment: -1.0,
+					CPUCostAdjustment: 5.666667,
+					RAMCostAdjustment: 6.5,
+					GPUCostAdjustment: -1.0,
 				},
 				// ADJUSTMENT_RATE: 1.0
 				// Type | NODE_COST | NODE_HOURs | ALLOC_COST | ALLOC_HOURS
@@ -1932,14 +1932,14 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 				// RAM	|    10	    |	  2	     |     1 	  |	  1
 				// GPU	|    10	    |	 24      |     1 	  |	  1
 				"cluster2/namespace3/pod-vwx/container8": {
-					CPUAdjustment: 4.0,
-					RAMAdjustment: 4.0,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 4.0,
+					RAMCostAdjustment: 4.0,
+					GPUCostAdjustment: -0.583333,
 				},
 				"cluster2/namespace3/pod-vwx/container9": {
-					CPUAdjustment: 4.0,
-					RAMAdjustment: 4.0,
-					GPUAdjustment: -0.583333,
+					CPUCostAdjustment: 4.0,
+					RAMCostAdjustment: 4.0,
+					GPUCostAdjustment: -0.583333,
 				},
 			},
 		},
@@ -1947,7 +1947,7 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 
 	for name, testcase := range cases {
 		t.Run(name, func(t *testing.T) {
-			err = as.ReconcileAllocations(testcase.assetSet)
+			err = as.Reconcile(testcase.assetSet)
 			reconAllocs := as.allocations
 			if err != nil {
 				t.Fatalf("unexpected error: %s", err)
@@ -1958,14 +1958,14 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 					t.Fatalf("expected allocation %s", allocationName)
 				}
 
-				if !util.IsApproximately(reconAllocs[allocationName].CPUAdjustment, testAlloc.CPUAdjustment) {
-					t.Fatalf("expected CPU Adjustment for %s to be %f; got %f", allocationName, testAlloc.CPUAdjustment, reconAllocs[allocationName].CPUAdjustment)
+				if !util.IsApproximately(reconAllocs[allocationName].CPUCostAdjustment, testAlloc.CPUCostAdjustment) {
+					t.Fatalf("expected CPU Adjustment for %s to be %f; got %f", allocationName, testAlloc.CPUCostAdjustment, reconAllocs[allocationName].CPUCostAdjustment)
 				}
-				if !util.IsApproximately(reconAllocs[allocationName].RAMAdjustment, testAlloc.RAMAdjustment) {
-					t.Fatalf("expected RAM Adjustment for %s to be %f; got %f", allocationName, testAlloc.RAMAdjustment, reconAllocs[allocationName].RAMAdjustment)
+				if !util.IsApproximately(reconAllocs[allocationName].RAMCostAdjustment, testAlloc.RAMCostAdjustment) {
+					t.Fatalf("expected RAM Adjustment for %s to be %f; got %f", allocationName, testAlloc.RAMCostAdjustment, reconAllocs[allocationName].RAMCostAdjustment)
 				}
-				if !util.IsApproximately(reconAllocs[allocationName].GPUAdjustment, testAlloc.GPUAdjustment) {
-					t.Fatalf("expected GPU Adjustment for %s to be %f; got %f", allocationName, testAlloc.GPUAdjustment, reconAllocs[allocationName].GPUAdjustment)
+				if !util.IsApproximately(reconAllocs[allocationName].GPUCostAdjustment, testAlloc.GPUCostAdjustment) {
+					t.Fatalf("expected GPU Adjustment for %s to be %f; got %f", allocationName, testAlloc.GPUCostAdjustment, reconAllocs[allocationName].GPUCostAdjustment)
 				}
 			}
 		})

+ 6 - 6
pkg/kubecost/kubecost_codecs.go

@@ -164,10 +164,10 @@ func (target *Allocation) MarshalBinary() (data []byte, err error) {
 	buff.WriteFloat64(target.CPUCoreRequestAverage)  // write float64
 	buff.WriteFloat64(target.CPUCoreUsageAverage)    // write float64
 	buff.WriteFloat64(target.CPUCost)                // write float64
-	buff.WriteFloat64(target.CPUAdjustment)          // write float64
+	buff.WriteFloat64(target.CPUCostAdjustment)      // write float64
 	buff.WriteFloat64(target.GPUHours)               // write float64
 	buff.WriteFloat64(target.GPUCost)                // write float64
-	buff.WriteFloat64(target.GPUAdjustment)          // write float64
+	buff.WriteFloat64(target.GPUCostAdjustment)      // write float64
 	buff.WriteFloat64(target.NetworkCost)            // write float64
 	buff.WriteFloat64(target.LoadBalancerCost)       // write float64
 	buff.WriteFloat64(target.PVByteHours)            // write float64
@@ -176,7 +176,7 @@ func (target *Allocation) MarshalBinary() (data []byte, err error) {
 	buff.WriteFloat64(target.RAMBytesRequestAverage) // write float64
 	buff.WriteFloat64(target.RAMBytesUsageAverage)   // write float64
 	buff.WriteFloat64(target.RAMCost)                // write float64
-	buff.WriteFloat64(target.RAMAdjustment)          // write float64
+	buff.WriteFloat64(target.RAMCostAdjustment)      // write float64
 	buff.WriteFloat64(target.SharedCost)             // write float64
 	buff.WriteFloat64(target.ExternalCost)           // write float64
 	if target.RawAllocationOnly == nil {
@@ -285,7 +285,7 @@ func (target *Allocation) UnmarshalBinary(data []byte) (err error) {
 	target.CPUCost = s
 
 	t := buff.ReadFloat64() // read float64
-	target.CPUAdjustment = t
+	target.CPUCostAdjustment = t
 
 	u := buff.ReadFloat64() // read float64
 	target.GPUHours = u
@@ -294,7 +294,7 @@ func (target *Allocation) UnmarshalBinary(data []byte) (err error) {
 	target.GPUCost = w
 
 	x := buff.ReadFloat64() // read float64
-	target.GPUAdjustment = x
+	target.GPUCostAdjustment = x
 
 	y := buff.ReadFloat64() // read float64
 	target.NetworkCost = y
@@ -321,7 +321,7 @@ func (target *Allocation) UnmarshalBinary(data []byte) (err error) {
 	target.RAMCost = gg
 
 	hh := buff.ReadFloat64() // read float64
-	target.RAMAdjustment = hh
+	target.RAMCostAdjustment = hh
 
 	kk := buff.ReadFloat64() // read float64
 	target.SharedCost = kk