Sean Holcomb před 5 roky
rodič
revize
4fdae7a876

+ 3 - 3
pkg/costmodel/allocation.go

@@ -388,7 +388,7 @@ func (cm *CostModel) ComputeAllocation(start, end time.Time, resolution time.Dur
 					// weighted by count (i.e. the number of containers in the pod)
 					// record the amount of total PVBytes Hours attributable to a given PV
 					if alloc.PVs == nil {
-						alloc.PVs = kubecost.PV{}
+						alloc.PVs = kubecost.PVAllocations{}
 					}
 					pvKey := kubecost.PVKey{
 						Cluster: pvc.Cluster,
@@ -1678,7 +1678,7 @@ func applyUnmountedPVs(window kubecost.Window, podMap map[podKey]*Pod, pvMap map
 			Cluster: cluster,
 			Name:    kubecost.UnmountedSuffix,
 		}
-		unmountedBreakDown := kubecost.PV{
+		unmountedBreakDown := kubecost.PVAllocations{
 			pvKey: {
 				ByteHours: unmountedPVBytes[cluster] * window.Minutes() / 60.0,
 				Cost:      amount,
@@ -1730,7 +1730,7 @@ func applyUnmountedPVCs(window kubecost.Window, podMap map[podKey]*Pod, pvcMap m
 			Cluster: cluster,
 			Name:    kubecost.UnmountedSuffix,
 		}
-		unmountedBreakDown := kubecost.PV{
+		unmountedBreakDown := kubecost.PVAllocations{
 			pvKey: {
 				ByteHours: unmountedPVCBytes[key] * window.Minutes() / 60.0,
 				Cost:      amount,

+ 18 - 18
pkg/kubecost/allocation.go

@@ -65,15 +65,15 @@ type Allocation struct {
 	GPUCostAdjustment      float64               `json:"gpuCostAdjustment"`
 	NetworkCost            float64               `json:"networkCost"`
 	LoadBalancerCost       float64               `json:"loadBalancerCost"`
-	PVs                    PV
-	PVCostAdjustment       float64 `json:"pvCostAdjustment"`
-	RAMByteHours           float64 `json:"ramByteHours"`
-	RAMBytesRequestAverage float64 `json:"ramByteRequestAverage"`
-	RAMBytesUsageAverage   float64 `json:"ramByteUsageAverage"`
-	RAMCost                float64 `json:"ramCost"`
-	RAMCostAdjustment      float64 `json:"ramCostAdjustment"`
-	SharedCost             float64 `json:"sharedCost"`
-	ExternalCost           float64 `json:"externalCost"`
+	PVs                    PVAllocations         `json:"-"`
+	PVCostAdjustment       float64               `json:"pvCostAdjustment"`
+	RAMByteHours           float64               `json:"ramByteHours"`
+	RAMBytesRequestAverage float64               `json:"ramByteRequestAverage"`
+	RAMBytesUsageAverage   float64               `json:"ramByteUsageAverage"`
+	RAMCost                float64               `json:"ramCost"`
+	RAMCostAdjustment      float64               `json:"ramCostAdjustment"`
+	SharedCost             float64               `json:"sharedCost"`
+	ExternalCost           float64               `json:"externalCost"`
 	// RawAllocationOnly is a pointer so if it is not present it will be
 	// marshalled as null rather than as an object with Go default values.
 	RawAllocationOnly *RawAllocationOnlyData `json:"rawAllocationOnly"`
@@ -107,17 +107,17 @@ type RawAllocationOnlyData struct {
 	RAMBytesUsageMax float64 `json:"ramByteUsageMax"`
 }
 
-// PV is a map of Disk Asset Identifiers to the
+// PVAllocations is a map of Disk Asset Identifiers to the
 // usage of them by an Allocation as recorded in a PVAllocation
-type PV map[PVKey]*PVAllocation
+type PVAllocations map[PVKey]*PVAllocation
 
-// Clone creates a deep copy of a PV
-func (pv *PV) Clone() PV {
+// Clone creates a deep copy of a PVAllocations
+func (pv *PVAllocations) Clone() PVAllocations {
 	if pv == nil || *pv == nil {
 		return nil
 	}
 	apv := *pv
-	clonePV := PV{}
+	clonePV := PVAllocations{}
 	for k, v := range apv {
 		clonePV[k] = &PVAllocation{
 			ByteHours: v.ByteHours,
@@ -127,12 +127,12 @@ func (pv *PV) Clone() PV {
 	return clonePV
 }
 
-// Add adds contents of that to the calling PV
-func (pv *PV) Add(that PV) PV {
+// Add adds contents of that to the calling PVAllocations
+func (pv *PVAllocations) Add(that PVAllocations) PVAllocations {
 	apv := pv.Clone()
 	if that != nil {
 		if apv == nil {
-			apv = PV{}
+			apv = PVAllocations{}
 		}
 		for pvKey, thatPVAlloc := range that {
 			apvAlloc, ok := apv[pvKey]
@@ -606,7 +606,7 @@ func (a *Allocation) add(that *Allocation) {
 	a.SharedCost += that.SharedCost
 	a.ExternalCost += that.ExternalCost
 
-	// Sum PV Breakdown
+	// Sum PVAllocations
 	a.PVs = a.PVs.Add(that.PVs)
 
 	// Sum all cumulative adjustment fields

+ 5 - 5
pkg/kubecost/allocation_test.go

@@ -56,7 +56,7 @@ func NewUnitAllocation(name string, start time.Time, resolution time.Duration, p
 		GPUCost:               1,
 		NetworkCost:           1,
 		LoadBalancerCost:      1,
-		PVs: PV{
+		PVs: PVAllocations{
 			disk: {
 				ByteHours: 1,
 				Cost:      1,
@@ -129,7 +129,7 @@ func TestAllocation_Add(t *testing.T) {
 		GPUHours:              1.0 * hrs1,
 		GPUCost:               1.0 * hrs1 * gpuPrice,
 		GPUCostAdjustment:     2.0,
-		PVs: PV{
+		PVs: PVAllocations{
 			disk: {
 				ByteHours: 100.0 * gib * hrs1,
 				Cost:      100.0 * hrs1 * pvPrice,
@@ -301,7 +301,7 @@ func TestAllocation_Share(t *testing.T) {
 		GPUHours:              1.0 * hrs1,
 		GPUCost:               1.0 * hrs1 * gpuPrice,
 		GPUCostAdjustment:     2.0,
-		PVs: PV{
+		PVs: PVAllocations{
 			disk: {
 				ByteHours: 100.0 * gib * hrs1,
 				Cost:      100.0 * hrs1 * pvPrice,
@@ -465,7 +465,7 @@ func TestAllocation_MarshalJSON(t *testing.T) {
 		GPUCostAdjustment:     2.0,
 		NetworkCost:           0.05,
 		LoadBalancerCost:      0.02,
-		PVs: PV{
+		PVs: PVAllocations{
 			disk: {
 				ByteHours: 100.0 * gib * hrs,
 				Cost:      100.0 * hrs * pvPrice,
@@ -1792,7 +1792,7 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 	// add reconcilable pvs to pod-mno
 	for _, a := range as.allocations {
 		if a.Properties.Pod == "pod-mno" {
-			a.PVs = a.PVs.Add(PV{
+			a.PVs = a.PVs.Add(PVAllocations{
 				disk1: {
 					Cost:      2.5,
 					ByteHours: 2.5 * gb,

+ 1 - 1
pkg/kubecost/bingen.go

@@ -25,7 +25,7 @@ package kubecost
 // @bingen:generate:AllocationLabels
 // @bingen:generate:AllocationAnnotations
 // @bingen:generate:RawAllocationOnlyData
-// @bingen:generate:PV
+// @bingen:generate:PVAllocations
 // @bingen:generate:PVKey
 // @bingen:generate:PVAllocation
 

+ 5 - 5
pkg/kubecost/kubecost_codecs.go

@@ -172,7 +172,7 @@ func (target *Allocation) MarshalBinary() (data []byte, err error) {
 	buff.WriteFloat64(target.GPUCostAdjustment)     // write float64
 	buff.WriteFloat64(target.NetworkCost)           // write float64
 	buff.WriteFloat64(target.LoadBalancerCost)      // write float64
-	// --- [begin][write][alias](PV) ---
+	// --- [begin][write][alias](PVAllocations) ---
 	if map[PVKey]*PVAllocation(target.PVs) == nil {
 		buff.WriteUInt8(uint8(0)) // write nil byte
 	} else {
@@ -209,7 +209,7 @@ func (target *Allocation) MarshalBinary() (data []byte, err error) {
 		// --- [end][write][map](map[PVKey]*PVAllocation) ---
 
 	}
-	// --- [end][write][alias](PV) ---
+	// --- [end][write][alias](PVAllocations) ---
 
 	buff.WriteFloat64(target.PVCostAdjustment)       // write float64
 	buff.WriteFloat64(target.RAMByteHours)           // write float64
@@ -342,7 +342,7 @@ func (target *Allocation) UnmarshalBinary(data []byte) (err error) {
 	aa := buff.ReadFloat64() // read float64
 	target.LoadBalancerCost = aa
 
-	// --- [begin][read][alias](PV) ---
+	// --- [begin][read][alias](PVAllocations) ---
 	var bb map[PVKey]*PVAllocation
 	if buff.ReadUInt8() == uint8(0) {
 		bb = nil
@@ -384,8 +384,8 @@ func (target *Allocation) UnmarshalBinary(data []byte) (err error) {
 		// --- [end][read][map](map[PVKey]*PVAllocation) ---
 
 	}
-	target.PVs = PV(bb)
-	// --- [end][read][alias](PV) ---
+	target.PVs = PVAllocations(bb)
+	// --- [end][read][alias](PVAllocations) ---
 
 	mm := buff.ReadFloat64() // read float64
 	target.PVCostAdjustment = mm