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. Let's first get an overview.
- Assistant
Let me explore more about the raycluster integration code.
- Assistant
Let me first understand the repository structure and the relevant files for this issue.
- Assistant
Let me examine the raycluster controller and the relevant code that handles custom annotations.
- Assistant
Now I need to look at the raycluster controller to understand where
GetCustomAnnotationsis called and how it's used. Let me check the controller file. - Assistant
Now let me search for where
GetCustomAnnotationsis defined and called. - Assistant
Let me check if RayCluster has a GetCustomAnnotations method.
- Assistant
So RayCluster itself doesn't have
GetCustomAnnotations. Let me look at RayJob and RayService to understand the pattern. - Assistant
Now let's look at how the RayService handles this.
- Assistant
Now let me check if the standalone RayCluster has a
GetCustomAnnotationsmethod somewhere else. - Assistant
So RayCluster doesn't implement
GetCustomAnnotations. Let me check the RayCluster webhook and also search for whereGetWorkloadslicingRayClusterCustomAnnotationsis called for standalone RayClusters. - Assistant
Let me check the reconciler to understand how
GetCustomAnnotationsis used. - Assistant
So the issue is that when workload slicing is enabled, the reconciler calls
GetCustomAnnotationson the job. For a standalone RayCluster, this would need to be implemented. Let me check if there's an interface assertion forJobWithCustomAnnotationson the RayCluster type. - Assistant
So the RayCluster type doesn't implement . But according to the issue description, the standalone RayCluster IS being updated by Kueue's controller. Let me re-read the issue more carefully.
- Assistant
Let me understand the flow. Let me check if there's a
GetCustomAnnotationsmethod on the RayCluster wrapper. - Assistant
Let me look at the interface and the reconciler more carefully.
- Assistant
Now let me understand the issue better. Let me search for where standalone RayCluster implements
GetCustomAnnotations. - Assistant
So the RayCluster doesn't implement
GetCustomAnnotations. Let me check if there's a different mechanism causing the issue. Let me look at the reconciler to understand the flow better. - Assistant
Let me search more broadly for any method on RayCluster that might implement
GetCustomAnnotations. - Assistant
Let me check if there's another file in the raycluster package that I might have missed.
- Assistant
I notice the RayCluster type does NOT have a
GetCustomAnnotationsmethod. Let me check the git history for recent changes to see if this was added. - Assistant
Let me look at how the
GetCustomAnnotationspath works for standalone RayClusters. Let me first check if there's something that handles this case. - Assistant
Let me look at the reconciler code more carefully to understand the flow for standalone RayClusters.
- Assistant
Now I need to understand the issue better. Let me search for whether RayCluster implements
GetCustomAnnotationssomewhere else. - Assistant
Let me check if the RayCluster implements this interface elsewhere. Maybe I need to look at the rayjob controller since it references
rayclusterpackage. - Assistant
I need to understand the full picture. Let me check if there's a
GetCustomAnnotationsimplementation for RayCluster in any other files. - Assistant
Now I need to understand how a standalone RayCluster gets the
GetCustomAnnotationscall. Let me check theElasticWorkloadNameProviderinterface too. - Assistant
Let me look at how the elastic workload name is constructed, which is key to understanding the issue.
- Assistant
Let me understand the flow better. Let me check if there's something in the reconciler that calls
GetCustomAnnotationsfor RayCluster. - Assistant
Let me look more closely at the issue. The standalone RayCluster doesn't implement
GetCustomAnnotations, but the issue says the annotation is being set. Let me search for how the annotation could be set. - Assistant
I need to understand the issue better. Let me look at the
GetWorkloadslicingRayClusterCustomAnnotationsfunction more carefully. - Assistant
Let me look at the test files to understand what's expected.
- Assistant
Let me look at the RayCluster webhook to understand how annotations are set.
- Assistant
Now I understand the issue. Let me look at the
GetWorkloadslicingRayClusterCustomAnnotationsfunction more carefully and understand the flow. The issue is that when a standalone RayCluster callsGetCustomAnnotations, it passes itself as bothjobObjectandrayClusterName. This creates a self-update loop because:- Function fetches the RayCluster to get its generation
- Writes the generation as an annotation back onto the same RayCluster
- This metadata update increments the generation
- The annotation is now stale, triggering another update
The fix should be to omit
raycluster-generationwhen thejobObjectis the same standalone RayCluster as therayClusterName. Let me first check if the RayCluster type actually implementsGetCustomAnnotations. - Assistant
Let me check if there's been a recent change that added
GetCustomAnnotationsto the RayCluster type. Let me look at the common_test.go to understand the expected behavior. - Assistant
Let me look at the issue more carefully. The issue says that for standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name). But the RayCluster type doesn't implementGetCustomAnnotations. Let me check if there's some other way this could happen. Let me look at the reconciler code more carefully. - Assistant
Now I need to understand the full picture. The RayCluster type doesn't implement
GetCustomAnnotations. Let me check if the issue is about a scenario where RayCluster should implement it but there's a bug. Let me look at the issue from a different angle - maybe theGetWorkloadslicingRayClusterCustomAnnotationsfunction is being called from somewhere else. - Assistant
I see - the
GetWorkloadslicingRayClusterCustomAnnotationsis only called from RayJob and RayService. Let me check if there's a branch that has the fix we need to implement. - Assistant
Let me check all methods on the RayCluster type to see if
GetCustomAnnotationsmight be defined somewhere I haven't looked. - Assistant
Now I have a much better understanding of the issue. Let me look at how the
GetWorkloadslicingRayClusterCustomAnnotationsfunction works. The key issue is:-
For RayJob/RayService:
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Status.RayClusterName)wherej.Object()is the RayJob/RayService andrayClusterNameis the underlying RayCluster. This is correct - the annotation on the RayJob/RayService tracks the RayCluster's generation. -
For standalone RayClusters: if
GetCustomAnnotationswere implemented, it would callGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)where BOTHjobObjectandrayClusterNamerefer to the same RayCluster. This creates the self-update loop.
The fix should be in
GetWorkloadslicingRayClusterCustomAnnotations: whenjobObjectis a standalone RayCluster that is the same object asrayClusterName, we should omit theRayClusterGenerationAnnotation.Let me verify this understanding by looking at the interface comment.
-
- Assistant
Now I understand the issue clearly. The
GetWorkloadslicingRayClusterCustomAnnotationsfunction is designed for RayJob/RayService, wherejobObjectis the parent object andrayClusterNameis the child RayCluster. For standalone RayClusters, both refer to the same object, creating a self-update loop. The fix is to omitRayClusterGenerationAnnotationwhenjobObjectis the same RayCluster asrayClusterName.Let me implement the fix:
- Assistant
Now I understand the issue clearly. Let me implement the fix. The
GetWorkloadslicingRayClusterCustomAnnotationsfunction should check if thejobObjectis the same RayCluster as the one it's fetching (by comparingjobObjectname and namespace withrayClusterName). If they're the same (standalone RayCluster case), it should omit theRayClusterGenerationAnnotationto prevent the self-update loop. - Assistant
Now let me implement the fix. The key insight is that when
jobObjectis the same RayCluster asrayClusterName, we should omit theRayClusterGenerationAnnotation. The best way to detect this is to check ifjobObjectis a*rayv1.RayClusterand its name matchesrayClusterName. - Assistant
Now I'll implement the fix. The key is to detect when
jobObjectis the same RayCluster asrayClusterName(i.e., standalone RayCluster case) and omit theRayClusterGenerationAnnotationto prevent the self-update loop. - Assistant
Let me check what happened to the function.
- Assistant
It looks like the function was removed but not replaced properly. Let me restore the file and try again with proper syntax.
- Assistant
Good, the file is restored. Now let me use the proper heredoc syntax to edit the function.
- Assistant
Now let me edit the function using the heredoc syntax.
- Assistant
Good, the edit was applied. Let me verify the change looks correct and the file compiles.
- Assistant
Let me set up the go environment properly.
- Assistant
Good, the file compiles. Now let me run the existing tests to make sure I haven't broken anything.
- Assistant
Good, all existing tests pass. Let me continue to see the full test output.
- Assistant
All tests pass. Now let me also check if the RayJob and RayService tests still pass, since they call
GetWorkloadslicingRayClusterCustomAnnotationstoo. - Assistant
Good. Let me also check RayService tests.
- Assistant
All tests pass. Now let me verify the change by looking at the diff.
- Assistant
The diff looks good. Let me also check the test file to see if there's a test case for the standalone RayCluster scenario.
- Assistant
Let me look at the test cases to understand the existing test structure.
- Assistant
I see that the existing test uses a
corev1.ConfigMapas thejobObject, not a*rayv1.RayCluster. So my fix won't affect the existing tests because the type assertionjobObject.(*rayv1.RayCluster)will be false for the existing tests. This is correct - the fix only applies to standalone RayClusters.Let me also verify that the existing test still passes after my change, and let me look at the test file to see if there's a test case for the standalone RayCluster scenario.
- Assistant
All tests pass. Let me also check if there are tests for
GetCustomAnnotationsin the RayJob tests. - Assistant
All tests pass. Let me now write a quick script to verify the fix works correctly for the standalone RayCluster case.
- Assistant
The test script needs a
testing.T- let me just verify the fix is correct with the existing tests. Let me run all the relevant tests once more. - Assistant
All tests pass. Let me also clean up the temporary test script.
- Assistant
Let me also run the broader jobframework tests since the common code is used by the reconciler.
- Assistant
All tests pass. Let me verify the final state of my change once more.
- Assistant
Let me look at the final diff one more time to make sure everything is correct.
- Assistant
Let me also verify that the type assertion works correctly for the wrapper type.
- Assistant
The
Object()method returns(*rayv1.RayCluster)(j), which is a*rayv1.RayCluster. So the type assertionjobObject.(*rayv1.RayCluster)will work correctly for standalone RayClusters.Now let me run a broader set of tests to make sure nothing else is broken.
- Assistant
Let me also run the reconciler tests to make sure nothing is broken.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.