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 me first get an overview.
- Assistant
Let me get more files related to RayCluster and also check the current directory structure.
- Assistant
Let me focus on the raycluster controller and webhook files. Let me also search for the specific functions mentioned in the issue.
- Assistant
Let me look at the key files. First, let me check the issue mentioned about
GetWorkloadslicingRayClusterCustomAnnotationsandGetCustomAnnotations. - Assistant
Now let me look at the RayCluster controller to understand how
GetCustomAnnotationsis called: - Assistant
Let me look at how
GetCustomAnnotationsis used in the RayJob controller: - Assistant
Let me check the rayjob_controller.go for GetCustomAnnotations implementation.
- Assistant
Now let me check the RayCluster controller:
- Assistant
Let me look at the RayCluster controller to see if it has GetCustomAnnotations.
- Assistant
Let me check the full RayCluster controller file:
- Assistant
Now I need to understand the issue better. Let me look at how
GetCustomAnnotationsis used in the reconciler. The issue mentions that for a standalone RayCluster,GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations. Let me check the interface definition and see howGetCustomAnnotationsis implemented for RayCluster. - Assistant
Let me check if RayCluster implements GetCustomAnnotations through a default implementation or if it needs to be added:
- Assistant
Let me look at the full context around that line.
- Assistant
Now I need to check if RayCluster implements
GetCustomAnnotations. Let me search more carefully: - Assistant
So RayCluster doesn't implement
GetCustomAnnotations, but RayJob and RayService do. Let me check the RayService controller too. - Assistant
Let me check the rayservice implementation too.
- Assistant
Wait, the issue says
GetCustomAnnotationsIS called for standalone RayClusters. Let me look more carefully at the RayCluster type and see if there's something I'm missing. - Assistant
So
RayClusterdoesn't implementJobWithCustomAnnotationsbutRayJobandRayServicedo. Let me look more closely at the issue again.The issue says: "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."Let me check how
RayClusteris defined again. TheRayClustertype istype RayCluster rayv1.RayCluster. Let me see if there's any method that makes it implementJobWithCustomAnnotations.Actually, wait. Looking more carefully at the issue: "A standalone Kueue-managed elastic RayCluster". The RayCluster itself is a standalone job (not managed by RayJob/RayService). But the
RayClustertype doesn't implementJobWithCustomAnnotations. So where does the issue come from?Let me re-read the reconciler code. The check is
if jobWithCustomAnnotations, ok := job.(JobWithCustomAnnotations); ok. This is a type assertion. If doesn't implement this interface, then would be false and the code wouldn't run. - Assistant
OK, so the RayCluster doesn't implement
GetCustomAnnotations. But the issue says that standalone RayClusters are continuously updated. Let me look more carefully at the reconciler code.Let me check the
UpdatePodSetsfunction - it's called in the reconciler for RayClusters with in-tree autoscaling enabled. And it also fetches the RayCluster and reads replicas from it.But wait, the issue mentions the generation annotation. Let me trace the code flow again:
- Standalone RayCluster is reconciled
WorkloadSliceEnabledis true (becauseElasticJobsViaWorkloadSlices=trueand the annotation )
- Assistant
Wait, I need to look at this more carefully. Let me check where the
RayClusterGenerationAnnotationis actually used/written: - Assistant
Let me look at the interface more carefully to understand the issue.
- Assistant
Now I need to understand the issue better. Let me look at the
JobWithCustomAnnotationsinterface. The issue says that a standalone RayCluster is continuously updated by Kueue. Looking at the code,RayJobandRayServiceimplementJobWithCustomAnnotations, butRayClusterdoes not.Wait, let me re-read the issue:
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.So it seems like the issue is that
GetCustomAnnotationson a standalone RayCluster would fetch the RayCluster itself and set the generation annotation, which triggers an update. But wait,RayClusterdoesn't implementJobWithCustomAnnotations.Let me look at this more carefully. Let me check if there's a
GetCustomAnnotationsmethod onRayCluster: - Assistant
So RayCluster doesn't implement
GetCustomAnnotations. Let me look at the reconciler code to see how custom annotations are handled: - Assistant
OK so RayCluster doesn't implement
GetCustomAnnotations. But the issue says it's happening. Let me check what theGetWorkloadNameExtraPartmethod does and see if there's something in the workload slicing path that triggers the annotation update.Let me also look at the
workloadslicing.EnsureWorkloadSlicesfunction to understand the flow better. Maybe the issue is that the annotation is being set through a different path, perhaps in the workload slicing code itself. - Assistant
Let me look at the workloadslicing code to understand the flow better.
- Assistant
Let me understand the issue more thoroughly. Let me check for
ElasticWorkloadNameProviderand see if RayCluster implements it: - Assistant
Let me look at the webhook for RayCluster:
- Assistant
Let me check the git history for the file:
- Assistant
Let me look at the reconciler more carefully to understand the flow. Let me see if there's a
GetCustomAnnotationsfor RayCluster that may have been added recently. - Assistant
Let me understand the issue better. Let me search for how
GetCustomAnnotationsis implemented for RayCluster specifically: - Assistant
Wait, let me re-examine. The issue says "For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)." But I see that the RayCluster type does NOT have aGetCustomAnnotationsmethod. Let me check if maybe the issue is about the RayJob controller managing a standalone RayCluster? Let me look more carefully at theGetWorkloadslicingRayClusterCustomAnnotationsfunction.Actually wait - the issue says the annotation IS being set. So something must be calling it. Let me check if there's a missing
GetCustomAnnotationson the RayCluster that should exist but has the bug. - Assistant
Let me look at the test file for the RayCluster controller:
- Assistant
Let me check the test:
- Assistant
Wait, I need to re-examine the issue. Let me re-read the issue description:
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.This suggests that
RayClusteralready has aGetCustomAnnotationsmethod. But I didn't find it in the code. Maybe it was added in a commit that I'm looking at? Let me check if there's a recent commit that added this.Actually wait, let me re-check the RayCluster controller. Maybe the
GetCustomAnnotationsmethod is defined somewhere else that I missed.Let me search more carefully.
- Assistant
Let me check how the
GetWorkloadNameExtraPartis used in the reconciler: - Assistant
Let me look at the context around that line:
- Assistant
I notice that
RayClusterdoesn't implementGetCustomAnnotations. Let me look at the reconciler more carefully to understand the flow for standalone RayClusters: - Assistant
Let me look at the
WorkloadSliceEnabledfunction to understand what conditions trigger workload slicing. - Assistant
Let me check the git history for the raycluster controller to see recent changes:
- Assistant
Let me look at the commit that added generation-based elastic workload names:
- Assistant
Let me look at this commit in detail to understand the changes:
- Assistant
Let me look at the reconciler flow more carefully. Let me look at how reconcile calls the workload slicing path:
- Assistant
Let me trace through the code flow more carefully. The issue says the annotation is being set on standalone RayClusters. Let me check if there's any code path that could set this annotation on a standalone RayCluster. Let me look at how the reconciler handles updates:
- Assistant
Wait, let me re-examine. The issue says "For standalone RayClusters,
GetCustomAnnotationscalls...". But the current code doesn't haveGetCustomAnnotationson theRayClustertype. Let me search more broadly: - Assistant
Let me look at this from a different angle. The issue says that the RayCluster is being self-updated. Let me check if there's a place in the reconciler that modifies the RayCluster's annotations. Let me also check the
reconcilefunction flow more carefully. - Assistant
Let me look at the main reconcile function.
- Assistant
Let me now look at the reconcile function flow more carefully. Let me check if the RayCluster controller adds the generation annotation:
- Assistant
Let me search for where the RayCluster annotation might be set in the webhook:
- Assistant
Let me look more carefully at the issue. The issue says the RayCluster itself is being annotated with
raycluster-generation. Let me look at theGetWorkloadslicingRayClusterCustomAnnotationsfunction - the key issue is that for standalone RayClusters, the function sets theraycluster-generationannotation on the RayCluster itself, which causes the generation to increment. Let me check if there's a missingGetCustomAnnotationsfor RayCluster: - Assistant
Let me now look at how the RayCluster type implements the GenericJob interface. Maybe there's something I'm missing:
- Assistant
Let me check the test file for custom annotations:
- Assistant
Let me look more carefully at the flow. Let me check if the RayCluster type is expected to also implement
JobWithCustomAnnotations: - Assistant
Let me look at recent PRs related to the RayCluster:
- Assistant
Let me think about this differently. The issue says "standalone RayCluster self-updates raycluster-generation annotation". Let me look at the
GetWorkloadslicingRayClusterCustomAnnotationsfunction and understand what it does for the standalone case. Let me also check if there's aGetCustomAnnotationsimplementation on theRayClustertype that I might have missed. - Assistant
- Assistant
- Assistant
Now I understand the issue. Let me look at the
GetWorkloadslicingRayClusterCustomAnnotationsfunction to understand the fix needed: - Assistant
Now I have a clear understanding of the issue. Let me trace through the problem:
GetWorkloadslicingRayClusterCustomAnnotationsalways includesRayClusterGenerationAnnotationin its return value- For
RayJob/RayService, this annotation is set on the RayJob/RayService (different object from the RayCluster), so no loop - For a standalone RayCluster, if this function is called with
jobObjectbeing the RayCluster itself andrayClusterNamebeing its own name, setting the annotation on itself incrementsmetadata.generation, which makes the annotation stale again, causing an infinite update loop
The fix: In
GetWorkloadslicingRayClusterCustomAnnotations, check ifjobObjectis a*rayv1.RayClusterandjobObject.GetName() == rayClusterName. If so, skip theRayClusterGenerationAnnotation.Let me implement this fix. First, let me check the existing tests to understand what test patterns exist:
- Assistant
Let me look at the test to understand the test patterns:
- Assistant
Now I understand the full picture. Let me implement the fix. The issue is in
GetWorkloadslicingRayClusterCustomAnnotations- whenjobObjectis the same RayCluster asrayClusterName, it creates a self-update loop. The fix is to detect this case and skip theRayClusterGenerationAnnotation.Let me implement the fix:
- Assistant
Now let me apply the fix directly to the file:
- Assistant
Let me scroll down to see the GetWorkloadslicingRayClusterCustomAnnotations function.
- Assistant
Let me scroll down more to see the GetWorkloadslicingRayClusterCustomAnnotations function.
- Assistant
Let me see the rest of the file:
- Assistant
Now I can see the full function. Let me implement the fix. I need to modify
GetWorkloadslicingRayClusterCustomAnnotationsto check ifjobObjectis a*rayv1.RayClusterandjobObject.GetName() == rayClusterName, and if so, skip theRayClusterGenerationAnnotation.Let me edit the file directly.
- Assistant
Good, my edit is applied. But I notice a problem: when
isStandaloneRayClusteris true, theRayClusterGenerationAnnotationis still included in the returned map with an empty value"". The issue says to "omit" the annotation. Let me fix this: - Assistant
I see there's a duplicate closing brace/return at the end. Let me fix that.
- Assistant
Wait, there's still an extra
}at line 382. Let me check the full ending of the file: - Assistant
There's an extra
}at the end. Let me remove it. - Assistant
Good, the file looks correct now. Let me verify the file compiles:
- Assistant
Let me set up the Go cache properly.
- Assistant
Good, the code compiles. Now let me run the existing tests to make sure I haven't broken anything:
- Assistant
The existing tests pass. Now let me run all tests in the raycluster package:
- Assistant
All tests pass. Now let me also run the RayJob and RayService tests to make sure I haven't broken anything there:
- Assistant
All tests pass. Let me also run the RayService tests:
- Assistant
All tests pass. Let me also run the workloadslicing tests to make sure nothing is broken:
- Assistant
All tests pass. Let me verify the diff to make sure the changes look correct:
- Assistant
The diff looks clean and correct. Now let me also run the broader reconciler tests to make sure nothing is broken:
- Assistant
All tests pass. Let me also run the full test suite for the raycluster package one more time to make sure everything is good:
- Assistant
All tests pass. Let me verify the final state of the modified function:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.