Skip to content

Commit 09c3853

Browse files
committed
feat: add schedulerName to pod for second scheduler
Signed-off-by: Cheyu Wu <[email protected]>
1 parent 9be8abd commit 09c3853

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

ray-operator/controllers/ray/batchscheduler/scheduler-plugins/scheduler_plugins.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ func (k *KubeScheduler) AddMetadataToPod(_ context.Context, app *rayv1.RayCluste
9999
if k.isGangSchedulingEnabled(app) {
100100
pod.Labels[kubeSchedulerPodGroupLabelKey] = app.Name
101101
}
102-
// TODO(kevin85421): Currently, we only support "single scheduler" mode. If we want to support
103-
// "second scheduler" mode, we need to add `schedulerName` to the pod spec.
102+
pod.Spec.SchedulerName = k.Name()
104103
}
105104

106105
func (k *KubeScheduler) isGangSchedulingEnabled(app *rayv1.RayCluster) bool {

ray-operator/controllers/ray/batchscheduler/scheduler-plugins/scheduler_plugins_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,54 @@ func TestCreatePodGroup(t *testing.T) {
9696
// 1 head and 2 workers
9797
a.Equal(int32(3), podGroup.Spec.MinMember)
9898
}
99+
100+
func TestAddMetadataToPod(t *testing.T) {
101+
tests := []struct {
102+
name string
103+
enableGang bool
104+
podHasLabels bool
105+
expectedPodGroup bool
106+
}{
107+
{"GangEnabled_WithLabels", true, true, true},
108+
{"GangDisabled_WithLabels", false, true, false},
109+
{"GangDisabled_WithoutLabels", false, false, false},
110+
}
111+
112+
for _, tt := range tests {
113+
t.Run(tt.name, func(t *testing.T) {
114+
a := assert.New(t)
115+
cluster := createTestRayCluster(1)
116+
if cluster.Labels == nil {
117+
cluster.Labels = make(map[string]string)
118+
}
119+
if tt.enableGang {
120+
cluster.Labels["ray.io/gang-scheduling-enabled"] = "true"
121+
} else {
122+
delete(cluster.Labels, "ray.io/gang-scheduling-enabled")
123+
}
124+
125+
var pod *corev1.Pod
126+
if tt.podHasLabels {
127+
pod = &corev1.Pod{
128+
ObjectMeta: metav1.ObjectMeta{
129+
Labels: map[string]string{},
130+
},
131+
}
132+
} else {
133+
pod = &corev1.Pod{}
134+
}
135+
136+
scheduler := &KubeScheduler{}
137+
scheduler.AddMetadataToPod(context.TODO(), &cluster, "worker", pod)
138+
139+
if tt.expectedPodGroup {
140+
a.Equal(cluster.Name, pod.Labels[kubeSchedulerPodGroupLabelKey])
141+
} else {
142+
_, exists := pod.Labels[kubeSchedulerPodGroupLabelKey]
143+
a.False(exists)
144+
}
145+
146+
a.Equal(scheduler.Name(), pod.Spec.SchedulerName)
147+
})
148+
}
149+
}

0 commit comments

Comments
 (0)