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 <chenzicong4@huawei.com>
  • Loading branch information
JesseStutler committed Dec 24, 2024
1 parent b0c1a56 commit 826142e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 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 @@ -595,11 +593,13 @@ func (cp *capacityPlugin) newQueueAttr(queue *api.QueueInfo) *queueAttr {
}
if len(queue.Queue.Spec.Capability) != 0 {
attr.capability = api.NewResource(queue.Queue.Spec.Capability)
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 +610,10 @@ 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 {
// root's parent is itself
cp.queueOpts[queue.UID] = cp.newQueueAttr(queue, queue)
return nil
}

Expand All @@ -624,10 +626,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 Down

0 comments on commit 826142e

Please sign in to comment.