Skip to content

Commit

Permalink
moved client.matching label into associate.go
Browse files Browse the repository at this point in the history
Signed-off-by: owenowenisme <[email protected]>
  • Loading branch information
owenowenisme committed Jan 13, 2025
1 parent 9068102 commit 9e9031f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
8 changes: 8 additions & 0 deletions ray-operator/controllers/ray/common/association.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
15 changes: 6 additions & 9 deletions ray-operator/controllers/ray/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 9e9031f

Please sign in to comment.