Sean Holcomb 5 лет назад
Родитель
Сommit
43da9ddc34
3 измененных файлов с 20 добавлено и 20 удалено
  1. 3 3
      pkg/costmodel/allocation.go
  2. 11 12
      pkg/kubecost/allocation.go
  3. 6 5
      pkg/kubecost/allocation_test.go

+ 3 - 3
pkg/costmodel/allocation.go

@@ -1676,10 +1676,10 @@ func applyUnmountedPVs(window kubecost.Window, podMap map[podKey]*Pod, pvMap map
 		podMap[key].Allocations[container].Properties.Container = container
 		pvKey := kubecost.PVKey{
 			Cluster: cluster,
-			Name: kubecost.UnmountedSuffix,
+			Name:    kubecost.UnmountedSuffix,
 		}
 		unmountedBreakDown := kubecost.PV{
-			pvKey : {
+			pvKey: {
 				ByteHours: unmountedPVBytes[cluster] * window.Minutes() / 60.0,
 				Cost:      amount,
 			},
@@ -1728,7 +1728,7 @@ func applyUnmountedPVCs(window kubecost.Window, podMap map[podKey]*Pod, pvcMap m
 		podMap[podKey].Allocations[container].Properties.Container = container
 		pvKey := kubecost.PVKey{
 			Cluster: cluster,
-			Name: kubecost.UnmountedSuffix,
+			Name:    kubecost.UnmountedSuffix,
 		}
 		unmountedBreakDown := kubecost.PV{
 			pvKey: {

+ 11 - 12
pkg/kubecost/allocation.go

@@ -66,14 +66,14 @@ type Allocation struct {
 	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"`
+	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"`
@@ -112,20 +112,20 @@ type RawAllocationOnlyData struct {
 type PV map[PVKey]*PVAllocation
 
 // Clone creates a deep copy of a PV
-func (pv *PV) Clone() PV{
+func (pv *PV) Clone() PV {
 	if pv == nil || *pv == nil {
 		return nil
 	}
 	apv := *pv
 	clonePV := PV{}
-	for k, v := range apv{
+	for k, v := range apv {
 		clonePV[k] = v
 	}
 	return clonePV
 }
 
 // Add adds contents of that to the calling PV
-func (pv *PV) Add(that PV) PV{
+func (pv *PV) Add(that PV) PV {
 	apv := pv.Clone()
 	if that != nil {
 		if apv == nil {
@@ -186,7 +186,6 @@ func (a *Allocation) Clone() *Allocation {
 		return nil
 	}
 
-
 	return &Allocation{
 		Name:                   a.Name,
 		Properties:             a.Properties.Clone(),

+ 6 - 5
pkg/kubecost/allocation_test.go

@@ -11,14 +11,15 @@ import (
 )
 
 const day = 24 * time.Hour
+
 var disk = PVKey{}
 var disk1 = PVKey{
 	Cluster: "cluster2",
-	Name: "disk1",
+	Name:    "disk1",
 }
 var disk2 = PVKey{
 	Cluster: "cluster2",
-	Name: "disk2",
+	Name:    "disk2",
 }
 
 func NewUnitAllocation(name string, start time.Time, resolution time.Duration, props *AllocationProperties) *Allocation {
@@ -301,7 +302,7 @@ func TestAllocation_Share(t *testing.T) {
 		GPUCost:               1.0 * hrs1 * gpuPrice,
 		GPUCostAdjustment:     2.0,
 		PVs: PV{
-			disk : {
+			disk: {
 				ByteHours: 100.0 * gib * hrs1,
 				Cost:      100.0 * hrs1 * pvPrice,
 			},
@@ -1793,11 +1794,11 @@ func TestAllocationSet_ReconcileAllocations(t *testing.T) {
 		if a.Properties.Pod == "pod-mno" {
 			a.PVs = a.PVs.Add(PV{
 				disk1: {
-					Cost: 2.5,
+					Cost:      2.5,
 					ByteHours: 2.5 * gb,
 				},
 				disk2: {
-					Cost: 5,
+					Cost:      5,
 					ByteHours: 5 * gb,
 				},
 			})