Skip to content

Commit

Permalink
Merge pull request #3913 from JesseStutler/czc_dev
Browse files Browse the repository at this point in the history
fix: hierarchical queue webhook validation use listing podgroups instead
  • Loading branch information
volcano-sh-bot authored Jan 12, 2025
2 parents abc1f8c + 2b06848 commit 9185a93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pkg/webhooks/admission/queues/validate/validate_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
13 changes: 11 additions & 2 deletions pkg/webhooks/admission/queues/validate/validate_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1050,7 +1052,9 @@ func TestAdmitHierarchicalQueues(t *testing.T) {
Parent: "root",
},
Status: schedulingv1beta1.QueueStatus{
Running: 2,
Allocated: v1.ResourceList{
v1.ResourcePods: resource.MustParse("1"),
},
},
}

Expand All @@ -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{
Expand Down Expand Up @@ -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",
},
},
},
Expand Down

0 comments on commit 9185a93

Please sign in to comment.