diff --git a/ray-operator/controllers/ray/common/association.go b/ray-operator/controllers/ray/common/association.go index 59f956309a2..c85383917c6 100644 --- a/ray-operator/controllers/ray/common/association.go +++ b/ray-operator/controllers/ray/common/association.go @@ -54,7 +54,7 @@ func (list AssociationOptions) ToDeleteOptions() (options []client.DeleteAllOfOp return options } -func RayClusterHeadPodsRelatedAssociationOptions(instance *rayv1.RayCluster) AssociationOptions { +func RayClusterHeadPodsAssociationOptions(instance *rayv1.RayCluster) AssociationOptions { return AssociationOptions{ client.InNamespace(instance.Namespace), client.MatchingLabels{ diff --git a/ray-operator/controllers/ray/raycluster_controller.go b/ray-operator/controllers/ray/raycluster_controller.go index efa1a83b84b..3fd30790c0a 100644 --- a/ray-operator/controllers/ray/raycluster_controller.go +++ b/ray-operator/controllers/ray/raycluster_controller.go @@ -230,7 +230,7 @@ func (r *RayClusterReconciler) rayClusterReconcile(ctx context.Context, request "DeletionTimestamp", instance.ObjectMeta.DeletionTimestamp) // Delete the head Pod if it exists. - headPods, err := r.deleteAllPods(ctx, common.RayClusterHeadPodsRelatedAssociationOptions(instance)) + headPods, err := r.deleteAllPods(ctx, common.RayClusterHeadPodsAssociationOptions(instance)) if err != nil { return ctrl.Result{RequeueAfter: DefaultRequeueDuration}, err } @@ -504,7 +504,7 @@ func (r *RayClusterReconciler) reconcileHeadService(ctx context.Context, instanc logger := ctrl.LoggerFrom(ctx) services := corev1.ServiceList{} - if err := r.List(ctx, &services, common.RayClusterHeadPodsRelatedAssociationOptions(instance).ToListOptions()...); err != nil { + if err := r.List(ctx, &services, common.RayClusterHeadPodsAssociationOptions(instance).ToListOptions()...); err != nil { return err } @@ -633,7 +633,7 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv // check if all the pods exist headPods := corev1.PodList{} - if err := r.List(ctx, &headPods, common.RayClusterHeadPodsRelatedAssociationOptions(instance).ToListOptions()...); err != nil { + if err := r.List(ctx, &headPods, common.RayClusterHeadPodsAssociationOptions(instance).ToListOptions()...); err != nil { return err } if EnableBatchScheduler { @@ -1292,12 +1292,12 @@ func (r *RayClusterReconciler) getHeadPodIP(ctx context.Context, instance *rayv1 logger := ctrl.LoggerFrom(ctx) runtimePods := corev1.PodList{} - if err := r.List(ctx, &runtimePods, common.RayClusterHeadPodsRelatedAssociationOptions(instance).ToListOptions()...); err != nil { + if err := r.List(ctx, &runtimePods, common.RayClusterHeadPodsAssociationOptions(instance).ToListOptions()...); err != nil { logger.Error(err, "Failed to list pods while getting head pod ip.") return "", err } if len(runtimePods.Items) != 1 { - logger.Info(fmt.Sprintf("Found %d head pods. cluster name %s, filter labels %v", len(runtimePods.Items), instance.Name, common.RayClusterHeadPodsRelatedAssociationOptions(instance).ToListOptions())) + logger.Info(fmt.Sprintf("Found %d head pods. cluster name %s, filter labels %v", len(runtimePods.Items), instance.Name, common.RayClusterHeadPodsAssociationOptions(instance).ToListOptions())) return "", nil } return runtimePods.Items[0].Status.PodIP, nil @@ -1325,7 +1325,7 @@ func (r *RayClusterReconciler) updateEndpoints(ctx context.Context, instance *ra // We assume we can find the right one by filtering Services with appropriate label selectors // and picking the first one. We may need to select by name in the future if the Service naming is stable. rayHeadSvc := corev1.ServiceList{} - if err := r.List(ctx, &rayHeadSvc, common.RayClusterHeadPodsRelatedAssociationOptions(instance).ToListOptions()...); err != nil { + if err := r.List(ctx, &rayHeadSvc, common.RayClusterHeadPodsAssociationOptions(instance).ToListOptions()...); err != nil { return err } @@ -1350,7 +1350,7 @@ func (r *RayClusterReconciler) updateEndpoints(ctx context.Context, instance *ra } } } else { - logger.Info("updateEndpoints", "unable to find a Service for this RayCluster. Not adding RayCluster status.endpoints", instance.Name, "Service selectors", common.RayClusterHeadPodsRelatedAssociationOptions(instance).ToListOptions()) + logger.Info("updateEndpoints", "unable to find a Service for this RayCluster. Not adding RayCluster status.endpoints", instance.Name, "Service selectors", common.RayClusterHeadPodsAssociationOptions(instance).ToListOptions()) } return nil diff --git a/ray-operator/controllers/ray/raycluster_controller_test.go b/ray-operator/controllers/ray/raycluster_controller_test.go index cd4ed584b2b..5873a9912f4 100644 --- a/ray-operator/controllers/ray/raycluster_controller_test.go +++ b/ray-operator/controllers/ray/raycluster_controller_test.go @@ -91,7 +91,7 @@ var _ = Context("Inside the default namespace", func() { headPods := corev1.PodList{} workerPods := corev1.PodList{} workerFilters := common.RayClusterGroupPodsAssociationOptions(rayCluster, rayCluster.Spec.WorkerGroupSpecs[0].GroupName).ToListOptions() - headFilters := common.RayClusterHeadPodsRelatedAssociationOptions(rayCluster).ToListOptions() + headFilters := common.RayClusterHeadPodsAssociationOptions(rayCluster).ToListOptions() It("Verify RayCluster spec", func() { // These test are designed based on the following assumptions: @@ -318,7 +318,7 @@ var _ = Context("Inside the default namespace", func() { workerPods := corev1.PodList{} allPods := corev1.PodList{} workerFilters := common.RayClusterGroupPodsAssociationOptions(rayCluster, rayCluster.Spec.WorkerGroupSpecs[0].GroupName).ToListOptions() - headFilters := common.RayClusterHeadPodsRelatedAssociationOptions(rayCluster).ToListOptions() + headFilters := common.RayClusterHeadPodsAssociationOptions(rayCluster).ToListOptions() allFilters := common.RayClusterRelatedAssociationOptions(rayCluster).ToListOptions() It("Verify RayCluster spec", func() { @@ -573,7 +573,7 @@ var _ = Context("Inside the default namespace", func() { headPods := corev1.PodList{} workerPods := corev1.PodList{} workerFilters := common.RayClusterGroupPodsAssociationOptions(rayCluster, rayCluster.Spec.WorkerGroupSpecs[0].GroupName).ToListOptions() - headFilters := common.RayClusterHeadPodsRelatedAssociationOptions(rayCluster).ToListOptions() + headFilters := common.RayClusterHeadPodsAssociationOptions(rayCluster).ToListOptions() It("Create a RayCluster with PodTemplate referencing a different namespace.", func() { rayCluster.Spec.HeadGroupSpec.Template.ObjectMeta.Namespace = "not-default" diff --git a/ray-operator/controllers/ray/suite_helpers_test.go b/ray-operator/controllers/ray/suite_helpers_test.go index 63d86dff5d6..f20ba90b3ed 100644 --- a/ray-operator/controllers/ray/suite_helpers_test.go +++ b/ray-operator/controllers/ray/suite_helpers_test.go @@ -210,7 +210,7 @@ func updateHeadPodToRunningAndReady(ctx context.Context, rayClusterName string, time.Second*3, time.Millisecond*500).Should(gomega.BeNil(), "RayCluster %v not found", rayClusterName) headPods := corev1.PodList{} - headLabels := common.RayClusterHeadPodsRelatedAssociationOptions(&instance).ToListOptions() + headLabels := common.RayClusterHeadPodsAssociationOptions(&instance).ToListOptions() gomega.Eventually( listResourceFunc(ctx, &headPods, headLabels...),