Skip to content

Commit

Permalink
feat: validate the length of RayCluster name and worker group names
Browse files Browse the repository at this point in the history
Signed-off-by: Rueian <rueiancsie@gmail.com>
  • Loading branch information
rueian committed Feb 25, 2025
1 parent b24ba93 commit 8817876
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions ray-operator/controllers/ray/rayjob_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ var _ = Context("RayJob with different submission modes", func() {
Describe("RayJob with DeletionPolicy=DeleteCluster", Ordered, func() {
ctx := context.Background()
namespace := "default"
rayJob := rayJobTemplate("rayjob-test-deletionpolicy-deletecluster", namespace)
rayJob := rayJobTemplate("rayjob-test-deletionpolicy-1", namespace)
deletionPolicy := rayv1.DeleteClusterDeletionPolicy
rayJob.Spec.DeletionPolicy = &deletionPolicy
rayJob.Spec.ShutdownAfterJobFinishes = false
Expand Down Expand Up @@ -964,7 +964,7 @@ var _ = Context("RayJob with different submission modes", func() {
Describe("RayJob with DeletionPolicy=DeleteWorkers", Ordered, func() {
ctx := context.Background()
namespace := "default"
rayJob := rayJobTemplate("rayjob-test-deletionpolicy-deleteworkers", namespace)
rayJob := rayJobTemplate("rayjob-test-deletionpolicy-2", namespace)
deletionPolicy := rayv1.DeleteWorkersDeletionPolicy
rayJob.Spec.DeletionPolicy = &deletionPolicy
rayJob.Spec.ShutdownAfterJobFinishes = false
Expand Down Expand Up @@ -1213,7 +1213,7 @@ var _ = Context("RayJob with different submission modes", func() {
Describe("RayJob with DeletionPolicy=DeleteNone", Ordered, func() {
ctx := context.Background()
namespace := "default"
rayJob := rayJobTemplate("rayjob-test-deletionpolicy-deletenone", namespace)
rayJob := rayJobTemplate("rayjob-test-deletionpolicy-3", namespace)
deletionPolicy := rayv1.DeleteNoneDeletionPolicy
rayJob.Spec.DeletionPolicy = &deletionPolicy
rayJob.Spec.ShutdownAfterJobFinishes = false
Expand Down
8 changes: 4 additions & 4 deletions ray-operator/controllers/ray/utils/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ func ValidateRayClusterStatus(instance *rayv1.RayCluster) error {

// Validation for invalid Ray Cluster configurations.
func ValidateRayClusterSpec(instance *rayv1.RayCluster) error {
if len(instance.Name) > 63 {
return fmt.Errorf("RayCluster name should be no more than 63 characters")
if len(instance.Name) > 46 {
return fmt.Errorf("RayCluster name should be no more than 46 characters")
}
if len(instance.Spec.HeadGroupSpec.Template.Spec.Containers) == 0 {
return fmt.Errorf("headGroupSpec should have at least one container")
}

for _, workerGroup := range instance.Spec.WorkerGroupSpecs {
if len(workerGroup.GroupName) > 63 {
return fmt.Errorf("group name should be no more than 63 characters")
if len(workerGroup.GroupName) > 46 {
return fmt.Errorf("group name should be no more than 46 characters")
}
if len(workerGroup.Template.Spec.Containers) == 0 {
return fmt.Errorf("workerGroupSpec should have at least one container")
Expand Down
18 changes: 9 additions & 9 deletions ray-operator/controllers/ray/utils/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,17 @@ func TestValidateRayClusterSpecNames(t *testing.T) {
expectError bool
}{
{
name: "RayCluster name is too long (> 63 characters)",
name: "RayCluster name is too long (> 46 characters)",
rayCluster: &rayv1.RayCluster{
ObjectMeta: metav1.ObjectMeta{
Name: strings.Repeat("A", 64),
Name: strings.Repeat("A", 47),
},
},
expectError: true,
errorMessage: "RayCluster name should be no more than 63 characters",
errorMessage: "RayCluster name should be no more than 46 characters",
},
{
name: "Worker group name is too long (> 63 characters)",
name: "Worker group name is too long (> 46 characters)",
rayCluster: &rayv1.RayCluster{
Spec: rayv1.RayClusterSpec{
HeadGroupSpec: rayv1.HeadGroupSpec{
Expand All @@ -404,19 +404,19 @@ func TestValidateRayClusterSpecNames(t *testing.T) {
},
WorkerGroupSpecs: []rayv1.WorkerGroupSpec{
{
GroupName: strings.Repeat("A", 64),
GroupName: strings.Repeat("A", 47),
},
},
},
},
expectError: true,
errorMessage: "group name should be no more than 63 characters",
errorMessage: "group name should be no more than 46 characters",
},
{
name: "Both RayCluster name and Worker group name are ok (== 63 characters)",
name: "Both RayCluster name and Worker group name are ok (== 46 characters)",
rayCluster: &rayv1.RayCluster{
ObjectMeta: metav1.ObjectMeta{
Name: strings.Repeat("A", 63),
Name: strings.Repeat("A", 46),
},
Spec: rayv1.RayClusterSpec{
HeadGroupSpec: rayv1.HeadGroupSpec{
Expand All @@ -428,7 +428,7 @@ func TestValidateRayClusterSpecNames(t *testing.T) {
},
WorkerGroupSpecs: []rayv1.WorkerGroupSpec{
{
GroupName: strings.Repeat("A", 63),
GroupName: strings.Repeat("A", 46),
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{{Name: "ray-worker"}},
Expand Down
6 changes: 3 additions & 3 deletions ray-operator/test/e2e/raycluster_gcs_ft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ func TestRayClusterGCSFTWithMaximumNames(t *testing.T) {
testScript, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Apply(test.Ctx(), testScriptAC, TestApplyOptions)
g.Expect(err).NotTo(HaveOccurred())

test.T().Run("Test Maximum Cluster Name and Group name (63 characters)", func(_ *testing.T) {
maximumRayClusterName := strings.Repeat("r", 63)
maximumWorkerGroupName := strings.Repeat("w", 63)
test.T().Run("Test Maximum Cluster Name and Group name (46 characters)", func(_ *testing.T) {
maximumRayClusterName := strings.Repeat("r", 46)
maximumWorkerGroupName := strings.Repeat("w", 46)

checkRedisDBSize := deployRedis(test, namespace.Name, redisPassword)
defer g.Eventually(checkRedisDBSize, time.Second*30, time.Second).Should(BeEquivalentTo("0"))
Expand Down

0 comments on commit 8817876

Please sign in to comment.