Skip to content

Commit

Permalink
fix: if the capability cpu or memory is not specified in the hierarch…
Browse files Browse the repository at this point in the history
…ical queue, it will be set to the corresponding value of the parent queue

Signed-off-by: JesseStutler <[email protected]>
  • Loading branch information
JesseStutler committed Dec 25, 2024
1 parent b0c1a56 commit 9754ae3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
38 changes: 26 additions & 12 deletions pkg/scheduler/plugins/capacity/capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,7 @@ func (cp *capacityPlugin) buildHierarchicalQueueAttrs(ssn *framework.Session) bo
continue
}

attr := cp.newQueueAttr(queue)
cp.queueOpts[queue.UID] = attr
err := cp.updateParents(queue, ssn)
err := cp.initializeHierarchicalQueueAttrs(queue, ssn)
if err != nil {
klog.Errorf("Failed to update Queue <%s> attributes, error: %v", queue.Name, err)
return false
Expand Down Expand Up @@ -579,7 +577,7 @@ func (cp *capacityPlugin) buildHierarchicalQueueAttrs(ssn *framework.Session) bo
return true
}

func (cp *capacityPlugin) newQueueAttr(queue *api.QueueInfo) *queueAttr {
func (cp *capacityPlugin) newQueueAttr(queue *api.QueueInfo, parent *api.QueueInfo) *queueAttr {
attr := &queueAttr{
queueID: queue.UID,
name: queue.Name,
Expand All @@ -593,13 +591,29 @@ func (cp *capacityPlugin) newQueueAttr(queue *api.QueueInfo) *queueAttr {
inqueue: api.EmptyResource(),
guarantee: api.EmptyResource(),
}

if queue.Name == cp.rootQueue {
attr.realCapability = cp.totalResource
attr.capability = attr.realCapability
attr.deserved = cp.totalResource
return attr
}

if len(queue.Queue.Spec.Capability) != 0 {
attr.capability = api.NewResource(queue.Queue.Spec.Capability)
parentCapability := api.EmptyResource()
if parent.Queue.Name == cp.rootQueue {
// if current queue's parent is root, set parentCapability to totalResource (because root's realCapability is totalResource, and the attr of root queue may not have been initialized yet)
parentCapability = cp.totalResource
} else {
parentCapability = api.NewResource(parent.Queue.Spec.Capability)
}
// If the user does not set CPU or memory in capability, we set the value to be the same as parent (we do not consider the situation where the user sets CPU or memory<=0)
if attr.capability.MilliCPU <= 0 {
attr.capability.MilliCPU = math.MaxFloat64
attr.capability.MilliCPU = parentCapability.MilliCPU
}
if attr.capability.Memory <= 0 {
attr.capability.Memory = math.MaxFloat64
attr.capability.Memory = parentCapability.Memory
}
}

Expand All @@ -610,8 +624,9 @@ func (cp *capacityPlugin) newQueueAttr(queue *api.QueueInfo) *queueAttr {
return attr
}

func (cp *capacityPlugin) updateParents(queue *api.QueueInfo, ssn *framework.Session) error {
func (cp *capacityPlugin) initializeHierarchicalQueueAttrs(queue *api.QueueInfo, ssn *framework.Session) error {
if queue.Name == cp.rootQueue {
cp.queueOpts[queue.UID] = cp.newQueueAttr(queue, nil)
return nil
}

Expand All @@ -624,10 +639,11 @@ func (cp *capacityPlugin) updateParents(queue *api.QueueInfo, ssn *framework.Ses
}

parentInfo := ssn.Queues[api.QueueID(parent)]
curQueueAttr := cp.newQueueAttr(queue, parentInfo)
cp.queueOpts[curQueueAttr.queueID] = curQueueAttr

if _, found := cp.queueOpts[parentInfo.UID]; !found {
parentAttr := cp.newQueueAttr(parentInfo)
cp.queueOpts[parentAttr.queueID] = parentAttr
err := cp.updateParents(parentInfo, ssn)
err := cp.initializeHierarchicalQueueAttrs(parentInfo, ssn)
if err != nil {
return err
}
Expand All @@ -653,8 +669,6 @@ func (cp *capacityPlugin) checkHierarchicalQueue(attr *queueAttr) error {
if attr.name == cp.rootQueue {
attr.guarantee = totalGuarantee
cp.totalGuarantee = totalGuarantee
attr.realCapability = cp.totalResource
attr.deserved = cp.totalResource
}

for _, childAttr := range attr.children {
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/plugins/capacity/capacity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func Test_capacityPlugin_OnSessionOpenWithHierarchy(t *testing.T) {
// podgroup
pg1 := util.BuildPodGroup("pg1", "ns1", "q11", 1, nil, schedulingv1beta1.PodGroupInqueue)
// queue
root := buildQueueWithParents("root", "", api.BuildResourceList("8", "8Gi", []api.ScalarResource{{Name: "pods", Value: "10"}}...), api.BuildResourceList("8", "8Gi", []api.ScalarResource{{Name: "pods", Value: "10"}}...))
root := buildQueueWithParents("root", "", nil, nil)
queue1 := buildQueueWithParents("q1", "root", nil, api.BuildResourceList("4", "4Gi"))
queue2 := buildQueueWithParents("q2", "root", nil, api.BuildResourceList("4", "4Gi"))
queue11 := buildQueueWithParents("q11", "q1", nil, api.BuildResourceList("1", "1Gi"))
Expand Down

0 comments on commit 9754ae3

Please sign in to comment.