diff --git a/pkg/scheduler/webhook.go b/pkg/scheduler/webhook.go index f3ab758ae5..00b4578e7f 100644 --- a/pkg/scheduler/webhook.go +++ b/pkg/scheduler/webhook.go @@ -135,12 +135,12 @@ func fitResourceQuota(pod *corev1.Pod) bool { } for _, ctr := range pod.Spec.Containers { req, ok := getRequest(&ctr, resourceName) - if ok && req == 1 { + if ok { if memReq, ok := getRequest(&ctr, memResourceName); ok { - memoryReq += memReq + memoryReq += memReq * req } if coreReq, ok := getRequest(&ctr, coreResourceName); ok { - coresReq += coreReq + coresReq += coreReq * req } } } diff --git a/pkg/scheduler/webhook_test.go b/pkg/scheduler/webhook_test.go index 00f356ca55..bb5e9f94df 100644 --- a/pkg/scheduler/webhook_test.go +++ b/pkg/scheduler/webhook_test.go @@ -356,6 +356,33 @@ func TestFitResourceQuota(t *testing.T) { }, }, }, + fit: false, + }, + { + name: "request multiple gpus within quota", + pod: &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-pod", + Namespace: "default", + }, + Spec: corev1.PodSpec{ + SchedulerName: "hami-scheduler", + Containers: []corev1.Container{ + { + Name: "container1", + SecurityContext: &corev1.SecurityContext{ + Privileged: nil, + }, + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + "nvidia.com/gpu": resource.MustParse("2"), + "nvidia.com/gpumem": resource.MustParse("400"), + }, + }, + }, + }, + }, + }, fit: true, }, {