Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: task-topology plugin cannot handle the tasks whose name contains - #2940

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pkg/scheduler/plugins/task-topology/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,15 @@ func affinityCheck(job *api.JobInfo, affinity [][]string) error {

var taskNumber = len(job.Tasks)
var taskRef = make(map[string]bool, taskNumber)
var jobNamePrefix = job.Name + "-"
for _, task := range job.Tasks {
tmpStrings := strings.Split(task.Name, "-")
if _, exist := taskRef[tmpStrings[len(tmpStrings)-2]]; !exist {
taskRef[tmpStrings[len(tmpStrings)-2]] = true
// the full task name looks like "${job name}-${task name}-${index}",
// so we can trim the jobNamePrefix and the indexSuffix to get the short task name.
tmpTaskName := task.Name[:strings.LastIndex(task.Name, "-")]
tmpTaskName = strings.TrimPrefix(tmpTaskName, jobNamePrefix)

if _, exist := taskRef[tmpTaskName]; !exist {
taskRef[tmpTaskName] = true
}
}

Expand Down
66 changes: 66 additions & 0 deletions pkg/scheduler/plugins/task-topology/topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,72 @@ func Test_readTopologyFromPgAnnotations(t *testing.T) {
},
err: nil,
},
{
description: "correct annotation with tasks whose names contain `-`",
job: &api.JobInfo{
Name: "job1",
Namespace: "default",
Tasks: map[api.TaskID]*api.TaskInfo{
"0": {
Name: "job1-ps-some-0",
},
"1": {
Name: "job1-ps-some-1",
},
"2": {
Name: "job1-worker-another-some-0",
},
"3": {
Name: "job1-worker-another-some-1",
},
"4": {
Name: "job1-chief-kk-0",
},
"5": {
Name: "job1-evaluator-tt-0",
},
},
PodGroup: &api.PodGroup{
PodGroup: scheduling.PodGroup{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
JobAffinityAnnotations: "ps-some,worker-another-some;ps-some,chief-kk",
JobAntiAffinityAnnotations: "ps-some;worker-another-some,chief-kk",
TaskOrderAnnotations: "ps-some,worker-another-some,chief-kk,evaluator-tt",
},
},
},
},
},
topology: &TaskTopology{
Affinity: [][]string{
{
"ps-some",
"worker-another-some",
},
{
"ps-some",
"chief-kk",
},
},
AntiAffinity: [][]string{
{
"ps-some",
},
{
"worker-another-some",
"chief-kk",
},
},
TaskOrder: []string{
"ps-some",
"worker-another-some",
"chief-kk",
"evaluator-tt",
},
},
err: nil,
},
{
description: "nil annotation",
job: &api.JobInfo{
Expand Down
Loading