From b56d8539f8a7a6701af1e40ca5f9eed278209620 Mon Sep 17 00:00:00 2001 From: james Date: Fri, 3 Jul 2026 10:40:47 +0800 Subject: [PATCH] fix: count the resource if reqnum > 1 Signed-off-by: james --- pkg/scheduler/webhook.go | 6 +++--- pkg/scheduler/webhook_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) 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, }, {