Skip to content

Commit aa8f8c1

Browse files
refactor: Add a helper to check rule match
Signed-off-by: JiangJiaWei1103 <waynechuang97@gmail.com>
1 parent 72ed628 commit aa8f8c1

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

ray-operator/controllers/ray/rayjob_controller.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,13 +1217,7 @@ func (r *RayJobReconciler) handleDeletionRules(ctx context.Context, rayJob *rayv
12171217
// Categorize all applicable and incomplete rules into "overdue" or "pending".
12181218
for _, rule := range rayJob.Spec.DeletionStrategy.DeletionRules {
12191219
// Skip rules that don't match the current job status or job deployment status.
1220-
var match bool
1221-
if rule.Condition.JobStatus != nil {
1222-
match = *rule.Condition.JobStatus == rayJob.Status.JobStatus
1223-
} else if rule.Condition.JobDeploymentStatus != nil {
1224-
match = *rule.Condition.JobDeploymentStatus == rayJob.Status.JobDeploymentStatus
1225-
}
1226-
if !match {
1220+
if !isDeletionRuleMatched(rule, rayJob) {
12271221
continue
12281222
}
12291223

@@ -1388,6 +1382,17 @@ func (r *RayJobReconciler) executeDeletionPolicy(ctx context.Context, rayJob *ra
13881382
return ctrl.Result{}, nil
13891383
}
13901384

1385+
// isDeletionRuleMatched checks if the deletion rule matches the current job status or job deployment status.
1386+
func isDeletionRuleMatched(rule rayv1.DeletionRule, rayJob *rayv1.RayJob) bool {
1387+
if rule.Condition.JobStatus != nil {
1388+
return *rule.Condition.JobStatus == rayJob.Status.JobStatus
1389+
}
1390+
if rule.Condition.JobDeploymentStatus != nil {
1391+
return *rule.Condition.JobDeploymentStatus == rayJob.Status.JobDeploymentStatus
1392+
}
1393+
return false
1394+
}
1395+
13911396
// isDeletionActionCompleted checks if the state corresponding to a deletion policy is already achieved.
13921397
// This is crucial for making the reconciliation loop idempotent by checking the actual cluster state.
13931398
func (r *RayJobReconciler) isDeletionActionCompleted(ctx context.Context, rayJob *rayv1.RayJob, policy rayv1.DeletionPolicyType) (bool, error) {

0 commit comments

Comments
 (0)