@@ -16,13 +16,13 @@ import (
1616 "sigs.k8s.io/controller-runtime/pkg/client/fake"
1717)
1818
19- func newHypervisorWithCapacity (name , capacityCPU , capacityMem string ) * hv1.Hypervisor {
19+ func newHypervisorWithEffectiveCapacity (name , capacityCPU , capacityMem string ) * hv1.Hypervisor {
2020 return & hv1.Hypervisor {
2121 ObjectMeta : metav1.ObjectMeta {
2222 Name : name ,
2323 },
2424 Status : hv1.HypervisorStatus {
25- Capacity : map [hv1.ResourceName ]resource.Quantity {
25+ EffectiveCapacity : map [hv1.ResourceName ]resource.Quantity {
2626 hv1 .ResourceCPU : resource .MustParse (capacityCPU ),
2727 hv1 .ResourceMemory : resource .MustParse (capacityMem ),
2828 },
@@ -189,9 +189,9 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
189189 {
190190 name : "smallest host gets highest score with memory weight only" ,
191191 hypervisors : []* hv1.Hypervisor {
192- newHypervisorWithCapacity ("host1" , "100" , "64Gi" ), // smallest memory
193- newHypervisorWithCapacity ("host2" , "100" , "128Gi" ), // middle memory
194- newHypervisorWithCapacity ("host3" , "100" , "256Gi" ), // largest memory
192+ newHypervisorWithEffectiveCapacity ("host1" , "100" , "64Gi" ), // smallest memory
193+ newHypervisorWithEffectiveCapacity ("host2" , "100" , "128Gi" ), // middle memory
194+ newHypervisorWithEffectiveCapacity ("host3" , "100" , "256Gi" ), // largest memory
195195 },
196196 request : newPreferSmallerHostsRequest ([]string {"host1" , "host2" , "host3" }),
197197 opts : KVMPreferSmallerHostsStepOpts {
@@ -209,9 +209,9 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
209209 {
210210 name : "smallest host gets highest score with cpu weight only" ,
211211 hypervisors : []* hv1.Hypervisor {
212- newHypervisorWithCapacity ("host1" , "64" , "100Gi" ), // smallest CPU
213- newHypervisorWithCapacity ("host2" , "128" , "100Gi" ), // middle CPU
214- newHypervisorWithCapacity ("host3" , "256" , "100Gi" ), // largest CPU
212+ newHypervisorWithEffectiveCapacity ("host1" , "64" , "100Gi" ), // smallest CPU
213+ newHypervisorWithEffectiveCapacity ("host2" , "128" , "100Gi" ), // middle CPU
214+ newHypervisorWithEffectiveCapacity ("host3" , "256" , "100Gi" ), // largest CPU
215215 },
216216 request : newPreferSmallerHostsRequest ([]string {"host1" , "host2" , "host3" }),
217217 opts : KVMPreferSmallerHostsStepOpts {
@@ -230,11 +230,11 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
230230 name : "weighted average with both cpu and memory weights" ,
231231 hypervisors : []* hv1.Hypervisor {
232232 // host1: smallest memory (64Gi), largest CPU (256) -> mem score=1.0, cpu score=0.0
233- newHypervisorWithCapacity ("host1" , "256" , "64Gi" ),
233+ newHypervisorWithEffectiveCapacity ("host1" , "256" , "64Gi" ),
234234 // host2: middle memory (128Gi), middle CPU (128) -> mem score=0.667, cpu score=0.667
235- newHypervisorWithCapacity ("host2" , "128" , "128Gi" ),
235+ newHypervisorWithEffectiveCapacity ("host2" , "128" , "128Gi" ),
236236 // host3: largest memory (256Gi), smallest CPU (64) -> mem score=0.0, cpu score=1.0
237- newHypervisorWithCapacity ("host3" , "64" , "256Gi" ),
237+ newHypervisorWithEffectiveCapacity ("host3" , "64" , "256Gi" ),
238238 },
239239 request : newPreferSmallerHostsRequest ([]string {"host1" , "host2" , "host3" }),
240240 opts : KVMPreferSmallerHostsStepOpts {
@@ -257,9 +257,9 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
257257 name : "different weights for cpu and memory" ,
258258 hypervisors : []* hv1.Hypervisor {
259259 // host1: smallest memory (64Gi), largest CPU (256) -> mem score=1.0, cpu score=0.0
260- newHypervisorWithCapacity ("host1" , "256" , "64Gi" ),
260+ newHypervisorWithEffectiveCapacity ("host1" , "256" , "64Gi" ),
261261 // host2: largest memory (256Gi), smallest CPU (64) -> mem score=0.0, cpu score=1.0
262- newHypervisorWithCapacity ("host2" , "64" , "256Gi" ),
262+ newHypervisorWithEffectiveCapacity ("host2" , "64" , "256Gi" ),
263263 },
264264 request : newPreferSmallerHostsRequest ([]string {"host1" , "host2" }),
265265 opts : KVMPreferSmallerHostsStepOpts {
@@ -279,8 +279,8 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
279279 {
280280 name : "two hosts with different sizes" ,
281281 hypervisors : []* hv1.Hypervisor {
282- newHypervisorWithCapacity ("host1" , "100" , "100Gi" ),
283- newHypervisorWithCapacity ("host2" , "100" , "200Gi" ),
282+ newHypervisorWithEffectiveCapacity ("host1" , "100" , "100Gi" ),
283+ newHypervisorWithEffectiveCapacity ("host2" , "100" , "200Gi" ),
284284 },
285285 request : newPreferSmallerHostsRequest ([]string {"host1" , "host2" }),
286286 opts : KVMPreferSmallerHostsStepOpts {
@@ -297,9 +297,9 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
297297 {
298298 name : "all hosts have same memory capacity" ,
299299 hypervisors : []* hv1.Hypervisor {
300- newHypervisorWithCapacity ("host1" , "100" , "128Gi" ),
301- newHypervisorWithCapacity ("host2" , "100" , "128Gi" ),
302- newHypervisorWithCapacity ("host3" , "100" , "128Gi" ),
300+ newHypervisorWithEffectiveCapacity ("host1" , "100" , "128Gi" ),
301+ newHypervisorWithEffectiveCapacity ("host2" , "100" , "128Gi" ),
302+ newHypervisorWithEffectiveCapacity ("host3" , "100" , "128Gi" ),
303303 },
304304 request : newPreferSmallerHostsRequest ([]string {"host1" , "host2" , "host3" }),
305305 opts : KVMPreferSmallerHostsStepOpts {
@@ -318,7 +318,7 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
318318 {
319319 name : "single host" ,
320320 hypervisors : []* hv1.Hypervisor {
321- newHypervisorWithCapacity ("host1" , "100" , "128Gi" ),
321+ newHypervisorWithEffectiveCapacity ("host1" , "100" , "128Gi" ),
322322 },
323323 request : newPreferSmallerHostsRequest ([]string {"host1" }),
324324 opts : KVMPreferSmallerHostsStepOpts {
@@ -351,8 +351,8 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
351351 {
352352 name : "hypervisor missing for one host" ,
353353 hypervisors : []* hv1.Hypervisor {
354- newHypervisorWithCapacity ("host1" , "100" , "64Gi" ),
355- newHypervisorWithCapacity ("host2" , "100" , "128Gi" ),
354+ newHypervisorWithEffectiveCapacity ("host1" , "100" , "64Gi" ),
355+ newHypervisorWithEffectiveCapacity ("host2" , "100" , "128Gi" ),
356356 // host3 hypervisor is missing
357357 },
358358 request : newPreferSmallerHostsRequest ([]string {"host1" , "host2" , "host3" }),
@@ -371,12 +371,12 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
371371 {
372372 name : "hypervisor without memory capacity" ,
373373 hypervisors : []* hv1.Hypervisor {
374- newHypervisorWithCapacity ("host1" , "100" , "64Gi" ),
375- newHypervisorWithCapacity ("host2" , "100" , "128Gi" ),
374+ newHypervisorWithEffectiveCapacity ("host1" , "100" , "64Gi" ),
375+ newHypervisorWithEffectiveCapacity ("host2" , "100" , "128Gi" ),
376376 {
377377 ObjectMeta : metav1.ObjectMeta {Name : "host3" },
378378 Status : hv1.HypervisorStatus {
379- Capacity : map [hv1.ResourceName ]resource.Quantity {
379+ EffectiveCapacity : map [hv1.ResourceName ]resource.Quantity {
380380 hv1 .ResourceCPU : resource .MustParse ("100" ),
381381 // No memory capacity
382382 },
@@ -399,9 +399,9 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
399399 {
400400 name : "host filtered out by previous steps" ,
401401 hypervisors : []* hv1.Hypervisor {
402- newHypervisorWithCapacity ("host1" , "100" , "64Gi" ),
403- newHypervisorWithCapacity ("host2" , "100" , "128Gi" ),
404- newHypervisorWithCapacity ("host3" , "100" , "256Gi" ),
402+ newHypervisorWithEffectiveCapacity ("host1" , "100" , "64Gi" ),
403+ newHypervisorWithEffectiveCapacity ("host2" , "100" , "128Gi" ),
404+ newHypervisorWithEffectiveCapacity ("host3" , "100" , "256Gi" ),
405405 },
406406 // Only host1 and host2 in the request (host3 was filtered out)
407407 request : newPreferSmallerHostsRequest ([]string {"host1" , "host2" }),
@@ -419,9 +419,9 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
419419 {
420420 name : "varied memory sizes - score calculation" ,
421421 hypervisors : []* hv1.Hypervisor {
422- newHypervisorWithCapacity ("host1" , "100" , "100Gi" ), // smallest
423- newHypervisorWithCapacity ("host2" , "100" , "150Gi" ), // middle
424- newHypervisorWithCapacity ("host3" , "100" , "200Gi" ), // largest
422+ newHypervisorWithEffectiveCapacity ("host1" , "100" , "100Gi" ), // smallest
423+ newHypervisorWithEffectiveCapacity ("host2" , "100" , "150Gi" ), // middle
424+ newHypervisorWithEffectiveCapacity ("host3" , "100" , "200Gi" ), // largest
425425 },
426426 request : newPreferSmallerHostsRequest ([]string {"host1" , "host2" , "host3" }),
427427 opts : KVMPreferSmallerHostsStepOpts {
@@ -440,10 +440,10 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
440440 {
441441 name : "four hosts with varying sizes" ,
442442 hypervisors : []* hv1.Hypervisor {
443- newHypervisorWithCapacity ("host1" , "100" , "64Gi" ),
444- newHypervisorWithCapacity ("host2" , "100" , "96Gi" ),
445- newHypervisorWithCapacity ("host3" , "100" , "128Gi" ),
446- newHypervisorWithCapacity ("host4" , "100" , "192Gi" ),
443+ newHypervisorWithEffectiveCapacity ("host1" , "100" , "64Gi" ),
444+ newHypervisorWithEffectiveCapacity ("host2" , "100" , "96Gi" ),
445+ newHypervisorWithEffectiveCapacity ("host3" , "100" , "128Gi" ),
446+ newHypervisorWithEffectiveCapacity ("host4" , "100" , "192Gi" ),
447447 },
448448 request : newPreferSmallerHostsRequest ([]string {"host1" , "host2" , "host3" , "host4" }),
449449 opts : KVMPreferSmallerHostsStepOpts {
@@ -466,13 +466,13 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
466466 {
467467 ObjectMeta : metav1.ObjectMeta {Name : "host1" },
468468 Status : hv1.HypervisorStatus {
469- Capacity : map [hv1.ResourceName ]resource.Quantity {},
469+ EffectiveCapacity : map [hv1.ResourceName ]resource.Quantity {},
470470 },
471471 },
472472 {
473473 ObjectMeta : metav1.ObjectMeta {Name : "host2" },
474474 Status : hv1.HypervisorStatus {
475- Capacity : map [hv1.ResourceName ]resource.Quantity {},
475+ EffectiveCapacity : map [hv1.ResourceName ]resource.Quantity {},
476476 },
477477 },
478478 },
@@ -492,8 +492,8 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
492492 {
493493 name : "very small difference in memory" ,
494494 hypervisors : []* hv1.Hypervisor {
495- newHypervisorWithCapacity ("host1" , "100" , "128Gi" ),
496- newHypervisorWithCapacity ("host2" , "100" , "129Gi" ),
495+ newHypervisorWithEffectiveCapacity ("host1" , "100" , "128Gi" ),
496+ newHypervisorWithEffectiveCapacity ("host2" , "100" , "129Gi" ),
497497 },
498498 request : newPreferSmallerHostsRequest ([]string {"host1" , "host2" }),
499499 opts : KVMPreferSmallerHostsStepOpts {
@@ -510,10 +510,10 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
510510 {
511511 name : "extra hypervisors not in request" ,
512512 hypervisors : []* hv1.Hypervisor {
513- newHypervisorWithCapacity ("host1" , "100" , "64Gi" ),
514- newHypervisorWithCapacity ("host2" , "100" , "128Gi" ),
515- newHypervisorWithCapacity ("host3" , "100" , "256Gi" ), // not in request
516- newHypervisorWithCapacity ("host4" , "100" , "512Gi" ), // not in request
513+ newHypervisorWithEffectiveCapacity ("host1" , "100" , "64Gi" ),
514+ newHypervisorWithEffectiveCapacity ("host2" , "100" , "128Gi" ),
515+ newHypervisorWithEffectiveCapacity ("host3" , "100" , "256Gi" ), // not in request
516+ newHypervisorWithEffectiveCapacity ("host4" , "100" , "512Gi" ), // not in request
517517 },
518518 request : newPreferSmallerHostsRequest ([]string {"host1" , "host2" }),
519519 opts : KVMPreferSmallerHostsStepOpts {
@@ -534,7 +534,7 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
534534 {
535535 ObjectMeta : metav1.ObjectMeta {Name : "host1" },
536536 Status : hv1.HypervisorStatus {
537- Capacity : map [hv1.ResourceName ]resource.Quantity {
537+ EffectiveCapacity : map [hv1.ResourceName ]resource.Quantity {
538538 hv1 .ResourceMemory : resource .MustParse ("64Gi" ),
539539 // No CPU
540540 },
@@ -543,7 +543,7 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
543543 {
544544 ObjectMeta : metav1.ObjectMeta {Name : "host2" },
545545 Status : hv1.HypervisorStatus {
546- Capacity : map [hv1.ResourceName ]resource.Quantity {
546+ EffectiveCapacity : map [hv1.ResourceName ]resource.Quantity {
547547 hv1 .ResourceMemory : resource .MustParse ("128Gi" ),
548548 // No CPU
549549 },
@@ -567,9 +567,9 @@ func TestKVMPreferSmallerHostsStep_Run(t *testing.T) {
567567 {
568568 name : "zero weight for memory, non-zero for cpu" ,
569569 hypervisors : []* hv1.Hypervisor {
570- newHypervisorWithCapacity ("host1" , "64" , "256Gi" ), // smallest CPU, largest memory
571- newHypervisorWithCapacity ("host2" , "128" , "128Gi" ), // middle
572- newHypervisorWithCapacity ("host3" , "256" , "64Gi" ), // largest CPU, smallest memory
570+ newHypervisorWithEffectiveCapacity ("host1" , "64" , "256Gi" ), // smallest CPU, largest memory
571+ newHypervisorWithEffectiveCapacity ("host2" , "128" , "128Gi" ), // middle
572+ newHypervisorWithEffectiveCapacity ("host3" , "256" , "64Gi" ), // largest CPU, smallest memory
573573 },
574574 request : newPreferSmallerHostsRequest ([]string {"host1" , "host2" , "host3" }),
575575 opts : KVMPreferSmallerHostsStepOpts {
0 commit comments