Skip to content

Commit 6cb920c

Browse files
committed
Add support for additional resources in capabilities for MachineClass
1 parent 9223614 commit 6cb920c

7 files changed

Lines changed: 238 additions & 116 deletions

File tree

broker/machinebroker/server/status.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,22 @@ func (s *Server) convertIronCoreMachineClassStatus(machineClass *computev1alpha1
8383
cpu := machineClass.Capabilities.CPU()
8484
memory := machineClass.Capabilities.Memory()
8585

86+
additionalResources := map[string]int64{}
87+
resourceList := machineClass.Capabilities
88+
89+
for resource, quantity := range resourceList {
90+
if string(resource) != string(corev1alpha1.ResourceCPU) && string(resource) != string(corev1alpha1.ResourceMemory) {
91+
additionalResources[string(resource)] = quantity.Value()
92+
}
93+
}
94+
8695
return &iri.MachineClassStatus{
8796
MachineClass: &iri.MachineClass{
8897
Name: machineClass.Name,
8998
Capabilities: &iri.MachineClassCapabilities{
90-
CpuMillis: cpu.MilliValue(),
91-
MemoryBytes: memory.Value(),
99+
CpuMillis: cpu.MilliValue(),
100+
MemoryBytes: memory.Value(),
101+
AdditionalResources: additionalResources,
92102
},
93103
},
94104
Quantity: quantity.Value(),

internal/controllers/compute/machine_scheduler_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)