From d465e9771491b907f4824bfce35405f8bfe6dc39 Mon Sep 17 00:00:00 2001 From: Rueian Date: Thu, 20 Feb 2025 15:47:37 -0800 Subject: [PATCH] feat: validate the length of RayCluster name and worker group names Signed-off-by: Rueian --- ray-operator/controllers/ray/common/ingress.go | 2 +- ray-operator/controllers/ray/common/ingress_test.go | 12 ++++++++++++ ray-operator/controllers/ray/common/route.go | 2 +- ray-operator/controllers/ray/common/route_test.go | 12 ++++++++++++ ray-operator/test/e2e/raycluster_gcs_ft_test.go | 1 + 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ray-operator/controllers/ray/common/ingress.go b/ray-operator/controllers/ray/common/ingress.go index 24fa0d41ca9..f09df072664 100644 --- a/ray-operator/controllers/ray/common/ingress.go +++ b/ray-operator/controllers/ray/common/ingress.go @@ -68,7 +68,7 @@ func BuildIngressForHeadService(ctx context.Context, cluster rayv1.RayCluster) ( ingress := &networkingv1.Ingress{ ObjectMeta: metav1.ObjectMeta{ - Name: utils.GenerateIngressName(cluster.Name), + Name: utils.CheckLabel(utils.GenerateIngressName(cluster.Name)), Namespace: cluster.Namespace, Labels: labels, Annotations: annotation, diff --git a/ray-operator/controllers/ray/common/ingress_test.go b/ray-operator/controllers/ray/common/ingress_test.go index 537a6c4a97c..e37d385bb42 100644 --- a/ray-operator/controllers/ray/common/ingress_test.go +++ b/ray-operator/controllers/ray/common/ingress_test.go @@ -3,6 +3,7 @@ package common import ( "context" "reflect" + "strings" "testing" "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils" @@ -132,3 +133,14 @@ func TestBuildIngressForHeadService(t *testing.T) { } } } + +func TestBuildIngressForHeadServiceForMaximumClusterName(t *testing.T) { + cluster := instanceWithIngressEnabled.DeepCopy() + cluster.Name = strings.Repeat("A", 63) + + ingress, err := BuildIngressForHeadService(context.Background(), *cluster) + require.NoError(t, err) + + require.NotEqual(t, ingress.Name, utils.GenerateIngressName(cluster.Name)) + require.Equal(t, ingress.Name, utils.CheckLabel(utils.GenerateIngressName(cluster.Name))) +} diff --git a/ray-operator/controllers/ray/common/route.go b/ray-operator/controllers/ray/common/route.go index c220192660d..8ba158f101d 100644 --- a/ray-operator/controllers/ray/common/route.go +++ b/ray-operator/controllers/ray/common/route.go @@ -42,7 +42,7 @@ func BuildRouteForHeadService(cluster rayv1.RayCluster) (*routev1.Route, error) route := &routev1.Route{ ObjectMeta: metav1.ObjectMeta{ - Name: utils.GenerateRouteName(cluster.Name), + Name: utils.CheckLabel(utils.GenerateRouteName(cluster.Name)), Namespace: cluster.Namespace, Labels: labels, Annotations: annotation, diff --git a/ray-operator/controllers/ray/common/route_test.go b/ray-operator/controllers/ray/common/route_test.go index 7dd3b658906..5f081fa901b 100644 --- a/ray-operator/controllers/ray/common/route_test.go +++ b/ray-operator/controllers/ray/common/route_test.go @@ -11,6 +11,7 @@ import ( "k8s.io/utils/ptr" rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" + "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils" ) var instanceWithRouteEnabled = &rayv1.RayCluster{ @@ -70,3 +71,14 @@ func TestBuildRouteForHeadService(t *testing.T) { t.Fatalf("Error generating service port. Expected `%v` but got `%v`", expectedPort, route.Spec.Port.TargetPort) } } + +func TestBuildRouteForHeadServiceForMaximumClusterName(t *testing.T) { + cluster := instanceWithRouteEnabled.DeepCopy() + cluster.Name = strings.Repeat("A", 63) + + route, err := BuildRouteForHeadService(*cluster) + require.NoError(t, err) + + require.NotEqual(t, route.Name, utils.GenerateRouteName(cluster.Name)) + require.Equal(t, route.Name, utils.CheckLabel(utils.GenerateRouteName(cluster.Name))) +} diff --git a/ray-operator/test/e2e/raycluster_gcs_ft_test.go b/ray-operator/test/e2e/raycluster_gcs_ft_test.go index cd389edbb57..6f92c48ab7d 100644 --- a/ray-operator/test/e2e/raycluster_gcs_ft_test.go +++ b/ray-operator/test/e2e/raycluster_gcs_ft_test.go @@ -154,6 +154,7 @@ func TestRayClusterGCSFTWithMaximumNames(t *testing.T) { ). WithRayVersion(GetRayVersion()). WithHeadGroupSpec(rayv1ac.HeadGroupSpec(). + WithEnableIngress(true). WithRayStartParams(map[string]string{ "num-cpus": "0", }).