@@ -434,4 +434,75 @@ var _ = Describe("MachineScheduler", func() {
434434 HaveField ("Spec.MachinePoolRef" , Equal (& corev1.LocalObjectReference {Name : machinePool .Name })),
435435 ))
436436 })
437+
438+ It ("should schedule machine on pool with correctly allocatable resources" , func (ctx SpecContext ) {
439+ By ("creating a machine pool" )
440+ machinePool := & computev1alpha1.MachinePool {
441+ ObjectMeta : metav1.ObjectMeta {
442+ GenerateName : "test-pool-" ,
443+ },
444+ }
445+ Expect (k8sClient .Create (ctx , machinePool )).To (Succeed (), "failed to create machine pool" )
446+
447+ By ("patching the machine pool status to contain a machine class" )
448+ Eventually (UpdateStatus (machinePool , func () {
449+ machinePool .Status .AvailableMachineClasses = []corev1.LocalObjectReference {{Name : machineClass .Name }}
450+ machinePool .Status .Allocatable = corev1alpha1.ResourceList {
451+ corev1alpha1 .ClassCountFor (corev1alpha1 .ClassTypeMachineClass , machineClass .Name ): resource .MustParse ("5" ),
452+ }
453+ })).Should (Succeed ())
454+
455+ By ("creating a second machine pool" )
456+ secondMachinePool := & computev1alpha1.MachinePool {
457+ ObjectMeta : metav1.ObjectMeta {
458+ GenerateName : "second-test-pool-" ,
459+ },
460+ }
461+ Expect (k8sClient .Create (ctx , secondMachinePool )).To (Succeed (), "failed to create the second machine pool" )
462+
463+ By ("creating a second machine class" )
464+ secondMachineClass := & computev1alpha1.MachineClass {
465+ ObjectMeta : metav1.ObjectMeta {
466+ GenerateName : "second-machine-class-" ,
467+ },
468+ Capabilities : corev1alpha1.ResourceList {
469+ corev1alpha1 .ResourceCPU : resource .MustParse ("1" ),
470+ corev1alpha1 .ResourceMemory : resource .MustParse ("1Gi" ),
471+ "type-a.vendor.com/gpu" : resource .MustParse ("1" ),
472+ },
473+ }
474+ Expect (k8sClient .Create (ctx , secondMachineClass )).To (Succeed (), "failed to create second machine class" )
475+
476+ By ("patching the second machine pool status to contain a both machine classes" )
477+ Eventually (UpdateStatus (secondMachinePool , func () {
478+ secondMachinePool .Status .AvailableMachineClasses = []corev1.LocalObjectReference {
479+ {Name : machineClass .Name },
480+ {Name : secondMachineClass .Name },
481+ }
482+ secondMachinePool .Status .Allocatable = corev1alpha1.ResourceList {
483+ corev1alpha1 .ClassCountFor (corev1alpha1 .ClassTypeMachineClass , machineClass .Name ): resource .MustParse ("5" ),
484+ corev1alpha1 .ClassCountFor (corev1alpha1 .ClassTypeMachineClass , secondMachineClass .Name ): resource .MustParse ("5" ),
485+ }
486+ })).Should (Succeed ())
487+
488+ By ("creating a machine" )
489+ machine := & computev1alpha1.Machine {
490+ ObjectMeta : metav1.ObjectMeta {
491+ Namespace : ns .Name ,
492+ GenerateName : "test-machine-" ,
493+ },
494+ Spec : computev1alpha1.MachineSpec {
495+ Image : "my-image" ,
496+ MachineClassRef : corev1.LocalObjectReference {
497+ Name : secondMachineClass .Name ,
498+ },
499+ },
500+ }
501+ Expect (k8sClient .Create (ctx , machine )).To (Succeed (), "failed to create the machine" )
502+
503+ By ("checking that the machine is scheduled onto the machine pool" )
504+ Eventually (Object (machine )).Should (SatisfyAll (
505+ HaveField ("Spec.MachinePoolRef.Name" , Equal (secondMachinePool .Name )),
506+ ))
507+ })
437508})
0 commit comments