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:metadata.generation: 273390 kueue.x-k8s.io/raycluster-generation: "273389"A later read showed the same pattern:
metadata.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:
metadata: annotations: kueue.x-k8s.io/elastic-job: "true" labels: kueue.x-k8s.io/queue-name: <local-queue>- Inspect the RayCluster generation and annotation repeatedly:
kubectl get raycluster.ray.io <name> -n <namespace> \ -o jsonpath='{.metadata.generation}{"\t"}{.metadata.annotations.kueue\.x-k8s\.io/raycluster-generation}{"\n"}'Anything else we need to know?:
This may be related to #10160, which added generation-based elastic workload names on the release-0.16 branch.
A fix is to omit
kueue.x-k8s.io/raycluster-generationwhen the is the same standalone RayCluster as . - 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
Let me explore the raycluster controller to understand how this function is called:
Assistant
Now let me check the
GetCustomAnnotationsmethod which is mentioned in the issue:Assistant
Let me check the interface file to understand how
GetCustomAnnotationsshould be implemented:Assistant
Now I need to check if RayCluster implements
JobWithCustomAnnotations:Assistant
Let me search in the reconciler to see how
GetCustomAnnotationsis called:Assistant
Let me check if RayCluster implements the
GetCustomAnnotationsinterface:Assistant
Let me check how RayJob and RayService implement GetCustomAnnotations to understand the pattern.
Assistant
Now let me check if RayCluster has a
GetCustomAnnotationsmethod:Assistant
So RayCluster doesn't have a
GetCustomAnnotationsmethod! Let me search where it might be defined:Assistant
Let me look at all the files in the raycluster directory:
Assistant
Now I understand the issue. Let me trace through the problem:
- RayJob and RayService implement
GetCustomAnnotationswhich callsGetWorkloadslicingRayClusterCustomAnnotations - That function fetches a RayCluster by
rayClusterNameand sets theraycluster-generationannotation - The issue states that for standalone RayCluster,
GetCustomAnnotationsalso calls this helper with the RayCluster's own name - This causes a self-triggered loop because:
- The RayCluster fetches its own generation
- Writes it back as an annotation
- This advances the RayCluster's metadata.generation
- The annotation is now stale
- Repeat
Let me check if RayCluster implements
JobWithCustomAnnotationsby looking for all interfaces it implements:- RayJob and RayService implement
Assistant
I need to check if there's a GetCustomAnnotations method on RayCluster anywhere else:
Assistant
Now let me check what happens when a standalone RayCluster is used. The issue mentions that "For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations". Let me search for where that might happen:Assistant
Let me check if RayCluster implements
ElasticWorkloadNameProvider:Assistant
Let me check the reconciler code more carefully to see how the custom annotations are applied and when the RayCluster would trigger the loop:
Assistant
Now I understand the flow. The reconciler checks if a job implements
JobWithCustomAnnotations. If it does, it callsGetCustomAnnotations. The issue is that standalone RayCluster must be implementing this interface somehow. Let me search for any embedded interface implementations:Assistant
Let me check the issue description again and understand better. The issue mentions that "For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)". Let me search for where this pattern occurs:Assistant
Let me look for where RayCluster might implement GetCustomAnnotations. The issue says it's calling GetWorkloadslicingRayClusterCustomAnnotations, so maybe there's another file:
Assistant
Now let me check if there's another adapter or if RayCluster has a GetCustomAnnotations somewhere I haven't found yet. Let me search more broadly:
Assistant
Let me look at all files in the raycluster directory that might contain the GetCustomAnnotations method:
Assistant
I see that RayCluster does NOT implement
JobWithCustomAnnotationsaccording to the current code. But wait, let me check if there's a newer version or if this was recently added:Assistant
Let me search the git history for when GetCustomAnnotations might have been added to RayCluster:
Assistant
Let me continue to see if RayCluster implements GetCustomAnnotations in that commit or later:
Assistant
Let me search for any recent changes that might have added GetCustomAnnotations to RayCluster:
Assistant
Let me now look at the most recent commit that might have added RayCluster's GetCustomAnnotations:
Assistant
The commands are still executing and I need to wait for them to complete. Let me continue with the analysis. )
<tool_call> <function=bash_terminal> <parameter=command> cd /kueue && git show 9131f6b66 --name-only | grep raycluster </tool_call>
Assistant
Let me search more specifically for where RayCluster might implement GetCustomAnnotations.
Assistant
The last commit that touched raycluster files was 9131f6b66 which only touched the webhook file. Let me search more specifically for where RayCluster might implement GetCustomAnnotations. Let me look at the current state of the code more carefully.
Assistant
The issue description says that for standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations. But when I search forGetCustomAnnotationsin the raycluster directory, I don't find any implementation. This is confusing.Let me re-read the issue description more carefully. The issue says: "For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)."But there's no GetCustomAnnotations method on RayCluster currently. So either:
- The issue is describing what SHOULD happen (i.e., it's a bug report for code that needs to be fixed)
- There's a GetCustomAnnotations method I haven't found yet
Let me check if there's a separate file or adapter for RayCluster that implements this.
Assistant
Let me reconsider the issue. The issue says "For standalone RayClusters, GetCustomAnnotations calls GetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)."
But I can't find any implementation of GetCustomAnnotations for RayCluster. Maybe the issue is describing what's happening indirectly - perhaps through some other mechanism. Let me look at the issue again.
Wait, I think I understand now. The issue is that RayCluster needs to implement GetCustomAnnotations to track the raycluster-generation annotation, but when it does, it creates a loop because it's writing its own generation back to itself.
Let me search for recent commits that might have added this or look at what the issue is actually asking for. The issue says "A fix is to omit kueue.x-k8s.io/raycluster-generation when the jobObject is the same standalone RayCluster as rayClusterName."
So the fix should be in GetWorkloadslicingRayClusterCustomAnnotations - it should check if the jobObject is the same as the RayCluster being fetched, and if so, omit the raycluster-generation annotation.
But wait, for this to be a problem, RayCluster would need to implement GetCustomAnnotations. Let me check if there's a recent change that added this.
Assistant
I need to understand the issue better. The issue says that standalone RayClusters are continuously updated by Kueue, creating a self-triggered loop. The problem is:
- The
kueue.x-k8s.io/raycluster-generationannotation tracks the RayCluster's ownmetadata.generation - For standalone RayClusters, when GetCustomAnnotations is called, it fetches the RayCluster and returns its generation as an annotation to write back
- This advances the RayCluster generation, making the annotation stale again
- This creates a loop
But I can't find where RayCluster implements GetCustomAnnotations. Let me check if maybe the issue is that RayCluster SHOULD implement GetCustomAnnotations (and ElasticWorkloadNameProvider) for workload slicing, but the current implementation would cause this loop.
- The
Assistant
Let me continue investigating. I found that
GetWorkloadNameExtraPartexists in common.go but I need to check if RayCluster implements the ElasticWorkloadNameProvider interface.Assistant
<tool_call> <function=bash_terminal> <parameter=command> cd /kueue && git log --all --oneline --grep="standalone" | head -10 </tool_call>
Assistant
Let me search for where GetCustomAnnotations might be implemented for RayCluster or if it's missing.
Assistant
Let me search for where RayCluster implements or should implement GetCustomAnnotations:
Assistant
Let me check the most recent commit that added the GetCustomAnnotations method to see what the issue is describing. The issue mentions that for standalone RayClusters, GetCustomAnnotations is being called. Let me search for when this was added.
Assistant
It seems like GetCustomAnnotations was never added to the RayCluster controller. But the issue says it's being called. Let me re-read the issue more carefully.
The issue says: "For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)."I think this is describing what SHOULD happen, or maybe it's already implemented but I need to find it. Let me search the entire codebase for where RayCluster might implement JobWithCustomAnnotations.
Assistant
Let me search more carefully for GetCustomAnnotations implementation in RayCluster:
Assistant
Let me look for the issue more carefully. The issue describes a problem where a standalone RayCluster is continuously updated. Let me check if RayCluster implements GetCustomAnnotations by looking at the raycluster_controller.go file more carefully:
Assistant
The RayCluster type currently only implements GenericJob and JobWithManagedBy interfaces. It does NOT implement JobWithCustomAnnotations.
But the issue says "For standalone RayClusters, GetCustomAnnotations calls GetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)."
I think the issue is describing what WILL happen when someone adds GetCustomAnnotations to RayCluster, or there's code I haven't found yet.
Let me think about this differently. The issue says:
- Kueue is continuously patching a standalone elastic RayCluster
- The raycluster-generation annotation is one value behind metadata.generation
- The fix is to "omit kueue.x-k8s.io/raycluster-generation when the jobObject is the same standalone RayCluster as rayClusterName"
So the issue is that when RayCluster implements GetCustomAnnotations (for elastic workloads), it would call GetWorkloadslicingRayClusterCustomAnnotations which fetches the RayCluster and returns its generation. But since the RayCluster is fetching itself, this creates a loop.
I need to:
- Check if RayCluster implements GetCustomAnnotations (or if it should)
- If it does, add the fix to omit the raycluster-generation annotation when jobObject is the same as the RayCluster
Assistant
Let me check what version this repository is at:
Assistant
The repository is at commit 4cc62da8e. The issue mentions Kueue v0.16.5, but this seems to be a development version. Let me check if RayCluster needs to implement GetCustomAnnotations for the elastic workload feature to work properly.
Looking back at the issue description, it says: "For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)."This suggests that RayCluster SHOULD implement GetCustomAnnotations but currently doesn't. The issue is asking us to either:
- Add GetCustomAnnotations to RayCluster but with the fix to avoid the self-update loop
- Or fix the GetWorkloadslicingRayClusterCustomAnnotations function to handle the case when jobObject is the same as the RayCluster
The fix suggestion says: "A fix is to omit kueue.x-k8s.io/raycluster-generation when the jobObject is the same standalone RayCluster as rayClusterName."
This means I need to:
- Add GetCustomAnnotations to RayCluster (so it can participate in elastic workloads)
- Fix GetWorkloadslicingRayClusterCustomAnnotations to check if jobObject is the same as the RayCluster being fetched, and if so, omit the raycluster-generation annotation
Assistant
Let me check if there are any branches related to the issue:
Assistant
Let me think about this differently. Based on the issue description:
- The issue happens when a standalone RayCluster has the elastic-job annotation
- The problem is that Kueue is continuously updating the raycluster-generation annotation
- This creates a self-triggered loop
The issue says "For standalone RayClusters, GetCustomAnnotations calls GetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)."
I think I misunderstood - maybe RayCluster DOES implement GetCustomAnnotations but I need to search more carefully. Let me check all methods on RayCluster:
Assistant
I still don't see GetCustomAnnotations in the RayCluster controller. Let me check if it might be in a separate file or if I need to add it.
Wait, let me re-read the issue more carefully. The issue says:
"For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)."I think this is saying that the problem EXISTS because GetCustomAnnotations IS being called. But I can't find where RayCluster implements GetCustomAnnotations.
Let me check if maybe the issue is that someone needs to ADD GetCustomAnnotations to RayCluster for elastic workloads to work, but the current helper function would cause a loop.
Actually, looking at the issue title again: "Standalone elastic RayCluster self-updates raycluster-generation annotation"
The key word is "elastic" - this suggests the RayCluster has the elastic-job annotation. And the issue is that Kueue is continuously updating it.
Maybe RayCluster DOES implement GetCustomAnnotations but I'm missing it. Let me check all .go files in the raycluster directory.
Assistant
OK, so RayCluster definitely does NOT implement GetCustomAnnotations currently. But the issue says it's being called and causing a loop.
Wait, let me re-read the issue one more time. The issue says:
"A later read showed the same pattern:
metadata.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."
So the annotation IS being written somehow. And the issue says:
"This is a self-triggered loop in the RayCluster custom annotation path. For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)."Maybe the issue is that RayCluster SHOULD implement GetCustomAnnotations to support elastic workloads properly, but the current code in GetWorkloadslicingRayClusterCustomAnnotations would cause a loop if it did.
Let me check what the ElasticWorkloadNameProvider interface does - this might be the key.
Assistant
I think I'm overcomplicating this. Let me step back and think about what the issue is actually saying.
The issue describes a problem where a standalone RayCluster is being continuously updated. The raycluster-generation annotation is always one value behind the actual generation. This creates a loop.
The issue says: "For standalone RayClusters,
GetCustomAnnotationscalls ."Assistant
Let me look for tests related to RayCluster and GetCustomAnnotations to understand the expected behavior:
Assistant
Now I understand the issue better. The issue is describing what WILL happen when RayCluster implements GetCustomAnnotations for elastic workloads. The current code doesn't have GetCustomAnnotations on RayCluster, but it SHOULD for elastic workloads to work properly.
Let me implement the fix:
- Add GetCustomAnnotations method to RayCluster
- Add ElasticWorkloadNameProvider interface implementation to RayCluster
- Fix GetWorkloadslicingRayClusterCustomAnnotations to omit raycluster-generation when jobObject is the same RayCluster
Assistant
Now I understand the issue clearly. The
GetWorkloadslicingRayClusterCustomAnnotationsfunction always sets theRayClusterGenerationAnnotation, even when thejobObjectis the same RayCluster that's being fetched. This creates a loop where:- RayCluster's GetCustomAnnotations is called
- It fetches itself and gets its generation
- It returns the generation as an annotation
- The annotation is written to the RayCluster
- This advances the RayCluster's metadata.generation
- The annotation is now stale (one behind)
- Repeat
The fix is to check if
jobObjectis the same RayCluster (by comparing the name and namespace) and if so, omit theRayClusterGenerationAnnotation.Let me implement the fix:
Assistant
Looking at the issue more carefully, I need to:
- Fix
GetWorkloadslicingRayClusterCustomAnnotationsto omit theraycluster-generationannotation when thejobObjectis the same RayCluster as the one being fetched - Add
GetCustomAnnotationsmethod to RayCluster so it can participate in elastic workloads - Add
ElasticWorkloadNameProviderinterface implementation to RayCluster
Let me start by implementing the fix:
- Fix
Assistant
Let me check if there's a version tag for v0.16.5 and understand the current state better:
Assistant
Let me check the git tags to understand the version state better.
Assistant
The previous command returned exit code 0 but no output. This means there are no tags matching "v0.16" in the repository. Let me check what tags exist and understand the repository state better.
Assistant
Let me search more carefully to understand if RayCluster already implements GetCustomAnnotations somewhere I haven't found:
Assistant
Let me look for how RayJob and RayService implement these interfaces to understand the pattern better:
Assistant
Now I understand the pattern. RayJob implements both
JobWithCustomAnnotationsandElasticWorkloadNameProviderinterfaces. I need to:- Add these interfaces to RayCluster
- Fix
GetWorkloadslicingRayClusterCustomAnnotationsto avoid the self-update loop when the jobObject is the same RayCluster
Let me implement the fix step by step:
Assistant
Now I understand the problem completely. Let me implement the fix. I need to:
- Fix
GetWorkloadslicingRayClusterCustomAnnotationsincommon.goto omit theraycluster-generationannotation when thejobObjectis the same RayCluster - Add
GetCustomAnnotationsmethod to RayCluster inraycluster_controller.go - Add
GetWorkloadNameExtraPartmethod to RayCluster inraycluster_controller.go - Add interface assertions for
JobWithCustomAnnotationsandElasticWorkloadNameProvider
Let me start by fixing the
GetWorkloadslicingRayClusterCustomAnnotationsfunction:- Fix
Assistant
Now let me create the fix. I'll edit the
GetWorkloadslicingRayClusterCustomAnnotationsfunction incommon.goto check if thejobObjectis the same RayCluster and omit the generation annotation in that case:Assistant
The patch is getting complex. Let me directly edit the file instead:
Assistant
Now I need to add
GetCustomAnnotationsandGetWorkloadNameExtraPartmethods to RayCluster, and add the interface assertions. Let me update the raycluster_controller.go file:Assistant
Now let me verify the changes to raycluster_controller.go and make sure the implementation is correct.
Assistant
I need to run the tests for the common.go file to make sure my changes didn't break anything. Let me run the specific test for GetWorkloadslicingRayClusterCustomAnnotations.
Assistant
Let me continue verifying the fix by checking if the tests pass and examining the test cases to make sure my changes are correct.
Assistant
The tests pass. Now I should write a test to verify that my fix works correctly - specifically that when the jobObject is the same RayCluster, the raycluster-generation annotation is NOT included.
Let me look at the existing tests to understand the pattern, then I'll add a test case for standalone RayCluster.
Actually wait, I need to think about this more carefully. The tests are passing because the existing tests are for RayJob, not for standalone RayCluster. I need to check if there's a test case that tests the scenario where the jobObject IS a RayCluster.
Let me look at the test cases to see what they're testing.
Assistant
I need to continue verifying my fix. Let me look at the existing test structure and then run all related tests to make sure everything passes. I should also add a test case for standalone RayCluster to ensure the fix works correctly.
Assistant
Let me analyze what I need to do:
- I've already made changes to
common.goto fix theGetWorkloadslicingRayClusterCustomAnnotationsfunction - I've added
GetCustomAnnotationsandGetWorkloadNameExtraPartmethods to RayCluster - The existing tests pass
Now I need to:
- Add a test case for standalone RayCluster to verify the fix works
- Run all tests to make sure nothing is broken
Let me add a test case for standalone RayCluster scenario.
- I've already made changes to
Assistant
Now I understand the test structure. The existing tests use a ConfigMap as a generic object, but to test the standalone RayCluster case, I need to pass a RayCluster object with the same name as rayClusterName. Let me add a test case for this scenario.
Assistant
Let me check how MakeCluster works to fix the test.
Assistant
I see there's a
SetAnnotationmethod. Let me update the test to use the correct API:Assistant
I need to run the tests again to verify the fix works correctly. Let me run the test to see if it passes now.
Assistant
The test is failing because my fix isn't working as expected. The test shows that the RayCluster generation annotation is still being set to "0" instead of being empty.
Let me look at my fix more carefully. The issue is that the
isStandaloneRayClustercheck is usingjobObject.GetObjectKind().GroupVersionKind().Kind == "RayCluster", but this might not work correctly for wrapped objects or objects that haven't been properly registered.Let me check how the GVK is determined for the RayCluster object in the test.
Assistant
The issue is that
GetObjectKind().GroupVersionKind().Kindreturns an empty string for objects that haven't had their GVK set. Let me use a different approach - I can compare the object's type using reflection or use the GVK directly.Actually, a simpler approach would be to check if the jobObject is a RayCluster by checking if it can be cast to *rayv1.RayCluster.
Assistant
The test is still failing because the GVK check isn't working. Let me debug by printing what the GVK actually is in the test. The issue is that
GetObjectKind().GroupVersionKind()might return an empty GVK for the RayCluster object in the test.Let me try a different approach - instead of checking the Kind, I should check if the jobObject is actually a *rayv1.RayCluster type using type assertion.
Assistant
All tests pass now. Let me run all the raycluster tests to make sure everything works correctly:
Assistant
I need to verify that my changes don't break RayJob and RayService functionality, since they also use
GetWorkloadslicingRayClusterCustomAnnotations.Assistant
The user is asking me to run the rayjob tests again and check the GetCustomAnnotations test specifically. Let me do that.
Assistant
The user wants me to check if the RayJob tests still pass. Looking at the output, all RayJob tests pass, including the GetCustomAnnotations tests. This confirms that my fix doesn't break RayJob functionality because RayJob is not a RayCluster (it's a different type), so the type assertion
jobObject.(*rayv1.RayCluster)will return false for RayJob, and the RayCluster generation annotation will still be set for RayJob.Let me also run the RayService tests to make sure they pass too.
Assistant
Excellent! All tests pass. Let me now summarize the changes I made and verify the final state of the fix.
Assistant
Let me verify the final state of my changes and make sure all tests pass before submitting.
Assistant
The user is reminding me that I need to use tool calls. Let me verify the tests pass and then submit my changes. I've made the following changes:
-
Modified
GetWorkloadslicingRayClusterCustomAnnotationsincommon.goto check if the jobObject is a standalone RayCluster (same type and name), and if so, skip setting the raycluster-generation annotation. -
Added
GetCustomAnnotationsandGetWorkloadNameExtraPartmethods to RayCluster inraycluster_controller.goto implement theJobWithCustomAnnotationsandElasticWorkloadNameProviderinterfaces. -
Added a test case in
common_test.goto verify the standalone RayCluster scenario.
Let me run all the tests one more time to make sure everything passes, then submit.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.