mirror of
https://github.com/hanzo-ml/kuberay.git
synced 2026-10-30 19:48:47 +00:00
* support scheduler plugins * add unit test update ValidateBatchSchedulerConfig() update helm chart Rename the function. * Update the role in helm chart. And ensure the crd is installed before start the operator. * Fix CI lint * Modify ray version in raycluster sample. * Update the scheduler name * Update the test * update and add TODOs --------- Signed-off-by: kunwuluan <[email protected]> Signed-off-by: KunWuLuan <[email protected]> Signed-off-by: kaihsun <[email protected]> Co-authored-by: GreenHand <[email protected]> Co-authored-by: yueming.wk <[email protected]>
99 lines
2.4 KiB
Go
99 lines
2.4 KiB
Go
package schedulerplugins
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
corev1 "k8s.io/api/core/v1"
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/utils/ptr"
|
|
|
|
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
|
|
)
|
|
|
|
func createTestRayCluster(numOfHosts int32) rayv1.RayCluster {
|
|
headSpec := corev1.PodSpec{
|
|
Containers: []corev1.Container{
|
|
{
|
|
Name: "ray-head",
|
|
Resources: corev1.ResourceRequirements{
|
|
Limits: corev1.ResourceList{
|
|
corev1.ResourceCPU: resource.MustParse("500m"),
|
|
corev1.ResourceMemory: resource.MustParse("512Mi"),
|
|
},
|
|
Requests: corev1.ResourceList{
|
|
corev1.ResourceCPU: resource.MustParse("256m"),
|
|
corev1.ResourceMemory: resource.MustParse("256Mi"),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
workerSpec := corev1.PodSpec{
|
|
Containers: []corev1.Container{
|
|
{
|
|
Name: "ray-worker",
|
|
Resources: corev1.ResourceRequirements{
|
|
Limits: corev1.ResourceList{
|
|
corev1.ResourceCPU: resource.MustParse("500m"),
|
|
corev1.ResourceMemory: resource.MustParse("512Mi"),
|
|
"nvidia.com/gpu": resource.MustParse("1"),
|
|
},
|
|
Requests: corev1.ResourceList{
|
|
corev1.ResourceCPU: resource.MustParse("256m"),
|
|
corev1.ResourceMemory: resource.MustParse("256Mi"),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
return rayv1.RayCluster{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "raycluster-sample",
|
|
Namespace: "default",
|
|
},
|
|
Spec: rayv1.RayClusterSpec{
|
|
HeadGroupSpec: rayv1.HeadGroupSpec{
|
|
Template: corev1.PodTemplateSpec{
|
|
Spec: headSpec,
|
|
},
|
|
},
|
|
WorkerGroupSpecs: []rayv1.WorkerGroupSpec{
|
|
{
|
|
Template: corev1.PodTemplateSpec{
|
|
Spec: workerSpec,
|
|
},
|
|
Replicas: ptr.To[int32](2),
|
|
NumOfHosts: numOfHosts,
|
|
MinReplicas: ptr.To[int32](1),
|
|
MaxReplicas: ptr.To[int32](4),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func TestCreatePodGroup(t *testing.T) {
|
|
a := assert.New(t)
|
|
|
|
cluster := createTestRayCluster(1)
|
|
|
|
podGroup := createPodGroup(context.TODO(), &cluster)
|
|
|
|
// 256m * 3 (requests, not limits)
|
|
a.Equal("768m", podGroup.Spec.MinResources.Cpu().String())
|
|
|
|
// 256Mi * 3 (requests, not limits)
|
|
a.Equal("768Mi", podGroup.Spec.MinResources.Memory().String())
|
|
|
|
// 2 GPUs total
|
|
a.Equal("2", podGroup.Spec.MinResources.Name("nvidia.com/gpu", resource.BinarySI).String())
|
|
|
|
// 1 head and 2 workers
|
|
a.Equal(int32(3), podGroup.Spec.MinMember)
|
|
}
|