@@ -74,13 +74,29 @@ func calculatePoolUtil(unallocated, allocated []resourceapi.Device) float64 {
74
74
TotalConsumedCounters := calculateConsumedCounters (append (allocated , unallocated ... ))
75
75
allocatedConsumedCounters := calculateConsumedCounters (allocated )
76
76
77
- // we want to find the counter that is most utilized, since it is the "bottleneck"
78
- maxUtilization := 0.0
77
+ // not all devices are partitionable, so fallback to the ratio of non-partionable devices
78
+ allocatedDevicesWithoutCounters := 0
79
+ devicesWithoutCounters := 0
80
+
81
+ for _ , device := range allocated {
82
+ if device .Basic .ConsumesCounters == nil {
83
+ devicesWithoutCounters ++
84
+ allocatedDevicesWithoutCounters ++
85
+ }
86
+ }
87
+ for _ , device := range unallocated {
88
+ if device .Basic .ConsumesCounters == nil {
89
+ devicesWithoutCounters ++
90
+ }
91
+ }
92
+
93
+ // we want to find the counter that is most utilized, since it is the "bottleneck" of the pool
94
+ maxUtilization := float64 (allocatedDevicesWithoutCounters ) / (float64 (allocatedDevicesWithoutCounters ) + float64 (devicesWithoutCounters ))
79
95
for counterSet , counters := range TotalConsumedCounters {
80
96
for counterName , totalValue := range counters {
81
97
if allocatedSet , exists := allocatedConsumedCounters [counterSet ]; exists {
82
98
if allocatedValue , exists := allocatedSet [counterName ]; exists && ! totalValue .IsZero () {
83
- utilization := float64 (allocatedValue .MilliValue ()) / float64 (totalValue .MilliValue ())
99
+ utilization := float64 (allocatedValue .Value ()) / float64 (totalValue .Value ())
84
100
if utilization > maxUtilization {
85
101
maxUtilization = utilization
86
102
}
@@ -95,6 +111,9 @@ func calculatePoolUtil(unallocated, allocated []resourceapi.Device) float64 {
95
111
func calculateConsumedCounters (devices []resourceapi.Device ) map [string ]map [string ]resource.Quantity {
96
112
countersConsumed := map [string ]map [string ]resource.Quantity {}
97
113
for _ , device := range devices {
114
+ if device .Basic .ConsumesCounters == nil {
115
+ continue
116
+ }
98
117
for _ , consumedCounter := range device .Basic .ConsumesCounters {
99
118
if _ , ok := countersConsumed [consumedCounter .CounterSet ]; ! ok {
100
119
countersConsumed [consumedCounter .CounterSet ] = map [string ]resource.Quantity {}
@@ -110,7 +129,6 @@ func calculateConsumedCounters(devices []resourceapi.Device) map[string]map[stri
110
129
}
111
130
}
112
131
return countersConsumed
113
-
114
132
}
115
133
116
134
func splitDevicesByAllocation (devices []resourceapi.Device , allocatedNames []string ) (unallocated , allocated []resourceapi.Device ) {
0 commit comments