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 20, 2025
1 parent 5cd981c commit d465e97
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ray-operator/controllers/ray/common/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions ray-operator/controllers/ray/common/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"context"
"reflect"
"strings"
"testing"

"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
Expand Down Expand Up @@ -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)))
}
2 changes: 1 addition & 1 deletion ray-operator/controllers/ray/common/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions ray-operator/controllers/ray/common/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)))
}
1 change: 1 addition & 0 deletions ray-operator/test/e2e/raycluster_gcs_ft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func TestRayClusterGCSFTWithMaximumNames(t *testing.T) {
).
WithRayVersion(GetRayVersion()).
WithHeadGroupSpec(rayv1ac.HeadGroupSpec().
WithEnableIngress(true).
WithRayStartParams(map[string]string{
"num-cpus": "0",
}).
Expand Down

0 comments on commit d465e97

Please sign in to comment.