ISSUE DESCRIPTION Standalone elastic RayCluster self-updates raycluster-generation…
- User
ISSUE DESCRIPTION
Standalone elastic RayCluster self-updates raycluster-generation annotation What happened:
A standalone Kueue-managed elastic RayCluster is continuously updated by Kueue.
The
kueue.x-k8s.io/raycluster-generationannotation tracks the RayCluster's ownmetadata.generation, but remains one value behind. For example:consolemetadata.generation: 273390 kueue.x-k8s.io/raycluster-generation: "273389"A later read showed the same pattern:
consolemetadata.generation: 273462 kueue.x-k8s.io/raycluster-generation: "273461"Kueue logs showed repeated RayCluster reconciles followed by RayCluster update webhook calls from the Kueue controller manager.
This is a self-triggered loop in the RayCluster custom annotation path. For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name). That helper fetches the same RayCluster and returns the fetched RayCluster generation as an annotation to write back onto the RayCluster. The metadata patch then advances the RayCluster generation, making the annotation stale again.What you expected to happen:
Kueue should not continuously patch a standalone elastic RayCluster when its replica counts have not changed.
The
raycluster-generationannotation is useful for RayJob and RayService, where the top-level object needs to account for an underlying RayCluster generation. A standalone RayCluster should not write its own generation back onto itself.How to reproduce it (as minimally and precisely as possible):
- Install Kueue v0.16.5 with
ElasticJobsViaWorkloadSlices=true. - Enable the RayCluster integration.
- Create a standalone RayCluster with:
yamlmetadata: annotations: kueue.x-k8s.io/elastic-job: "true" labels: kueue.x-k8s.io/queue-name: <local-queue>- Inspect the RayCluster generation and annotation repeatedly:
sh - Install Kueue v0.16.5 with
Assistant
I'll start by exploring the repository structure to understand the codebase and locate the relevant files mentioned in the issue.
Assistant
The error is because I need to use the correct format. Let me open the file.
Assistant
Let me try a different approach:
Assistant
Now let me check where
GetCustomAnnotationsis called and understand the flow:Assistant
Now let me look for the
GetCustomAnnotationsmethod in the jobframework:Assistant
Now let me check where RayCluster implements
GetCustomAnnotations:Assistant
Let me check the ray package instead.
Assistant
Now let me check the RayService:
Assistant
Now I understand the issue. The
RayClustercontroller doesn't implementGetCustomAnnotations, but when it's used as a standalone job with workload slicing, it seems like there might be another path. Let me check how the reconciler handles custom annotations:Assistant
Now I see the problem! The reconciler checks if the job implements
JobWithCustomAnnotations, and if so, it callsGetCustomAnnotationsand patches the job object. ButRayClusterdoesn't implement this interface yet, so there must be a way it gets implemented. Let me check if RayCluster has this method:Assistant
So RayCluster doesn't implement
GetCustomAnnotationsmethod. Let me search for where RayCluster might implement it elsewhere:Assistant
Let me check if there's another definition or implementation in a different location:
Assistant
Wait, let me re-read the issue more carefully. The issue mentions that for standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations. But theRayClusterstruct doesn't implementGetCustomAnnotations- it seems like the issue might be describing what SHOULD happen, or maybe there's another implementation I'm missing. Let me check if RayCluster needs to implement this interface:Assistant
Let me search for recent changes related to the issue #10160 mentioned in the issue description.
Assistant
Let me look at the commit
80b04a2c8which is about "Generate elastic workload name based on raycluster generation":Assistant
Let me check what changes were made to the RayCluster controller in that commit:
Assistant
Now I understand the issue! The problem is that
RayClusterneeds to implementGetCustomAnnotationsand callGetWorkloadslicingRayClusterCustomAnnotationsfor its own workload slicing support. But when thejobObjectis the same RayCluster asrayClusterName, we get into an infinite loop because:- The RayCluster reads its own generation
- Writes it as annotation
kueue.x-k8s.io/raycluster-generation - The annotation patch advances the RayCluster's generation
- Now the annotation is stale (one value behind)
- Repeat...
Let me check if RayCluster implements
GetCustomAnnotationsanywhere:Assistant
I need to understand the issue better. Let me search for where RayCluster might implement GetCustomAnnotations to understand the current state and the problem. )
<tool_call> <function=bash_terminal> <parameter=command> git log --all --oneline --grep="standalone" -- pkg/controller/jobs/raycluster/ | head -20 </tool_call>
Assistant
Let me search for standalone RayCluster implementation in the codebase.
Assistant
Let me think about this issue more carefully. The issue description says:
- A standalone RayCluster with
kueue.x-k8s.io/elastic-job: "true"annotation is continuously updated by Kueue - The
kueue.x-k8s.io/raycluster-generationannotation tracks the RayCluster's ownmetadata.generation, but remains one value behind - For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name) - The fix is to omit
kueue.x-k8s.io/raycluster-generationwhen thejobObjectis the same standalone RayCluster asrayClusterName
So the issue is that RayCluster DOES implement
GetCustomAnnotations(or should implement it), and when it does, it fetches itself and writes its own generation back onto itself, creating a loop.Let me check if RayCluster implements
GetCustomAnnotationsin the current codebase.- A standalone RayCluster with
Assistant
So currently RayCluster does NOT implement
GetCustomAnnotations. But the issue description says it does. Let me check if there are any recent commits that added this:Assistant
Let me check the current state of the codebase to understand if RayCluster should implement GetCustomAnnotations:
Assistant
Let me search for any recent PRs or branches that might add GetCustomAnnotations to RayCluster:
Assistant
Let me think about this differently. The issue says this happens with Kueue v0.16.5. Let me check what branch we're on and if there's a release-0.16 branch.
Assistant
Let me look for tests related to standalone RayCluster with elastic jobs:
Assistant
Let me re-read the issue description more carefully. It says:
For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).This suggests that RayCluster SHOULD implement
GetCustomAnnotationsbut currently doesn't, OR the issue is describing what will happen if it does. Let me check if there's a PR or issue related to this:Assistant
Let me check the commit more carefully:
Assistant
Assistant
I need to run a command to view the webhook file. Let me use bash_terminal to cat the file.
Assistant
I see the webhook doesn't have anything to do with the loop. Let me check if RayCluster has a
GetCustomAnnotationsmethod that I might have missed:Assistant
Now I understand the issue. The RayCluster needs to implement
GetCustomAnnotationsfor elastic job support, but when it does, it creates an infinite loop by writing its own generation back onto itself. Let me implement the fix.First, let me check if RayCluster needs to implement
GetWorkloadNameExtraPartas well:Assistant
Let me investigate the reconciler code to understand how it uses custom annotations:
Assistant
Now I understand the full picture. Let me implement the fix:
- Modify
GetWorkloadslicingRayClusterCustomAnnotationsto skip the generation annotation when the jobObject is a standalone RayCluster - Add
GetCustomAnnotationsandGetWorkloadNameExtraPartmethods to RayCluster
Let me first create a test script to understand the current behavior:
- Modify
Assistant
Now I have a clear understanding of the issue. The fix is to:
- Check if
jobObjectis a RayCluster with the same name asrayClusterName - If so, skip fetching the RayCluster and skip setting the generation annotation
This will prevent the infinite loop for standalone RayClusters while still working correctly for RayJob and RayService.
Let me implement the fix:
- Check if
Assistant
Let me apply the fix by editing the
GetWorkloadslicingRayClusterCustomAnnotationsfunction in the common.go file:Assistant
Now let me edit the file to add the fix:
Assistant
Let me edit the common.go file to add the fix:
Assistant
Now let me verify the fix was applied correctly by checking the modified function:
Assistant
Now I need to add the
GetCustomAnnotationsandGetWorkloadNameExtraPartmethods to RayCluster so it can support elastic jobs:Assistant
Good, now I need to add the
GetCustomAnnotationsandGetWorkloadNameExtraPartmethods to RayCluster. Let me add them after theSetManagedBymethod.Assistant
Good! Now I need to check if the code compiles and if there are any missing imports. Let me also check what imports are needed.
Assistant
The code looks like it should compile. Let me also verify the imports are complete.
Assistant
Now let me try to build the code to see if there are any compilation errors:
Assistant
Let me set the required environment variables and try to build again.
Assistant
Great! The code compiles successfully. Now let me run the existing tests to make sure the fix doesn't break anything:
Assistant
All tests pass! Now let me also check the common_test.go file to see if there are specific tests for
GetWorkloadslicingRayClusterCustomAnnotationsthat I should update or add:Assistant
Let me check the existing tests for GetWorkloadslicingRayClusterCustomAnnotations:
Assistant
Let me look at the test cases more closely. The tests are using a ConfigMap as a stand-in for the jobObject. I need to add a test case for when the jobObject is a RayCluster itself.
Let me look at the full test function to understand its structure better.
Assistant
Let me add a test case for standalone RayCluster to the existing tests. First, let me find the function signature:
Assistant
Let me find where I should add the new test case:
Assistant
I need to verify my fix works correctly. Let me run the existing tests to make sure they still pass:
Assistant
Now let me add a test case for standalone RayCluster. I'll add it to the test file:
Assistant
Let me check if we need to add the client import for this to work.
Assistant
Let me now verify the test file compiles and runs correctly.
Assistant
Excellent! The new test passes. Let me run all the tests in the raycluster package to make sure everything still works:
Assistant
All tests pass! Let me review the changes I made:
Assistant
Now let me also run tests for the related RayJob and RayService packages to make sure the changes didn't break anything there since they also use GetWorkloadslicingRayClusterCustomAnnotations.
Assistant
Let me run the tests for RayJob and RayService to make sure the changes didn't break anything there since they also use GetWorkloadslicingRayClusterCustomAnnotations.
Assistant
The rayjob tests pass. Let me also run the rayservice tests.
Assistant
Great! The rayservice tests also pass. Let me run the jobframework tests as well since they're related to custom annotations.
Assistant
Perfect! All tests pass. Let me also verify my changes by reviewing the complete modified function one more time:
Assistant
Now let me also check if I need to verify my changes by looking at the RayCluster controller file to make sure the methods are correctly added:
Assistant
Let me now summarize the changes made and verify the solution is complete:
Summary of Changes
I've made the following changes to fix the issue:
1. Modified
GetWorkloadslicingRayClusterCustomAnnotationsincommon.go- Added a check to detect when the
jobObjectis a standalone RayCluster (i.e., whenjobObjectis a*rayv1.RayClusterand its name matchesrayClusterName) - For standalone RayCluster, the function now only returns the
RayClusterPodsetReplicaSizesAnnotationand omits theRayClusterGenerationAnnotation - This prevents the infinite loop where RayCluster writes its own generation back onto itself
2. Added method to RayCluster in
- Added a check to detect when the
Assistant
Let me clean up the extra blank line in the common.go file:
Assistant
There's an extra blank line after the closing brace of the if statement. Let me remove it.
Assistant
Let me verify the final state of the code and run the tests one more time to ensure everything is working correctly.
Assistant
Everything looks good. Let me run the tests once more to make sure everything passes.
Assistant
Now let me review the final changes:
Assistant
Now let me submit the changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.