Skip to content

Commit

Permalink
put back the queue to priority queue after job's resource allocating …
Browse files Browse the repository at this point in the history
…finished

Signed-off-by: Panos Woo <panoswoo@outlook.com>
  • Loading branch information
panoswoo committed Apr 16, 2024
1 parent b53d6d8 commit a803f35
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pkg/scheduler/actions/allocate/allocate.go
Expand Up @@ -151,9 +151,6 @@ func (alloc *Action) allocateResources(queues *util.PriorityQueue, jobsMap map[a
}
tasks := pendingTasks[job.UID]

// Added Queue back until no job in Namespace.
queues.Push(queue)

if tasks.Empty() {
continue
}
Expand All @@ -162,6 +159,10 @@ func (alloc *Action) allocateResources(queues *util.PriorityQueue, jobsMap map[a
tasks.Len(), job.Namespace, job.Name)

alloc.allocateResourcesForTasks(tasks, job, jobs, queue, allNodes)

// Put back the queue to priority queue after job's resource allocating finished,
// to ensure that the priority of the queue is calculated based on the latest resource allocation situation.
queues.Push(queue)
}
}

Expand Down
55 changes: 54 additions & 1 deletion pkg/scheduler/actions/allocate/allocate_test.go
Expand Up @@ -133,9 +133,61 @@ func TestAllocate(t *testing.T) {
},
BindsNum: 1,
},
{
Name: "high priority queue should allocate first",
PodGroups: []*schedulingv1.PodGroup{
util.BuildPodGroup("pg-small-1", "ns-1", "q-1", 0, nil, schedulingv1.PodGroupRunning),
util.BuildPodGroup("pg-large-1", "ns-1", "q-1", 0, nil, schedulingv1.PodGroupInqueue),
util.BuildPodGroup("pg-large-2", "ns-1", "q-2", 0, nil, schedulingv1.PodGroupInqueue),
},
Pods: []*v1.Pod{
util.BuildPod("ns-1", "pod-small-1", "node-1", v1.PodRunning, api.BuildResourceList("1", "1G"), "pg-small-1", make(map[string]string), make(map[string]string)),
util.BuildPod("ns-1", "pod-large-1", "", v1.PodPending, api.BuildResourceList("2", "2G"), "pg-large-1", make(map[string]string), make(map[string]string)),
util.BuildPod("ns-1", "pod-large-2", "", v1.PodPending, api.BuildResourceList("3", "2G"), "pg-large-2", make(map[string]string), make(map[string]string)),
},
Nodes: []*v1.Node{
util.BuildNode("node-1", api.BuildResourceList("5", "5G", []api.ScalarResource{{Name: "pods", Value: "10"}}...), make(map[string]string)),
},
Queues: []*schedulingv1.Queue{
util.BuildQueue("q-1", 1, nil),
util.BuildQueue("q-2", 1, nil),
},
Bind: map[string]string{
"ns-1/pod-large-2": "node-1",
},
BindsNum: 1,
},
{
Name: "queue’s priority should be updated before it is put back into the priority queue",
PodGroups: []*schedulingv1.PodGroup{
util.BuildPodGroup("pg-small-1", "ns-1", "q-1", 0, nil, schedulingv1.PodGroupRunning),
util.BuildPodGroup("pg-large-1", "ns-1", "q-1", 0, nil, schedulingv1.PodGroupInqueue),
util.BuildPodGroup("pg-small-2", "ns-1", "q-2", 0, nil, schedulingv1.PodGroupInqueue),
util.BuildPodGroup("pg-large-2", "ns-1", "q-2", 0, nil, schedulingv1.PodGroupInqueue),
},
Pods: []*v1.Pod{
util.BuildPod("ns-1", "pod-small-1", "node-1", v1.PodRunning, api.BuildResourceList("1", "1G"), "pg-small-1", make(map[string]string), make(map[string]string)),
util.BuildPod("ns-1", "pod-large-1", "", v1.PodPending, api.BuildResourceList("2", "2G"), "pg-large-1", make(map[string]string), make(map[string]string)),
util.BuildPod("ns-1", "pod-large-2", "", v1.PodPending, api.BuildResourceList("2", "2G"), "pg-large-2", make(map[string]string), make(map[string]string)),
util.BuildPod("ns-1", "pod-small-2", "", v1.PodPending, api.BuildResourceList("1", "1G"), "pg-small-2", make(map[string]string), make(map[string]string)),
},
Nodes: []*v1.Node{
util.BuildNode("node-1", api.BuildResourceList("5", "5G", []api.ScalarResource{{Name: "pods", Value: "10"}}...), make(map[string]string)),
},
Queues: []*schedulingv1.Queue{
util.BuildQueue("q-1", 1, nil),
util.BuildQueue("q-2", 1, nil),
},
Bind: map[string]string{
"ns-1/pod-large-1": "node-1",
"ns-1/pod-large-2": "node-1",
},
BindsNum: 2,
},
}

trueValue := true
falseValue := false
tiers := []conf.Tier{
{
Plugins: []conf.PluginOption{
Expand All @@ -146,9 +198,10 @@ func TestAllocate(t *testing.T) {
},
{
Name: "proportion",
EnabledOverused: &falseValue,
EnabledQueueOrder: &trueValue,
EnabledReclaimable: &trueValue,
EnabledAllocatable: &trueValue,
EnabledAllocatable: &falseValue,
},
{
Name: predicates.PluginName,
Expand Down

0 comments on commit a803f35

Please sign in to comment.