Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ func (k *KubeScheduler) AddMetadataToPod(_ context.Context, app *rayv1.RayCluste
if k.isGangSchedulingEnabled(app) {
pod.Labels[kubeSchedulerPodGroupLabelKey] = app.Name
}
// TODO(kevin85421): Currently, we only support "single scheduler" mode. If we want to support
// "second scheduler" mode, we need to add `schedulerName` to the pod spec.
pod.Spec.SchedulerName = k.Name()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

func (k *KubeScheduler) isGangSchedulingEnabled(app *rayv1.RayCluster) bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,54 @@ func TestCreatePodGroupWithMultipleHosts(t *testing.T) {
// 1 head and 4 workers
a.Equal(int32(5), podGroup.Spec.MinMember)
}

func TestAddMetadataToPod(t *testing.T) {
tests := []struct {
name string
enableGang bool
podHasLabels bool
expectedPodGroup bool
}{
{"GangEnabled_WithLabels", true, true, true},
{"GangDisabled_WithLabels", false, true, false},
{"GangDisabled_WithoutLabels", false, false, false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := assert.New(t)
cluster := createTestRayCluster(1)
if cluster.Labels == nil {
cluster.Labels = make(map[string]string)
}
if tt.enableGang {
cluster.Labels["ray.io/gang-scheduling-enabled"] = "true"
} else {
delete(cluster.Labels, "ray.io/gang-scheduling-enabled")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be cleaner?

Suggested change
if cluster.Labels == nil {
cluster.Labels = make(map[string]string)
}
if tt.enableGang {
cluster.Labels["ray.io/gang-scheduling-enabled"] = "true"
} else {
delete(cluster.Labels, "ray.io/gang-scheduling-enabled")
}
cluster.Labels = make(map[string]string)
if tt.enableGang {
cluster.Labels["ray.io/gang-scheduling-enabled"] = "true"
}


var pod *corev1.Pod
if tt.podHasLabels {
pod = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{},
},
}
} else {
pod = &corev1.Pod{}
}

scheduler := &KubeScheduler{}
scheduler.AddMetadataToPod(context.TODO(), &cluster, "worker", pod)

if tt.expectedPodGroup {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we simply use enableGang instead of having another parameter? I think they have similar intention.

a.Equal(cluster.Name, pod.Labels[kubeSchedulerPodGroupLabelKey])
} else {
_, exists := pod.Labels[kubeSchedulerPodGroupLabelKey]
a.False(exists)
}

a.Equal(scheduler.Name(), pod.Spec.SchedulerName)
})
}
}
Loading