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 a sense of the project layout.
- Assistant
Let me understand the issue better. The problem is in the RayCluster integration where a standalone elastic RayCluster gets continuously updated with a stale
raycluster-generationannotation. I need to find the code related toGetCustomAnnotationsandGetWorkloadslicingRayClusterCustomAnnotations. - Assistant
Let me explore the relevant files. The issue mentions that
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations. Let's look at the RayCluster controller code first. - Assistant
Let me look at the RayCluster controller and understand how
GetCustomAnnotationsis implemented: - Assistant
Let me search for GetCustomAnnotations in the codebase more broadly.
- Assistant
Now let me look at the RayCluster controller to see if it implements
GetCustomAnnotations: - Assistant
Let me look at the RayCluster controller to see how it implements GetCustomAnnotations:
- Assistant
Let me check the RayCluster controller to find how GetCustomAnnotations is implemented.
- Assistant
Now let me look at how the reconciler uses
GetCustomAnnotations: - Assistant
Let me look at how
GetCustomAnnotationsis called in the reconciler: - Assistant
Let me check if RayCluster implements the
JobWithCustomAnnotationsinterface: - Assistant
Let me search for the
JobWithCustomAnnotationsinterface definition and find which types implement it. - Assistant
Now let me check which types implement this interface:
- Assistant
I see the issue now. RayJob and RayService implement
GetCustomAnnotations, but I need to understand the flow for standalone RayClusters. Let me look at the git history for recent changes related to this: - Assistant
Now let me understand the flow better. The issue is that when the
jobObjectis the same RayCluster (standalone RayCluster),GetWorkloadslicingRayClusterCustomAnnotationsfetches the same object, gets its generation, and writes it back as an annotation on the same object, which bumps the generation again. Let me look at how this is called: - Assistant
Let me check if RayCluster implements
GetCustomAnnotations: - Assistant
Interesting - RayCluster doesn't seem to implement
GetCustomAnnotations. Let me look more carefully at the code structure and the issue. The issue says "For standalone RayClusters,GetCustomAnnotationscalls...". Let me look at the RayJob implementation more carefully to understand the context: - Assistant
Now let me look at the RayCluster controller more carefully. I notice that
RayClustertype does NOT implementJobWithCustomAnnotations. But the issue says it should for elastic workloads. Let me check the RayService implementation to understand the pattern: - Assistant
Let me check where the RayCluster controller implements
GetCustomAnnotations- perhaps it's missing and that's part of the issue: - Assistant
Let me search for where the RayCluster type might implement GetCustomAnnotations more broadly:
- Assistant
I see that only RayJob and RayService implement
GetCustomAnnotations. But the issue says standalone RayClusters are affected. Let me look at how the RayCluster controller reconciliation flow works - maybe the RayCluster is being treated as its own jobObject: - Assistant
Let me search more broadly - maybe the RayCluster implements
GetCustomAnnotationsindirectly or through some other means: - Assistant
Let me look at the reconciler more carefully to understand the workload slicing code path:
- Assistant
Let me check if there's a
GetCustomAnnotationsimplementation somewhere I might have missed: - Assistant
Let me check the current git branch/version:
- Assistant
Let me look at how RayCluster is handled with elastic workload slicing. Let me check
GetWorkloadNameExtraPart: - Assistant
Let me re-read the issue more carefully. It says "For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)." Let me check if RayCluster implements this interface somewhere I haven't seen: - Assistant
Looking at the code, I notice that:
-
RayJobimplementsGetCustomAnnotationswhich callsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Status.RayClusterName)- this is correct becausej.Object()is the RayJob, not the RayCluster. -
RayServicealso implementsGetCustomAnnotationssimilarly.
-
- Assistant
Let me look more carefully at the issue. The issue says the RayCluster has
GetCustomAnnotations. Let me check if there's something I'm missing: - Assistant
Looking at the code, I can see that:
RayJobimplementsGetCustomAnnotationswith:j.Object()= RayJob object,rayClusterName=j.Status.RayClusterName(different object)RayServiceimplementsGetCustomAnnotationswith:j.Object()= RayService object,rayClusterName=j.Status.ActiveServiceStatus.RayClusterName(different object)
But the issue says standalone RayClusters also need this functionality. The problem occurs when
GetWorkloadslicingRayClusterCustomAnnotationsis called withjobObjectbeing the same RayCluster asrayClusterName. Let me look at how this function works: - Assistant
Wait, I need to re-read the issue more carefully. The issue describes that the RayCluster implements
GetCustomAnnotations. But looking at the code,RayClusterdoesn't implement this interface. However, I see the testTestGetWorkloadslicingCustomAnnotationstests theGetWorkloadslicingRayClusterCustomAnnotationshelper function, and the test uses a ConfigMap (not a RayCluster). Let me think about what's happening...Looking at the issue description again: "For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name)." This seems to suggest the RayCluster IS supposed to implementGetCustomAnnotations, and when it does, it would pass itself asjobObjectANDj.NameasrayClusterName.But actually, looking at the current code, only RayJob and RayService implement this. Let me check if there's been recent changes to add it to RayCluster:
- Assistant
Let me search for how a standalone RayCluster reconciler path could call this function:
- Assistant
I see the issue now. Let me look at the
JobPodSetsfunction and how workload slicing works for standalone RayClusters. The RayCluster type doesn't implementGetCustomAnnotations, but maybe it should. Let me check if there's been recent additions: - Assistant
Let me look at commit 80b04a2c8 which seems to be the one that introduced the generation-based elastic workload names.
- Assistant
Let me look at the full raycluster_controller_test.go to understand if there's supposed to be a
GetCustomAnnotationsfor RayCluster: - Assistant
Let me search more broadly for all implementations of
GetCustomAnnotations: - Assistant
Let me look at where
RayClusterGenerationAnnotationis actually used: - Assistant
I see. Now let me understand the actual issue. Let me look at what happens in the reconciler path for standalone RayClusters with elastic workloads. Let me check if the RayCluster actually does implement
GetCustomAnnotations- perhaps through a type assertion path: - Assistant
I see that RayCluster doesn't implement
GetCustomAnnotations. But the issue says it should. Let me understand the flow better. The issue says that for standalone RayClusters,GetCustomAnnotationsis called. Let me check if perhaps there's a code path where the RayCluster gets these annotations set on it through the RayJob/RayService path when they share the same object.Actually, let me re-read the issue description very carefully:
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 implies the RayCluster SHOULD implement
GetCustomAnnotations. Let me check if perhaps theElasticWorkloadNameProviderinterface is the one that's causing the issue. Let me look at howGetWorkloadNameExtraPartis called: - Assistant
Let me look at the full flow more carefully. Let me check the reconciler function to understand the full code path:
- Assistant
Let me look at the
WorkloadSliceEnabledfunction: - Assistant
Let me look at what happens in the reconciler when processing a standalone RayCluster with workload slicing enabled:
- Assistant
Now I understand the issue better. The problem is in
GetWorkloadslicingRayClusterCustomAnnotations. When called for a standalone RayCluster (wherejobObjectIS the RayCluster itself andrayClusterNameis its own name), it fetches the same RayCluster, reads its generation, and writes it back as an annotation. This causes the generation to bump, creating an infinite loop.The fix should be: when
jobObjectis the same RayCluster asrayClusterName, omit theraycluster-generationannotation. Let me look at the exact implementation: - Assistant
Now I understand the issue. The
GetWorkloadslicingRayClusterCustomAnnotationsfunction fetches the RayCluster object by name and writes its back as an annotation. When IS the same RayCluster (standalone), this creates a self-updating loop: writing the annotation bumps the generation, which makes the annotation stale. - Assistant
Let me look at what
JobPodSetsdoes and how the RayCluster gets processed during reconciliation: - Assistant
Let me search for JobPodSets in the whole repo.
- Assistant
Now I understand the full picture. Looking at the issue, the problem is in
GetWorkloadslicingRayClusterCustomAnnotations. When a standalone RayCluster (where thejobObjectIS the RayCluster itself, andrayClusterNameis its own name) calls this function, it fetches the same RayCluster, reads its generation, and writes it back as an annotation. The annotation patch bumps the generation, making the annotation stale again, creating an infinite loop.The fix should be: when
jobObjectis a RayCluster andjobObject.GetName() == rayClusterName, skip theRayClusterGenerationAnnotationsince the standalone RayCluster should not write its own generation back onto itself.However, I notice that the RayCluster type doesn't currently implement
GetCustomAnnotations. The issue describes that it does (or should). Let me first make the fix inGetWorkloadslicingRayClusterCustomAnnotationsto handle the standalone case, and then see if I need to addGetCustomAnnotationsto RayCluster.Let me implement the fix:
- Assistant
Let me go to the specific function I need to modify.
- Assistant
Now I understand the issue clearly. The
GetWorkloadslicingRayClusterCustomAnnotationsfunction is used by both RayJob and RayService wherejobObjectis different from the underlying RayCluster (so fetching the RayCluster's generation is correct). But for a standalone RayCluster,jobObjectIS the same RayCluster asrayClusterName, causing a self-update loop.The fix is to detect when
jobObjectis the same RayCluster asrayClusterNameand skip theRayClusterGenerationAnnotation. Let me also check whether the RayCluster type currently implementsGetCustomAnnotationsor needs to be added: - Assistant
Let me check if the RayCluster type currently implements
GetCustomAnnotationsby looking at what interfaces it satisfies: - Assistant
I see that RayCluster does NOT currently implement
GetCustomAnnotations. The issue says it does (in v0.16.5), which means the fix needs to be applied toGetWorkloadslicingRayClusterCustomAnnotationsto handle both cases. Let me now implement the fix.The fix should:
- In
GetWorkloadslicingRayClusterCustomAnnotations, detect whenjobObjectis the same RayCluster asrayClusterName - Skip setting
RayClusterGenerationAnnotationin that case
- In
- Assistant
Wait, I have a bug in my fix. The condition
jobObject.GetNamespace() == jobObject.GetNamespace()is always true (comparing the same object's namespace to itself). Let me fix that. Actually, it doesn't matter because ifjobObject.GetName() == rayClusterName, that's sufficient since both are in the same namespace. Let me simplify: - Assistant
Now I need to also add the
GetCustomAnnotationsmethod to the RayCluster type and the interface assertion. Let me also add theElasticWorkloadNameProviderinterface if needed.Actually, wait. Let me reconsider. Looking at the issue again - the issue says the loop already happens in v0.16.5. Let me look at whether the RayCluster type already implements
GetCustomAnnotationsin some other form. Let me check if there's a different version of this method: - Assistant
Now I need to add the
GetCustomAnnotationsmethod to the RayCluster type. Let me add it along with the interface assertion: - Assistant
Let me add the
GetCustomAnnotationsmethod to the RayCluster type: - Assistant
Now I need to add the
GetCustomAnnotationsmethod to the RayCluster type. Let me add it after thePodSetsmethod: - Assistant
Now I'll add the
GetCustomAnnotationsmethod to the RayCluster type: - Assistant
I see there are duplicate lines. Let me fix the file:
- Assistant
I see duplicate lines. Let me fix the file properly:
- Assistant
Good. Now let me verify both files are clean:
- Assistant
Now let me verify the common.go file is correct:
- Assistant
Good, both files look clean. Let me also check the
GetWorkloadNameExtraPartfunction - for a standalone RayCluster, when the generation annotation is empty (because we skipped it), the function should still work correctly: - Assistant
Good. For a standalone RayCluster, when the generation annotation is empty (because we skipped it),
GetWorkloadNameExtraPartwill return just the generation number without the_generationsuffix, which is correct.Now let me run the tests to verify the changes:
- Assistant
I need to set up the Go cache properly.
- Assistant
All tests pass. Let me also run the tests for the RayJob and RayService controllers to make sure we didn't break anything:
- Assistant
Good. All tests pass. Let me also run the tests for the rayservice controller:
- Assistant
All tests pass. Let me also run the broader test suite to make sure nothing is broken:
- Assistant
All tests pass. Let me also check the diff to make sure the changes are correct:
- Assistant
The changes look correct. Let me verify by looking at the
mergeAnnotationsfunction to understand how empty values are handled: - Assistant
Looking at the
mergeAnnotationsfunction, I can see that:- For standalone RayClusters, after the fix,
RayClusterGenerationAnnotationwill be set to""(empty string) - If the RayCluster previously had a non-empty generation annotation, the first reconcile will clear it
- On subsequent reconciles, the annotations won't change (since the generation annotation is already empty and podset replica sizes haven't changed)
This is correct. The fix should prevent the infinite reconcile loop.
Now let me also check if there are any other tests that might be affected by adding
GetCustomAnnotationsto the RayCluster type. Let me run the full test suite: - For standalone RayClusters, after the fix,
- Assistant
All tests pass. Let me also run the broader test suite to make sure nothing is broken:
- Assistant
All tests pass. Let me verify the final state of my 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.