From 9e9031ff792a2d53cf98a432079207a5123a3970 Mon Sep 17 00:00:00 2001 From: owenowenisme Date: Mon, 13 Jan 2025 01:01:27 +0000 Subject: [PATCH] moved client.matching label into associate.go Signed-off-by: owenowenisme --- .../controllers/ray/common/association.go | 8 ++++++++ .../controllers/ray/raycluster_controller.go | 15 ++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ray-operator/controllers/ray/common/association.go b/ray-operator/controllers/ray/common/association.go index 5566421a29c..0c8fd3377dc 100644 --- a/ray-operator/controllers/ray/common/association.go +++ b/ray-operator/controllers/ray/common/association.go @@ -184,3 +184,11 @@ func GetRayClusterHeadPod(ctx context.Context, reader client.Reader, instance *r } return &runtimePods.Items[0], nil } + +func GetFilteredRayClusterLabel(instance *rayv1.RayCluster) client.MatchingLabels { + return client.MatchingLabels{utils.RayClusterLabelKey: instance.Name} +} + +func GetFilteredRayClusterHeadPodLabel(instance *rayv1.RayCluster, nodeType string) client.MatchingLabels { + return client.MatchingLabels{utils.RayClusterLabelKey: instance.Name, utils.RayNodeTypeLabelKey: nodeType} +} diff --git a/ray-operator/controllers/ray/raycluster_controller.go b/ray-operator/controllers/ray/raycluster_controller.go index 9e42ccc136a..27e2950f6f9 100644 --- a/ray-operator/controllers/ray/raycluster_controller.go +++ b/ray-operator/controllers/ray/raycluster_controller.go @@ -286,7 +286,7 @@ func (r *RayClusterReconciler) rayClusterReconcile(ctx context.Context, instance } // We can start the Redis cleanup process now because the head Pod has been terminated. - filterLabels := client.MatchingLabels{utils.RayClusterLabelKey: instance.Name, utils.RayNodeTypeLabelKey: string(rayv1.RedisCleanupNode)} + filterLabels := common.GetFilteredRayClusterHeadPodLabel(instance, string(rayv1.RedisCleanupNode)) redisCleanupJobs := batchv1.JobList{} if err := r.List(ctx, &redisCleanupJobs, client.InNamespace(instance.Namespace), filterLabels); err != nil { return ctrl.Result{RequeueAfter: DefaultRequeueDuration}, err @@ -481,7 +481,7 @@ func (r *RayClusterReconciler) reconcileIngress(ctx context.Context, instance *r func (r *RayClusterReconciler) reconcileRouteOpenShift(ctx context.Context, instance *rayv1.RayCluster) error { logger := ctrl.LoggerFrom(ctx) headRoutes := routev1.RouteList{} - filterLabels := client.MatchingLabels{utils.RayClusterLabelKey: instance.Name} + filterLabels := common.GetFilteredRayClusterLabel(instance) if err := r.List(ctx, &headRoutes, client.InNamespace(instance.Namespace), filterLabels); err != nil { return err } @@ -512,7 +512,7 @@ func (r *RayClusterReconciler) reconcileRouteOpenShift(ctx context.Context, inst func (r *RayClusterReconciler) reconcileIngressKubernetes(ctx context.Context, instance *rayv1.RayCluster) error { logger := ctrl.LoggerFrom(ctx) headIngresses := networkingv1.IngressList{} - filterLabels := client.MatchingLabels{utils.RayClusterLabelKey: instance.Name} + filterLabels := common.GetFilteredRayClusterLabel(instance) if err := r.List(ctx, &headIngresses, client.InNamespace(instance.Namespace), filterLabels); err != nil { return err } @@ -544,7 +544,7 @@ func (r *RayClusterReconciler) reconcileIngressKubernetes(ctx context.Context, i func (r *RayClusterReconciler) reconcileHeadService(ctx context.Context, instance *rayv1.RayCluster) error { logger := ctrl.LoggerFrom(ctx) services := corev1.ServiceList{} - filterLabels := client.MatchingLabels{utils.RayClusterLabelKey: instance.Name, utils.RayNodeTypeLabelKey: string(rayv1.HeadNode)} + filterLabels := common.GetFilteredRayClusterHeadPodLabel(instance, string(rayv1.HeadNode)) if err := r.List(ctx, &services, client.InNamespace(instance.Namespace), filterLabels); err != nil { return err @@ -1280,7 +1280,7 @@ func (r *RayClusterReconciler) calculateStatus(ctx context.Context, instance *ra newInstance.Status.ObservedGeneration = newInstance.ObjectMeta.Generation runtimePods := corev1.PodList{} - filterLabels := client.MatchingLabels{utils.RayClusterLabelKey: newInstance.Name} + filterLabels := common.GetFilteredRayClusterLabel(newInstance) if err := r.List(ctx, &runtimePods, client.InNamespace(newInstance.Namespace), filterLabels); err != nil { return nil, err } @@ -1450,10 +1450,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{} - filterLabels := client.MatchingLabels{ - utils.RayClusterLabelKey: instance.Name, - utils.RayNodeTypeLabelKey: "head", - } + filterLabels := common.GetFilteredRayClusterHeadPodLabel(instance, string(rayv1.HeadNode)) if err := r.List(ctx, &rayHeadSvc, client.InNamespace(instance.Namespace), filterLabels); err != nil { return err }