fix(raycluster): stop recreate loop on YuniKorn ResourceReservationTimeout #5305
Could you manually verify this and share a screenshot or the relevant kubectl output to confirm the fix works as expected?
thanks @win5923; completed a live kind + yunikorn verify of this branch (kuberay/operator:rrt-5305 / --batch-scheduler=yunikorn).
setup: kind kuberay-rrt, helm yunikorn, operator from this PR. submitted an unsatisfiable hard-gang RayCluster (nvidia.com/gpu: 1 x2 workers, placeholderTimeoutInSeconds=30 gangSchedulingStyle=Hard on the pod templates).
after timeout, pods stay failed with ResourceReservationTimeout (same uids 30s later; no recreate loop), and the cluster surfaces state=failed + BatchSchedulingFailed=True:
$ kubectl get pods -n rrt-demo -o wide
NAME READY STATUS RESTARTS AGE
rrt-hard-gang-gpu-workers-worker-7x8qq 0/1 ResourceReservationTimeout 0 71s
rrt-hard-gang-gpu-workers-worker-drq7q 0/1 ResourceReservationTimeout 0 71s
rrt-hard-gang-head-mwz7b 0/1 ResourceReservationTimeout 0 71s
$ kubectl get pods -n rrt-demo -o custom-columns=NAME:.metadata.name,PHASE:.status.phase,REASON:.status.reason,UID:.metadata.uid
NAME PHASE REASON UID
rrt-hard-gang-gpu-workers-worker-7x8qq Failed ResourceReservationTimeout 27070f50-fbe4-41c8-8c39-0ff42f7f0dfa
rrt-hard-gang-gpu-workers-worker-drq7q Failed ResourceReservationTimeout 9b53a2c1-6f29-4ff9-8fc7-37981edeed59
rrt-hard-gang-head-mwz7b Failed ResourceReservationTimeout b1845b36-82ad-40d6-afe8-72572b2202d2
# +30s later: same three pods / same uids (no recreate)
$ kubectl get raycluster rrt-hard-gang -n rrt-demo -o jsonpath='{.status.state} {.status.reason}{"\n"}'
failed ResourceReservationTimeout
# condition
type=BatchSchedulingFailed status=True reason=ResourceReservationTimeout
message=Batch scheduler failed the gang reservation with ResourceReservationTimeout; Pod recreation is stopped
operator log on reconcile:
reconcilePods: ResourceReservationTimeout Pods observed; skipping pod create/delete to avoid looping against a terminated batch-scheduler application
reconcilePods: skipping pod create/delete because batch scheduler gang reservation failed terminally reason=ResourceReservationTimeout
pinging @kevin85421 @andrewsykim @rueian @MortalHappiness for review when you have a chance.
cc @fscnick @CheyuWu @HsiaoHungKai to take a look when you have time.
The function name Failed is a bit broad and doesn't clearly convey what it's checking. Since it checks ResourceReservationTimeoutReason, would it make sense to rename it to something more descriptive?
Why do we need to check ResourceReservationTimeout again? This condition seems unreachable here since all three shouldDeletePod() calls are made inside reconcilePods(), which has an early return.
good call. renamed to IsRayClusterResourceReservationTimeout so it matches the ResourceReservationTimeout reason it actually checks.
you are right; with the early returns in reconcilePods (status reason + HasResourceReservationTimeoutPods), none of the three shouldDeletePod call sites are reachable for RRT pods (including the multihost path, which is only called from reconcilePods). removed that branch and kept the protection on the early-return path; unit coverage stays on TestReconcilePods_ResourceReservationTimeout.
@fscnick thanks for the review. addressed both points in the latest push:
1. renamed IsRayClusterBatchSchedulingFailed → IsRayClusterResourceReservationTimeout
2. removed the unreachable RRT check from shouldDeletePod (early returns in reconcilePods already cover it)
unit tests for the RRT helpers / TestReconcilePods_ResourceReservationTimeout / TestShouldDeletePod are green locally.
Just noticed that while this PR could fix the issue, it also introduces YuniKorn-specific logic into the general reconciliation flow.
@fscnick agreed; the ResourceReservationTimeout reason string is yunikorn-specific.
the operator has no scheduler callback. it only sees Failed pods with that reason, and recreate is decided inside reconcilePods. that is why the stop lives there. we already removed the duplicate check from shouldDeletePod after your earlier review.
a BatchScheduler plugin hook (issue option 3) was left out of this pr on purpose so other schedulers do not grow inside the general path. happy to do that as a follow-up, or to tuck the reason check behind a small named helper in this pr if you want the boundary now. which do you prefer?
cc @CheyuWu
Discussed with the team offline, and they have some concerns about leaking YuniKorn-specific logic into the general reconciliation flow. Sorry for not noticing this earlier.
In addition, there has been some discussion about whether this PR is actually necessary if the current behavior is considered acceptable. Or, whether there’s a reasonable workaround.
@fscnick thanks for the offline sync and for calling this out.
agreed: hard-coding ResourceReservationTimeout into general reconcilePods / calculateStatus leaks yunikorn-specific logic across the batchscheduler boundary. that was the wrong layer for this fix, even though it stops the recreate loop.
on necessity / workaround:
spec.preRunningDeadlineSeconds (and activeDeadlineSeconds) already fail jobs stuck before running, which matches what you asked on #5301. that looks like a reasonable operator-native workaround for the job path without this pr.applicationId until someone deletes the cluster. soft gang style is also not a substitute for hard-gang semantics.proposal:
1. i can close #5305 (or convert to draft) so we do not merge yunikorn reason checks into general reconcile.
2. please choose one:
(a) close #5301 as workaround-accepted and we document preRunningDeadlineSeconds for yunikorn hard-gang timeouts on rayjob; or
(b) greenlight a thin follow-up that implements issue option 3 only: a generic BatchScheduler terminal-failure hook (or factory watch) with the rrt string living only under batchscheduler/yunikorn/, and general reconcile calling the interface without knowing yunikorn.
i will not push the current design further. happy to take (b) if you want the automatic stop-recreate + status signal without the layering leak; otherwise (a) seems aligned with the team's "is this necessary?" discussion.
cc @win5923 @CheyuWu @kevin85421
win5923
dundysm
Fixes
Fixes #5301
Summary
When YuniKorn hard-gang
placeholderTimeoutInSecondsexpires, Pods are failed withReason: ResourceReservationTimeoutand the YuniKorn application is removed. KubeRay previously treated those as ordinary terminal Pods, deleted them, and recreated replacements against the same deadapplicationId, leaving RayJob running untilactiveDeadlineSeconds.This change:
1. Treats
Failed+ResourceReservationTimeoutas a non-recreate terminal failure inshouldDeletePod.2. Short-circuits
reconcilePodswhen such Pods are present (or whenStatus.Reasonis already set) soWorkersToDeletecannot remove them and trigger recreation.3. Surfaces the failure on RayCluster (
Status.State=failed,Status.Reason=ResourceReservationTimeout, andBatchSchedulingFailedcondition when the status-conditions feature gate is enabled).4. Transitions RayJob to
FailedwithReason=ResourceReservationTimeoutwhile waiting for the cluster to become ready.A broader
BatchSchedulerplugin hook (issue option 3) is left for a follow-up / maintainer design choice; this implements the smallest correct stop-recreate + surface-failure path.Test plan
shouldDeletePodwithFailed+ResourceReservationTimeout