From 39fbfcd14b9336208fc5583eaf3a82e1ec943999 Mon Sep 17 00:00:00 2001 From: jessestutler Date: Tue, 10 Sep 2024 16:25:34 +0800 Subject: [PATCH] fix: not remove podgroup uid will cause topology annotation to be useless Signed-off-by: jessestutler --- .../plugins/task-topology/topology.go | 10 +- .../plugins/task-topology/topology_test.go | 96 ++++++++++++------- 2 files changed, 66 insertions(+), 40 deletions(-) diff --git a/pkg/scheduler/plugins/task-topology/topology.go b/pkg/scheduler/plugins/task-topology/topology.go index 268deaea84f..f3e63d08d2a 100644 --- a/pkg/scheduler/plugins/task-topology/topology.go +++ b/pkg/scheduler/plugins/task-topology/topology.go @@ -247,15 +247,9 @@ 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 { - // 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 + if _, exist := taskRef[task.TaskRole]; !exist { + taskRef[task.TaskRole] = true } } diff --git a/pkg/scheduler/plugins/task-topology/topology_test.go b/pkg/scheduler/plugins/task-topology/topology_test.go index 6d304e6bd3a..56fc2aeefbe 100644 --- a/pkg/scheduler/plugins/task-topology/topology_test.go +++ b/pkg/scheduler/plugins/task-topology/topology_test.go @@ -41,22 +41,28 @@ func Test_readTopologyFromPgAnnotations(t *testing.T) { Namespace: "default", Tasks: map[api.TaskID]*api.TaskInfo{ "0": { - Name: "job1-ps-0", + Name: "job1-ps-0", + TaskRole: "ps", }, "1": { - Name: "job1-ps-1", + Name: "job1-ps-1", + TaskRole: "ps", }, "2": { - Name: "job1-worker-0", + Name: "job1-worker-0", + TaskRole: "worker", }, "3": { - Name: "job1-worker-1", + Name: "job1-worker-1", + TaskRole: "worker", }, "4": { - Name: "job1-chief-0", + Name: "job1-chief-0", + TaskRole: "chief", }, "5": { - Name: "job1-evaluator-0", + Name: "job1-evaluator-0", + TaskRole: "evaluator", }, }, PodGroup: &api.PodGroup{ @@ -107,22 +113,28 @@ func Test_readTopologyFromPgAnnotations(t *testing.T) { Namespace: "default", Tasks: map[api.TaskID]*api.TaskInfo{ "0": { - Name: "job1-ps-some-0", + Name: "job1-ps-some-0", + TaskRole: "ps-some", }, "1": { - Name: "job1-ps-some-1", + Name: "job1-ps-some-1", + TaskRole: "ps-some", }, "2": { - Name: "job1-worker-another-some-0", + Name: "job1-worker-another-some-0", + TaskRole: "worker-another-some", }, "3": { - Name: "job1-worker-another-some-1", + Name: "job1-worker-another-some-1", + TaskRole: "worker-another-some", }, "4": { - Name: "job1-chief-kk-0", + Name: "job1-chief-kk-0", + TaskRole: "chief-kk", }, "5": { - Name: "job1-evaluator-tt-0", + Name: "job1-evaluator-tt-0", + TaskRole: "evaluator-tt", }, }, PodGroup: &api.PodGroup{ @@ -187,22 +199,28 @@ func Test_readTopologyFromPgAnnotations(t *testing.T) { Namespace: "default", Tasks: map[api.TaskID]*api.TaskInfo{ "0": { - Name: "job1-ps-0", + Name: "job1-ps-0", + TaskRole: "ps", }, "1": { - Name: "job1-ps-1", + Name: "job1-ps-1", + TaskRole: "ps", }, "2": { - Name: "job1-worker-0", + Name: "job1-worker-0", + TaskRole: "worker", }, "3": { - Name: "job1-worker-1", + Name: "job1-worker-1", + TaskRole: "worker", }, "4": { - Name: "job1-chief-0", + Name: "job1-chief-0", + TaskRole: "chief", }, "5": { - Name: "job1-evaluator-0", + Name: "job1-evaluator-0", + TaskRole: "evaluator", }, }, PodGroup: &api.PodGroup{ @@ -227,16 +245,20 @@ func Test_readTopologyFromPgAnnotations(t *testing.T) { Namespace: "default", Tasks: map[api.TaskID]*api.TaskInfo{ "0": { - Name: "job1-ps-0", + Name: "job1-ps-0", + TaskRole: "ps", }, "1": { - Name: "job1-ps-1", + Name: "job1-ps-1", + TaskRole: "ps", }, "2": { - Name: "job1-worker-0", + Name: "job1-worker-0", + TaskRole: "worker", }, "3": { - Name: "job1-worker-1", + Name: "job1-worker-1", + TaskRole: "worker", }, }, PodGroup: &api.PodGroup{ @@ -261,16 +283,20 @@ func Test_readTopologyFromPgAnnotations(t *testing.T) { Namespace: "default", Tasks: map[api.TaskID]*api.TaskInfo{ "0": { - Name: "job1-ps-0", + Name: "job1-ps-0", + TaskRole: "ps", }, "1": { - Name: "job1-ps-1", + Name: "job1-ps-1", + TaskRole: "ps", }, "2": { - Name: "job1-worker-0", + Name: "job1-worker-0", + TaskRole: "worker", }, "3": { - Name: "job1-worker-1", + Name: "job1-worker-1", + TaskRole: "worker", }, }, PodGroup: &api.PodGroup{ @@ -295,22 +321,28 @@ func Test_readTopologyFromPgAnnotations(t *testing.T) { Namespace: "default", Tasks: map[api.TaskID]*api.TaskInfo{ "0": { - Name: "job1-ps-0", + Name: "job1-ps-0", + TaskRole: "ps", }, "1": { - Name: "job1-ps-1", + Name: "job1-ps-1", + TaskRole: "ps", }, "2": { - Name: "job1-worker-0", + Name: "job1-worker-0", + TaskRole: "worker", }, "3": { - Name: "job1-worker-1", + Name: "job1-worker-1", + TaskRole: "worker", }, "4": { - Name: "job1-chief-0", + Name: "job1-chief-0", + TaskRole: "chief", }, "5": { - Name: "job1-evaluator-0", + Name: "job1-evaluator-0", + TaskRole: "evaluator", }, }, PodGroup: &api.PodGroup{