From 2b06848e2cf3c3d8b1048cd3397b06e694523a3d Mon Sep 17 00:00:00 2001 From: JesseStutler Date: Tue, 7 Jan 2025 17:41:57 +0800 Subject: [PATCH] fix: hierarchical queue webhook validation use listing podgroups instead Signed-off-by: JesseStutler --- .../admission/queues/validate/validate_queue.go | 8 ++++---- .../queues/validate/validate_queue_test.go | 13 +++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pkg/webhooks/admission/queues/validate/validate_queue.go b/pkg/webhooks/admission/queues/validate/validate_queue.go index b315f7baae..b0a3ddd63a 100644 --- a/pkg/webhooks/admission/queues/validate/validate_queue.go +++ b/pkg/webhooks/admission/queues/validate/validate_queue.go @@ -23,6 +23,7 @@ import ( admissionv1 "k8s.io/api/admission/v1" whv1 "k8s.io/api/admissionregistration/v1" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/validation/field" @@ -255,10 +256,9 @@ func validateHierarchicalQueue(queue *schedulingv1beta1.Queue) error { return fmt.Errorf("failed to get parent queue of queue %s: %v", queue.Name, err) } - if parentQueue.Status.Pending+parentQueue.Status.Running+parentQueue.Status.Unknown+parentQueue.Status.Inqueue > 0 { - return fmt.Errorf("queue %s cannot be the parent queue of queue %s because it has PodGroups (pending: %d, running: %d, unknown: %d, inqueue: %d)", - parentQueue.Name, queue.Name, parentQueue.Status.Pending, - parentQueue.Status.Running, parentQueue.Status.Unknown, parentQueue.Status.Inqueue) + if allocated, ok := parentQueue.Status.Allocated[v1.ResourcePods]; ok && !allocated.IsZero() { + return fmt.Errorf("queue %s cannot be the parent queue of queue %s because it has allocated Pods: %d", + parentQueue.Name, queue.Name, allocated.Value()) } klog.V(3).Infof("Validation passed for hierarchical queue %s with parent queue %s", diff --git a/pkg/webhooks/admission/queues/validate/validate_queue_test.go b/pkg/webhooks/admission/queues/validate/validate_queue_test.go index 039e644bcd..56a7907e39 100644 --- a/pkg/webhooks/admission/queues/validate/validate_queue_test.go +++ b/pkg/webhooks/admission/queues/validate/validate_queue_test.go @@ -23,7 +23,9 @@ import ( "testing" admissionv1 "k8s.io/api/admission/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" @@ -1050,7 +1052,9 @@ func TestAdmitHierarchicalQueues(t *testing.T) { Parent: "root", }, Status: schedulingv1beta1.QueueStatus{ - Running: 2, + Allocated: v1.ResourceList{ + v1.ResourcePods: resource.MustParse("1"), + }, }, } @@ -1061,6 +1065,11 @@ func TestAdmitHierarchicalQueues(t *testing.T) { Spec: schedulingv1beta1.QueueSpec{ Parent: "root", }, + Status: schedulingv1beta1.QueueStatus{ + Allocated: v1.ResourceList{ + v1.ResourcePods: resource.MustParse("0"), + }, + }, } childQueue := schedulingv1beta1.Queue{ @@ -1130,7 +1139,7 @@ func TestAdmitHierarchicalQueues(t *testing.T) { reviewResponse: &admissionv1.AdmissionResponse{ Allowed: false, Result: &metav1.Status{ - Message: "queue queue-with-jobs cannot be the parent queue of queue parent-queue-with-jobs because it has PodGroups (pending: 0, running: 2, unknown: 0, inqueue: 0)", + Message: "queue queue-with-jobs cannot be the parent queue of queue parent-queue-with-jobs because it has allocated Pods: 1", }, }, },