Explorar o código

Merge pull request #1032 from kubecost/neal/nil-pointer-patch

nil-pointer-patch-pr
Ajay Tripathy %!s(int64=4) %!d(string=hai) anos
pai
achega
97e26fce15
Modificáronse 1 ficheiros con 21 adicións e 7 borrados
  1. 21 7
      pkg/kubecost/summaryallocation.go

+ 21 - 7
pkg/kubecost/summaryallocation.go

@@ -640,7 +640,7 @@ func (sas *SummaryAllocationSet) AggregateBy(aggregateBy []string, options *Allo
 	}
 	}
 
 
 	// If we're recording allocTotalsAfterFilters and there are shared costs,
 	// If we're recording allocTotalsAfterFilters and there are shared costs,
-	// then record those resource totals here so that idle for thpse shared
+	// then record those resource totals here so that idle for those shared
 	// resources gets included.
 	// resources gets included.
 	if allocTotalsAfterFilters != nil {
 	if allocTotalsAfterFilters != nil {
 		for key, rt := range sharedResourceTotals {
 		for key, rt := range sharedResourceTotals {
@@ -822,7 +822,7 @@ func (sas *SummaryAllocationSet) AggregateBy(aggregateBy []string, options *Allo
 
 
 			var key string
 			var key string
 			if options.IdleByNode {
 			if options.IdleByNode {
-				key = ia.Properties.Node
+				key = fmt.Sprintf("%s/%s", ia.Properties.Cluster, ia.Properties.Node)
 			} else {
 			} else {
 				key = ia.Properties.Cluster
 				key = ia.Properties.Cluster
 			}
 			}
@@ -831,18 +831,32 @@ func (sas *SummaryAllocationSet) AggregateBy(aggregateBy []string, options *Allo
 			// which equals the proportion of filtered-to-actual cost.
 			// which equals the proportion of filtered-to-actual cost.
 			cpuFilterCoeff := 0.0
 			cpuFilterCoeff := 0.0
 			if allocTotals[key].CPUCost > 0.0 {
 			if allocTotals[key].CPUCost > 0.0 {
-				cpuFilterCoeff = allocTotalsAfterFilters[key].CPUCost / allocTotals[key].CPUCost
+				filteredAlloc, ok := allocTotalsAfterFilters[key]
+				if ok {
+					cpuFilterCoeff = filteredAlloc.CPUCost / allocTotals[key].CPUCost
+				} else {
+					cpuFilterCoeff = 0.0
+				}
 			}
 			}
 
 
 			gpuFilterCoeff := 0.0
 			gpuFilterCoeff := 0.0
-			if allocTotals[key].RAMCost > 0.0 {
-				gpuFilterCoeff = allocTotalsAfterFilters[key].RAMCost / allocTotals[key].RAMCost
+			if allocTotals[key].GPUCost > 0.0 {
+				filteredAlloc, ok := allocTotalsAfterFilters[key]
+				if ok {
+					gpuFilterCoeff = filteredAlloc.GPUCost / allocTotals[key].GPUCost
+				} else {
+					gpuFilterCoeff = 0.0
+				}
 			}
 			}
 
 
 			ramFilterCoeff := 0.0
 			ramFilterCoeff := 0.0
-
 			if allocTotals[key].RAMCost > 0.0 {
 			if allocTotals[key].RAMCost > 0.0 {
-				ramFilterCoeff = allocTotalsAfterFilters[key].RAMCost / allocTotals[key].RAMCost
+				filteredAlloc, ok := allocTotalsAfterFilters[key]
+				if ok {
+					ramFilterCoeff = filteredAlloc.RAMCost / allocTotals[key].RAMCost
+				} else {
+					ramFilterCoeff = 0.0
+				}
 			}
 			}
 
 
 			ia.CPUCost *= cpuFilterCoeff
 			ia.CPUCost *= cpuFilterCoeff