@@ -179,9 +179,9 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, request ctrl.Reque
179
179
return ctrl.Result {}, client .IgnoreNotFound (err )
180
180
}
181
181
182
- func (r * RayClusterReconciler ) deleteAllPods (ctx context.Context , namespace string , filterLabels client. MatchingLabels ) (pods corev1.PodList , err error ) {
182
+ func (r * RayClusterReconciler ) deleteAllPods (ctx context.Context , filters common. AssociationOptions ) (pods corev1.PodList , err error ) {
183
183
logger := ctrl .LoggerFrom (ctx )
184
- if err = r .List (ctx , & pods , client . InNamespace ( namespace ), filterLabels ); err != nil {
184
+ if err = r .List (ctx , & pods , filters . ToListOptions () ... ); err != nil {
185
185
return pods , err
186
186
}
187
187
active := 0
@@ -191,8 +191,8 @@ func (r *RayClusterReconciler) deleteAllPods(ctx context.Context, namespace stri
191
191
}
192
192
}
193
193
if active > 0 {
194
- logger .Info ("Deleting all Pods with labels" , "filterLabels " , filterLabels , "Number of active Pods" , active )
195
- return pods , r .DeleteAllOf (ctx , & corev1.Pod {}, client . InNamespace ( namespace ), filterLabels )
194
+ logger .Info ("Deleting all Pods with labels" , "filters " , filters , "Number of active Pods" , active )
195
+ return pods , r .DeleteAllOf (ctx , & corev1.Pod {}, filters . ToDeleteOptions () ... )
196
196
}
197
197
return pods , nil
198
198
}
@@ -230,18 +230,12 @@ func (r *RayClusterReconciler) rayClusterReconcile(ctx context.Context, request
230
230
"DeletionTimestamp" , instance .ObjectMeta .DeletionTimestamp )
231
231
232
232
// Delete the head Pod if it exists.
233
- headPods , err := r .deleteAllPods (ctx , instance .Namespace , client.MatchingLabels {
234
- utils .RayClusterLabelKey : instance .Name ,
235
- utils .RayNodeTypeLabelKey : string (rayv1 .HeadNode ),
236
- })
233
+ headPods , err := r .deleteAllPods (ctx , common .RayClusterHeadPodsAssociationOptions (instance ))
237
234
if err != nil {
238
235
return ctrl.Result {RequeueAfter : DefaultRequeueDuration }, err
239
236
}
240
237
// Delete all worker Pods if they exist.
241
- if _ , err = r .deleteAllPods (ctx , instance .Namespace , client.MatchingLabels {
242
- utils .RayClusterLabelKey : instance .Name ,
243
- utils .RayNodeTypeLabelKey : string (rayv1 .WorkerNode ),
244
- }); err != nil {
238
+ if _ , err = r .deleteAllPods (ctx , common .RayClusterWorkerPodsAssociationOptions (instance )); err != nil {
245
239
return ctrl.Result {RequeueAfter : DefaultRequeueDuration }, err
246
240
}
247
241
if len (headPods .Items ) > 0 {
@@ -631,8 +625,7 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv
631
625
632
626
// if RayCluster is suspended, delete all pods and skip reconcile
633
627
if instance .Spec .Suspend != nil && * instance .Spec .Suspend {
634
- clusterLabel := client.MatchingLabels {utils .RayClusterLabelKey : instance .Name }
635
- if _ , err := r .deleteAllPods (ctx , instance .Namespace , clusterLabel ); err != nil {
628
+ if _ , err := r .deleteAllPods (ctx , common .RayClusterAllPodsAssociationOptions (instance )); err != nil {
636
629
return err
637
630
}
638
631
@@ -644,8 +637,7 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv
644
637
645
638
// check if all the pods exist
646
639
headPods := corev1.PodList {}
647
- filterLabels := client.MatchingLabels {utils .RayClusterLabelKey : instance .Name , utils .RayNodeTypeLabelKey : string (rayv1 .HeadNode )}
648
- if err := r .List (ctx , & headPods , client .InNamespace (instance .Namespace ), filterLabels ); err != nil {
640
+ if err := r .List (ctx , & headPods , common .RayClusterHeadPodsAssociationOptions (instance ).ToListOptions ()... ); err != nil {
649
641
return err
650
642
}
651
643
if EnableBatchScheduler {
@@ -721,8 +713,7 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv
721
713
// check if WorkerGroupSpecs has been changed and we need to kill worker pods
722
714
for _ , worker := range instance .Spec .WorkerGroupSpecs {
723
715
workerPods := corev1.PodList {}
724
- filterLabels = client.MatchingLabels {utils .RayClusterLabelKey : instance .Name , utils .RayNodeGroupLabelKey : worker .GroupName }
725
- if err := r .List (ctx , & workerPods , client .InNamespace (instance .Namespace ), filterLabels ); err != nil {
716
+ if err := r .List (ctx , & workerPods , common .RayClusterGroupPodsAssociationOptions (instance , worker .GroupName ).ToListOptions ()... ); err != nil {
726
717
return err
727
718
}
728
719
updatedWorkerPods := false
@@ -749,8 +740,7 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv
749
740
logger .Info ("reconcilePods" , "desired workerReplicas (always adhering to minReplicas/maxReplica)" , workerReplicas , "worker group" , worker .GroupName , "maxReplicas" , worker .MaxReplicas , "minReplicas" , worker .MinReplicas , "replicas" , worker .Replicas )
750
741
751
742
workerPods := corev1.PodList {}
752
- filterLabels = client.MatchingLabels {utils .RayClusterLabelKey : instance .Name , utils .RayNodeGroupLabelKey : worker .GroupName }
753
- if err := r .List (ctx , & workerPods , client .InNamespace (instance .Namespace ), filterLabels ); err != nil {
743
+ if err := r .List (ctx , & workerPods , common .RayClusterGroupPodsAssociationOptions (instance , worker .GroupName ).ToListOptions ()... ); err != nil {
754
744
return err
755
745
}
756
746
0 commit comments