Skip to content

Commit

Permalink
Merge pull request #2940 from loheagn/master
Browse files Browse the repository at this point in the history
fix: task-topology plugin cannot handle the tasks whose name contains `-`
  • Loading branch information
volcano-sh-bot committed Mar 8, 2024
2 parents 92df051 + 42b0371 commit d996dde
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
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

0 comments on commit d996dde

Please sign in to comment.