Skip to content

Commit

Permalink
[Refactor][RayService] Add GetRayClusterWithRayServiceAssociationOpti…
Browse files Browse the repository at this point in the history
  • Loading branch information
evalaiyc98 authored Apr 22, 2024
1 parent 7af8988 commit b8212e5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
10 changes: 10 additions & 0 deletions ray-operator/controllers/ray/common/association.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ func RayClusterAllPodsAssociationOptions(instance *rayv1.RayCluster) Association
}
}

func RayServiceRayClustersAssociationOptions(rayService *rayv1.RayService) AssociationOptions {
return AssociationOptions{
client.InNamespace(rayService.Namespace),
client.MatchingLabels{
utils.RayOriginatedFromCRNameLabelKey: rayService.Name,
utils.RayOriginatedFromCRDLabelKey: utils.RayOriginatedFromCRDLabelValue(utils.RayServiceCRD),
},
}
}

func RayServiceServeServiceNamespacedName(rayService *rayv1.RayService) types.NamespacedName {
if rayService.Spec.ServeService != nil && rayService.Spec.ServeService.Name != "" {
return types.NamespacedName{
Expand Down
11 changes: 3 additions & 8 deletions ray-operator/controllers/ray/rayservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,9 @@ func (r *RayServiceReconciler) reconcileRayCluster(ctx context.Context, rayServi
func (r *RayServiceReconciler) cleanUpRayClusterInstance(ctx context.Context, rayServiceInstance *rayv1.RayService) error {
logger := ctrl.LoggerFrom(ctx)
rayClusterList := rayv1.RayClusterList{}
filterLabels := client.MatchingLabels{
utils.RayOriginatedFromCRNameLabelKey: rayServiceInstance.Name,
utils.RayOriginatedFromCRDLabelKey: utils.RayOriginatedFromCRDLabelValue(utils.RayServiceCRD),
}

var err error
if err = r.List(ctx, &rayClusterList, client.InNamespace(rayServiceInstance.Namespace), filterLabels); err != nil {
if err = r.List(ctx, &rayClusterList, common.RayServiceRayClustersAssociationOptions(rayServiceInstance).ToListOptions()...); err != nil {
logger.Error(err, "Fail to list RayCluster for "+rayServiceInstance.Name)
return err
}
Expand Down Expand Up @@ -1237,9 +1234,7 @@ func isServeAppUnhealthyOrDeployedFailed(appStatus string) bool {
// TODO: Move this function to util.go and always use this function to retrieve the head Pod.
func (r *RayServiceReconciler) getHeadPod(ctx context.Context, instance *rayv1.RayCluster) (*corev1.Pod, error) {
podList := corev1.PodList{}
filterLabels := client.MatchingLabels{utils.RayClusterLabelKey: instance.Name, utils.RayNodeTypeLabelKey: string(rayv1.HeadNode)}

if err := r.List(ctx, &podList, client.InNamespace(instance.Namespace), filterLabels); err != nil {
if err := r.List(ctx, &podList, common.RayClusterHeadPodsAssociationOptions(instance).ToListOptions()...); err != nil {
return nil, err
}

Expand Down
5 changes: 3 additions & 2 deletions ray-operator/controllers/ray/rayservice_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"os"
"time"

"github.com/ray-project/kuberay/ray-operator/controllers/ray/common"

"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"

"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -247,9 +249,8 @@ var _ = Context("Inside the default namespace", func() {
})

It("should create more than 1 worker", func() {
filterLabels := client.MatchingLabels{utils.RayClusterLabelKey: myRayService.Status.ActiveServiceStatus.RayClusterName, utils.RayNodeGroupLabelKey: "small-group"}
Eventually(
listResourceFunc(ctx, &workerPods, filterLabels, &client.ListOptions{Namespace: "default"}),
listResourceFunc(ctx, &workerPods, common.RayClusterGroupPodsAssociationOptions(myRayCluster, "small-group").ToListOptions()...),
time.Second*15, time.Millisecond*500).Should(Equal(3), fmt.Sprintf("workerGroup %v", workerPods.Items))
if len(workerPods.Items) > 0 {
Expect(workerPods.Items[0].Status.Phase).Should(Or(Equal(corev1.PodRunning), Equal(corev1.PodPending)))
Expand Down

0 comments on commit b8212e5

Please sign in to comment.