Skip to content

Commit 9e0d203

Browse files
authored
Did a small refactoring in allocation_info.go (#348)
1 parent dda5ba8 commit 9e0d203

File tree

2 files changed

+3
-27
lines changed

2 files changed

+3
-27
lines changed

pkg/scheduler/api/podgroup_info/allocation_info.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/NVIDIA/KAI-scheduler/pkg/scheduler/api/common_info"
1010
"github.com/NVIDIA/KAI-scheduler/pkg/scheduler/api/common_info/resources"
1111
"github.com/NVIDIA/KAI-scheduler/pkg/scheduler/api/pod_info"
12-
"github.com/NVIDIA/KAI-scheduler/pkg/scheduler/api/pod_status"
1312
"github.com/NVIDIA/KAI-scheduler/pkg/scheduler/api/resource_info"
1413
"github.com/NVIDIA/KAI-scheduler/pkg/scheduler/log"
1514
"github.com/NVIDIA/KAI-scheduler/pkg/scheduler/scheduler_util"
@@ -67,18 +66,6 @@ func GetTasksToAllocateRequestedGPUs(
6766
return tasksTotalRequestedGPUs, tasksTotalRequestedGpuMemory
6867
}
6968

70-
func GetJobsToAllocateInitResource(
71-
podGroupInfos []*PodGroupInfo, taskOrderFn common_info.LessFn, isRealAllocation bool,
72-
) *resource_info.Resource {
73-
tasksTotalRequestedResource := resource_info.EmptyResource()
74-
for _, podGroupInfo := range podGroupInfos {
75-
pgInitResource := GetTasksToAllocateInitResource(podGroupInfo, taskOrderFn, isRealAllocation)
76-
tasksTotalRequestedResource.Add(pgInitResource)
77-
}
78-
79-
return tasksTotalRequestedResource
80-
}
81-
8269
func GetTasksToAllocateInitResource(
8370
podGroupInfo *PodGroupInfo, taskOrderFn common_info.LessFn, isRealAllocation bool,
8471
) *resource_info.Resource {
@@ -113,7 +100,7 @@ func getTasksToAllocateQueue(
113100
}
114101

115102
func getNumOfTasksToAllocate(podGroupInfo *PodGroupInfo, numOfTasksWaitingAllocation int) int {
116-
allocatedTasks := int32(getNumOfAllocatedTasks(podGroupInfo))
103+
allocatedTasks := int32(podGroupInfo.GetActiveAllocatedTasksCount())
117104

118105
var maxTasksToAllocate int32
119106
if allocatedTasks >= podGroupInfo.MinAvailable {
@@ -124,13 +111,3 @@ func getNumOfTasksToAllocate(podGroupInfo *PodGroupInfo, numOfTasksWaitingAlloca
124111

125112
return int(math.Min(float64(maxTasksToAllocate), float64(numOfTasksWaitingAllocation)))
126113
}
127-
128-
func getNumOfAllocatedTasks(podGroupInfo *PodGroupInfo) int {
129-
allocatedTasks := 0
130-
for _, task := range podGroupInfo.PodInfos {
131-
if pod_status.IsActiveAllocatedStatus(task.Status) {
132-
allocatedTasks += 1
133-
}
134-
}
135-
return allocatedTasks
136-
}

pkg/scheduler/api/podgroup_info/allocation_info_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,10 @@ func Test_getMaxNumOfTasksToAllocate(t *testing.T) {
123123
pg.MinAvailable = tt.args.minAvailable
124124
for i, pod := range tt.args.pods {
125125
pi := pod_info.NewTaskInfo(pod)
126-
pg.AddTaskInfo(pi)
127-
128126
if tt.args.overridingStatus != nil {
129127
pi.Status = tt.args.overridingStatus[i]
130128
}
129+
pg.AddTaskInfo(pi)
131130
}
132131

133132
if got := getNumOfTasksToAllocate(pg, tt.args.podsWantingToAllocate); got != tt.want {
@@ -222,7 +221,7 @@ func Test_getNumOfAllocatedTasks(t *testing.T) {
222221
}
223222
}
224223

225-
if got := getNumOfAllocatedTasks(pg); got != tt.want {
224+
if got := pg.GetActiveAllocatedTasksCount(); got != tt.want {
226225
t.Errorf("getNumOfAllocatedTasks() = %v, want %v", got, tt.want)
227226
}
228227
})

0 commit comments

Comments
 (0)