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
Let me start by understanding the issue. The problem is that Kueue is continuously updating a standalone RayCluster with a
kueue.x-k8s.io/raycluster-generationannotation, which causes the RayCluster'smetadata.generationto increment, making the annotation stale again, leading to an infinite patch loop.The key insight from the issue is:
- The
kueue.x-k8s.io/raycluster-generationannotation tracks the RayCluster's generation - For standalone RayClusters, this annotation causes an infinite loop because:
- The helper fetches the RayCluster and returns its generation as an annotation
- Writing this annotation back to the RayCluster patches it
- The patch increments the RayCluster's generation
- This makes the annotation stale again
- The loop continues
The fix should be to omit the
kueue.x-k8s.io/raycluster-generationannotation when the job object is the same standalone RayCluster asrayClusterName.Let me start by exploring the repository structure to understand the codebase.
- The
Assistant
Let me look at the source code structure to find the relevant files for RayCluster handling.
<tool_call> <function=bash_terminal> <parameter=command> find /kueue/pkg -type f -name "*.go" | grep -i ray | head -20 </tool_call>
Assistant
Let me search for ray-related Go files in the pkg directory.
Assistant
Good, I found the RayCluster related files. The issue mentions
GetCustomAnnotationsandGetWorkloadSlicingRayClusterCustomAnnotations. Let me search for these functions to understand the code flow.<tool_call> <function=bash_terminal> <parameter=command> grep -r "GetWorkloadSlicingRayClusterCustomAnnotations" /kueue/pkg --include="*.go" </tool_call>
Assistant
Let me search for this function.
Assistant
The command returned exit code 1, which might mean grep didn't find the exact string. Let me try with a different approach - searching for the annotation name.
<tool_call> <function=bash_terminal> <parameter=command> grep -r "raycluster-generation" /kueue/pkg --include="*.go" </tool_call>
Assistant
Let me use the bash_terminal tool properly with a function call.
Assistant
Good! I found the annotation constant. Now let me look at the file that defines it and understand the context better.
<tool_call> <function=bash_terminal> <parameter=command> cat /kueue/pkg/controller/jobs/raycluster/common.go </tool_call>
Assistant
Let me use the bash_terminal tool correctly to view the content of common.go file.
Assistant
Now I can see the
GetWorkloadSlicingRayClusterCustomAnnotationsfunction. This function:- Fetches a RayCluster
- Returns annotations including
RayClusterGenerationAnnotationwith the RayCluster's generation - This is called by the Kueue controller to update the RayCluster with these annotations
The issue is that when the job object IS the same standalone RayCluster, this function returns the RayCluster's generation as an annotation to write back onto the RayCluster. This causes a patch, which advances the RayCluster's generation, making the annotation stale.
Let me now find where this function is called. Let me search for it in the codebase.
<tool_call> <function=bash_terminal> <parameter=command> grep -rn "GetWorkloadslicingRayClusterCustomAnnotations" /kueue --include="*.go" </tool_call>
Assistant
Let me search for the function call.
Assistant
Now I see the issue! The function
GetWorkloadslicingRayClusterCustomAnnotationsis called in:/kueue/pkg/controller/jobs/rayjob/rayjob_controller.go:216- for RayJob (where it makes sense)/kueue/pkg/controller/jobs/rayservice/rayservice_controller.go:227- for RayService (where it makes sense)
But there might also be a call for RayCluster standalone. Let me check the raycluster_controller.go file to see where GetCustomAnnotations is called.
<tool_call> <function=bash_terminal> <parameter=command> cat /kueue/pkg/controller/jobs/raycluster/raycluster_controller.go </tool_call>
Assistant
Let me view the raycluster_controller.go file to understand how GetCustomAnnotations is called.
Assistant
Now I need to find where GetCustomAnnotations is called in the base code. Let me search for it in the jobframework.
<tool_call> <function=bash_terminal> <parameter=command> grep -rn "GetCustomAnnotations" /kueue/pkg --include="*.go" </tool_call>
Assistant
Let me search for the GetCustomAnnotations function in the jobframework.
Assistant
Let me see the reconciler.go file to understand how GetCustomAnnotations is called.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '950,990p' /kueue/pkg/controller/jobframework/reconciler.go </tool_call>
Assistant
Let me view the reconciler.go file to see the context where GetCustomAnnotations is called.
Assistant
Now I understand the issue better. Let me look at where the
JobPodSetsis called and what it returns for RayCluster standalone. Let me check the interface definition.The issue is:
- When
WorkloadSliceEnabled(job)is true for a standalone RayCluster - The reconciler calls
jobWithCustomAnnotations.GetCustomAnnotations(ctx, r.client, podSets) - If
RayClusterimplementsJobWithCustomAnnotations, it will get custom annotations - For RayCluster standalone, the annotations include the RayCluster's own generation
- Writing these annotations back patches the RayCluster, advancing its generation
- This makes the annotation stale again, causing a loop
Let me check if RayCluster implements
GetCustomAnnotations.<tool_call> <function=bash_terminal> <parameter=command> grep -n "GetCustomAnnotations" /kueue/pkg/controller/jobs/raycluster/*.go </tool_call>
- When
Assistant
Let me search for GetCustomAnnotations implementation in the raycluster package.
Assistant
RayCluster does NOT implement GetCustomAnnotations directly. Let me check the rayjob and rayservice implementations to see how they work.
Assistant
Now I understand the issue better. Let me also check the rayservice_controller.go to see how it's structured:
Assistant
So both
RayJobandRayServiceimplementGetCustomAnnotationswhich callsraycluster.GetWorkloadslicingRayClusterCustomAnnotations. ButRayClusterstandalone doesn't implement this method.However, the issue says the problem is for standalone RayClusters. Let me check if the reconciler in reconciler.go is calling
GetCustomAnnotationsonRayClusterthrough the base class.Let me check if
RayClusterimplementsJobWithCustomAnnotations:Assistant
No results found. Let me check what interfaces RayCluster implements.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "var _" /kueue/pkg/controller/jobs/raycluster/raycluster_controller.go </tool_call>
Assistant
Let me look for interface implementations in the raycluster controller.
Assistant
RayCluster does NOT implement
JobWithCustomAnnotations. But the issue says the problem is for standalone RayClusters being continuously patched.Let me check the
raycluster_controller.goagain to see if it's callingGetWorkloadSlicingRayClusterCustomAnnotationsdirectly somewhere.<tool_call> <function=bash_terminal> <parameter=command> grep -n "GetWorkloadSlicingRayClusterCustomAnnotations" /kueue/pkg/controller/jobs/raycluster/raycluster_controller.go </tool_call>
Assistant
The function
GetWorkloadSlicingRayClusterCustomAnnotationsis not being called directly in the raycluster_controller.go. Let me check the common.go file more carefully to see if there's aGetCustomAnnotationsfunction in common.go or if there's another entry point.Let me search for where the raycluster's annotations are being updated.
Assistant
Let me search more broadly for where the RayCluster's annotations are being patched.
Assistant
Now I need to understand the flow. The issue says that
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotationsfor standalone RayClusters. Let me re-read the issue.The issue says:
For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).So there must be a
GetCustomAnnotationsfunction onRayClusterthat's callingGetWorkloadslicingRayClusterCustomAnnotations. Let me search again in the common.go file and the entire raycluster directory.<tool_call> <function=bash_terminal> <parameter=command> grep -n "GetCustomAnnotations" /kueue/pkg/controller/jobs/raycluster/common.go </tool_call>
Assistant
Let me search for GetCustomAnnotations in the entire raycluster directory:
Assistant
No results. Let me check the raycluster_controller.go file more carefully for where the raycluster generation is written back to the raycluster.
Assistant
Let me check if the raycluster_controller.go file has a webhook or any update mechanism:
Assistant
Let me look at the reconciler.go file to find the issue. The reconciler is calling GetCustomAnnotations for jobs that implement JobWithCustomAnnotations. But RayCluster doesn't implement JobWithCustomAnnotations, so that can't be the issue.
Wait, let me re-read the issue description again:
For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).This suggests that somewhere there's a
GetCustomAnnotationsfunction forRayClusterthat callsGetWorkloadSlicingRayClusterCustomAnnotations. Let me search more carefully.Let me check the full content of the raycluster_controller.go file again and look for where the issue might be:
<tool_call> <function=bash_terminal> <parameter=command> wc -l /kueue/pkg/controller/jobs/raycluster/raycluster_controller.go </tool_call>
Assistant
Let me check the line count of the file first.
Assistant
The file has 208 lines. Let me check if there's a GetCustomAnnotations implementation at the end of the file:
<tool_call> <function=bash_terminal> <parameter=command> tail -100 /kueue/pkg/controller/jobs/raycluster/raycluster_controller.go </tool_call>
Assistant
Let me use the bash_terminal tool with the proper command format.
Assistant
Assistant
Let me check the git history for recent changes to the raycluster controller.
Assistant
Let me check the commit
80b04a2c8 Generate elastic workload name based on raycluster generation (#9960)which might be related to this issue:<tool_call> <function=bash_terminal> <parameter=command> git -C /kueue show 80b04a2c8 --stat </tool_call>
Assistant
The git command is not working. Let me try with the proper tool syntax.
Assistant
This commit is about generating elastic workload names based on RayCluster generation. Let me check what changes were made to the raycluster_controller.go file in this commit to see if it added the
GetCustomAnnotationsmethod:Assistant
No changes to the raycluster_controller.go file in that commit. Let me check if there have been any more recent commits that added
GetCustomAnnotationsto the RayCluster:Assistant
Let me check the full git log for commits that might have added the GetCustomAnnotations to RayCluster:
Assistant
Now I'm confused. Let me read the issue description again. The issue says:
For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).Maybe this is describing the behavior that SHOULD happen (or was intended to happen) but isn't implemented yet? Or maybe the issue is that we need to add this method to RayCluster?
Let me check if there's a recent commit or if there's some code that was supposed to be added but wasn't:
<tool_call> <function=bash_terminal> <parameter=command> git -C /kueue log --all --oneline --since="2024-12-01" -- pkg/controller/jobs/raycluster/ | head -20 </tool_call>
Assistant
Let me check the recent commits more carefully to understand if there's a method being added.
<tool_call> <function=bash_terminal> <parameter=command> git -C /kueue log --all --oneline --since="2024-12-01" -- pkg/controller/jobs/raycluster/ | head -20 </tool_call>
Assistant
Let me try a different approach. Let me search for any implementation of GetCustomAnnotations on RayCluster in the entire codebase, including uncommitted changes.
Assistant
Let me search for "GetCustomAnnotations" in the current codebase to see if RayCluster implements it.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "GetCustomAnnotations" /kueue/pkg/controller/jobs/raycluster/raycluster_controller.go </tool_call>
Assistant
Let me try a simpler grep command to search for GetCustomAnnotations in the raycluster controller.
Assistant
The exit code 1 from grep means no match was found. So RayCluster currently does NOT implement
GetCustomAnnotations. Let me now understand the issue better. The issue says:For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).Maybe this is describing a method that needs to be ADDED, and the fix is to NOT include the
raycluster-generationannotation when the job object is the same as the RayCluster.Let me check if there's been any recent addition to the code that would call this method for RayCluster. Let me look at the git diff of recent commits:
<tool_call> <function=bash_terminal> <parameter=command> git -C /kueue show 80b04a2c8 -- pkg/controller/jobs/raycluster/common.go | head -200 </tool_call>
Assistant
Let me search for the function GetWorkloadSlicingRayClusterCustomAnnotations to see how it's defined and used:
Assistant
Now I understand the issue better. The function
GetWorkloadslicingRayClusterCustomAnnotationswas added in commit 80b04a2c8. It returns annotations that includeRayClusterGenerationAnnotation.Looking at the usages:
- RayJob calls it with
j.Status.RayClusterName(the RayCluster managed by the RayJob) - RayService calls it with
j.Status.ActiveServiceStatus.RayClusterName(the RayCluster managed by the RayService)
But the issue says that standalone RayClusters are also being patched with these annotations. Let me check if there's a
GetCustomAnnotationsmethod onRayClusterthat needs to be added.Actually, wait. The issue says:
For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).This suggests that someone has added a
GetCustomAnnotationsmethod toRayClusterthat callsGetWorkloadslicingRayClusterCustomAnnotationswith . This method would then return the with the RayCluster's own generation, which causes the self-patching loop.- RayJob calls it with
Assistant
Let me check if there's a GetCustomAnnotations method on RayCluster in the current codebase.
Assistant
So there's no
GetCustomAnnotationsmethod onRayCluster. Let me check if the issue is that we need to ADD this method and the fix is to make it not include theRayClusterGenerationAnnotationwhen it's the same RayCluster.Actually, let me re-read the issue description one more time to understand what's happening:
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.So the annotation IS being set and is one value behind. Let me check if there's a
GetCustomAnnotationsmethod that needs to be added toRayCluster.Let me look at the reconciler.go to see how the annotations are patched:
Assistant
OK, so the flow is:
- If
WorkloadSliceEnabled(job)is true and the job implementsJobWithCustomAnnotations, then:- Get custom annotations from the job
- Merge and patch the job with the custom annotations
For RayCluster standalone to have this issue, it must implement
JobWithCustomAnnotations. Let me check if it does:<tool_call> <function=bash_terminal> <parameter=command> grep -n "JobWithCustomAnnotations" /kueue/pkg/controller/jobs/raycluster/raycluster_controller.go </tool_call>
- If
Assistant
Let me check if RayCluster implements JobWithCustomAnnotations interface.
Assistant
RayCluster does NOT implement
JobWithCustomAnnotationsin the current codebase. Let me check if there's an issue with theWorkloadSliceEnabledfunction or if there's something else that's causing the self-patching loop.Let me search for where the
RayClusterGenerationAnnotationis being set or patched.Assistant
Now I see that
RayClusterGenerationAnnotationis only set inGetWorkloadslicingRayClusterCustomAnnotations. But the issue says that standalone RayClusters are having this annotation set. Let me check if there's aGetCustomAnnotationsmethod onRayClusterthat was added but not committed yet, or if there's another place where the annotation is being set.Actually, let me check if the issue is that the
RayClusterneeds to implementJobWithCustomAnnotationsand the fix is to make that method NOT include theRayClusterGenerationAnnotationwhen the RayCluster is the same as the job object.Let me create a test script to understand the issue better.
First, let me check the interface definition to understand what
JobWithCustomAnnotationsrequires:<tool_call> <function=bash_terminal> <parameter=command> grep -A 5 "JobWithCustomAnnotations" /kueue/pkg/controller/jobframework/interface.go </tool_call>
Assistant
Let me search for the interface definition of JobWithCustomAnnotations.
Assistant
Now I understand the interface. Let me check if
RayClusterimplements this interface:Assistant
Let me view the entire raycluster_controller.go file to see all methods:
Assistant
I see that
RayClusterdoes NOT have aGetCustomAnnotationsmethod. Let me check the current state of the repository to see if there's any uncommitted changes or if I need to understand the issue better.Actually, wait. Let me re-read the issue more carefully:
For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).This is describing what's happening (the problem), not what should happen. The issue is that somehow
GetCustomAnnotationsis being called on a standalone RayCluster, which causes the self-patching loop.Let me check if there's a
GetCustomAnnotationsmethod that was added toRayClusterbut not yet committed:<tool_call> <function=bash_terminal> <parameter=command> git -C /kueue diff HEAD -- pkg/controller/jobs/raycluster/raycluster_controller.go </tool_call>
Assistant
Let me check for any uncommitted changes in the raycluster controller.
Assistant
No changes. Let me check if there's a separate file or if the
GetCustomAnnotationsmethod is defined elsewhere.Assistant
Let me check if there's a GetCustomAnnotations method anywhere in the common.go file that might be called for RayCluster.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "GetCustomAnnotations" /kueue/pkg/controller/jobs/raycluster/common.go </tool_call>
Assistant
There's no
GetCustomAnnotationsmethod in common.go. Let me understand the issue better by looking at the problem from a different angle.The issue says that standalone RayClusters are being continuously patched with the
kueue.x-k8s.io/raycluster-generationannotation. This suggests that either:- Someone added a
GetCustomAnnotationsmethod toRayClusterthat wasn't committed yet - There's some other mechanism causing this
Let me check if there's a
GetCustomAnnotationsmethod that was added but not committed:Actually, I realize I should check if maybe the issue is that
RayClusterneeds to implementGetCustomAnnotationsbut it's not doing so correctly, or if there's another issue.Wait, let me re-read the issue description again:
For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).- Someone added a
Assistant
Let me look at the interface implementations in the raycluster controller to understand what interfaces are being implemented.
Assistant
RayClusterdoes NOT implementJobWithCustomAnnotations. So the issue must be something else.Wait, let me re-read the issue description more carefully:
What happened: A standalone Kueue-managed elastic RayCluster is continuously updated by Kueue.
Maybe the issue is that
RayClusterSHOULD implementJobWithCustomAnnotationsbut it's missing this implementation, causing some other code path to be taken.Actually, I think I finally understand the issue. Let me check if the
GetCustomAnnotationsmethod has been added toRayClusterbut the fix is to make it not include theraycluster-generationannotation when it's the same RayCluster.Let me check if there's a recent change or if the issue is that we need to add the
GetCustomAnnotationsmethod toRayCluster:Assistant
The repository is clean with no uncommitted changes. Let me check the current HEAD commit to understand what version of the codebase we're working with:
Assistant
The current HEAD is
4cc62da8e. The issue was reported against Kueue v0.16.5, but we're working with a later version of the codebase. Let me check if theGetCustomAnnotationsmethod was added toRayClusterafter the v0.16.5 release.Let me check the commit history to see when
GetCustomAnnotationswas added toRayCluster:<tool_call> <function=bash_terminal> <parameter=command> git -C /kueue log --all --oneline --grep="RayCluster" -- pkg/controller/jobs/raycluster/raycluster_controller.go | head -10 </tool_call>
Assistant
Let me search for commits that added GetCustomAnnotations to RayCluster.
Assistant
Let me check if there's any commit that added GetCustomAnnotations to RayCluster standalone. Let me search the git log for "GetCustomAnnotations" and "RayCluster":
Assistant
No commits found that mention "GetCustomAnnotations". Let me check the issue description again more carefully.
The issue says:
For standalone RayClusters,
GetCustomAnnotationscallsGetWorkloadSlicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name).I think the issue is describing what SHOULD happen (or what someone intended to happen) but is causing a problem. The fix is to make the
GetCustomAnnotationsmethod onRayClusterNOT include theRayClusterGenerationAnnotationwhen it's the same RayCluster.Let me check if the
RayClusterneeds to implementJobWithCustomAnnotationsbut the implementation hasn't been added yet. Let me check the RayJob and RayService implementations to see how they do it:Assistant
Now I see the pattern.
RayJob.GetCustomAnnotationscallsraycluster.GetWorkloadslicingRayClusterCustomAnnotationswithj.Status.RayClusterNameas the RayCluster name.Similarly,
RayService.GetCustomAnnotationscalls it withj.Status.ActiveServiceStatus.RayClusterName.For
RayClusterstandalone, if it were to implementGetCustomAnnotations, it would call it withj.Name(the RayCluster's own name), which would cause the self-patching loop.The fix should be to either:
- NOT add
GetCustomAnnotationstoRayCluster(which would avoid the self-patching loop) - OR add
GetCustomAnnotationstoRayClusterbut make it NOT include theRayClusterGenerationAnnotationwhen
- NOT add
Assistant
Now I understand the fix. The
GetWorkloadslicingRayClusterCustomAnnotationsfunction should NOT include theRayClusterGenerationAnnotationwhenjobObject.GetName() == rayClusterName. This is because:- For RayJob/RayService,
rayClusterNameis different fromjobObject.GetName(), so the annotation should be included. - For standalone RayCluster,
rayClusterName == jobObject.GetName(), so including the annotation would cause the self-patching loop.
The fix should be to add a check at the beginning of the function to return early if
jobObject.GetName() == rayClusterName, or to only include theRayClusterGenerationAnnotationwhen they are different.Let me implement the fix. The fix should:
- Check if
jobObject.GetName() == rayClusterName - If so, only return the
RayClusterPodsetReplicaSizesAnnotationwithout theRayClusterGenerationAnnotation
Let me create the fix:
- For RayJob/RayService,
Assistant
Now I'll implement the fix. The fix should:
- Check if
jobObject.GetName() == rayClusterName - If so, only return the
RayClusterPodsetReplicaSizesAnnotationwithout theRayClusterGenerationAnnotation
Let me create the fix:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/fix.patch << 'EOF' --- a/pkg/controller/jobs/raycluster/common.go +++ b/pkg/controller/jobs/raycluster/common.go @@ -334,6 +334,13 @@ func GetWorkloadslicingRayClusterCustomAnnotations(ctx context.Context, c client if workloadslicing.Enabled(jobObject) { log := ctrl.LoggerFrom(ctx)
-
// If the job object is the same as the RayCluster, we should not include -
// the raycluster-generation annotation to avoid a self-patching loop. -
// The annotation is useful for RayJob and RayService, where the top-level -
// object needs to account for an underlying RayCluster generation. -
if jobObject.GetName() == rayClusterName { -
return nil, nil -
} rayClusterGeneration := "" var rayClusterObj rayv1.RayCluster
- Check if
Assistant
Let me use the edit command to add the fix to the common.go file.
Assistant
Now let me use the edit command to add the fix to the common.go file. First, let me check the exact line numbers.
Assistant
Let me edit the file to add the fix. I need to add the check right after line 336 (the if statement) and before the log statement.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '334,370p' /kueue/pkg/controller/jobs/raycluster/common.go </tool_call>
Assistant
Let me use sed to insert the fix at the correct location.
Assistant
Now I'll use the edit command to insert the fix. I need to add the check after line 337 (the
log := ctrl.LoggerFrom(ctx)line) and before therayClusterGeneration := ""line.<tool_call> <function=bash_terminal> <parameter=command> sed -i '337a
// If the job object is the same as the RayCluster, we should not include
// the raycluster-generation annotation to avoid a self-patching loop.
// The annotation is useful for RayJob and RayService, where the top-level
// object needs to account for an underlying RayCluster generation.
if jobObject.GetName() == rayClusterName {
return nil, nil
}' /kueue/pkg/controller/jobs/raycluster/common.go </tool_call>Assistant
Let me verify the file was modified correctly:
Assistant
The sed command didn't work as expected. Let me try a different approach using the edit command.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '334,370p' /kueue/pkg/controller/jobs/raycluster/common.go </tool_call>
Assistant
The sed command didn't work as expected. Let me try to use the edit command instead to modify the file. First, let me see the current state of the file around the area I need to modify.
Assistant
The edit command didn't work as expected. Let me try a different approach - I'll use sed to replace the specific line and add the fix. Let me first see what line 337 looks like and then add the fix after it.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '335,342p' /kueue/pkg/controller/jobs/raycluster/common.go </tool_call>
Assistant
The sed command doesn't seem to be working as expected. Let me try a different approach - I'll create a new version of the file with the fix applied.
Let me first backup the original file and then create a new version with the fix.
Assistant
It seems the sed command is not outputting the content. Let me try a different approach. I'll use the
opentool to open the file and then use theeditcommand to modify it.First, let me check what the current state of the file is around line 336-338.
Actually, looking at the previous output, I see that line 335 is the function signature, line 336 is
if workloadslicing.Enabled(jobObject), line 337 islog := ctrl.LoggerFrom(ctx), and line 338 is empty. I need to add the fix after line 338.Let me use the edit command to add the fix.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '335,342p' /kueue/pkg/controller/jobs/raycluster/common.go </tool_call>
Assistant
The bash_terminal command seems to be returning unexpected results. Let me try a different approach to see the file content.
Assistant
Now I can see the file content. I need to add the fix after line 337 (the
log := ctrl.LoggerFrom(ctx)line). Let me use sed to insert the fix at line 338 (the empty line after the log statement).Actually, let me use a more reliable approach. I'll read the entire file, modify it, and write it back.
First, let me count the lines in the file:
<tool_call> <function=bash_terminal> <parameter=command> wc -l /kueue/pkg/controller/jobs/raycluster/common.go </tool_call>
Assistant
Let me try a different approach to modify the file. I'll use sed to insert the fix after line 337.
Assistant
Now I can use sed to insert the fix. The issue is that the sed command doesn't seem to be inserting the text correctly. Let me try a different approach - I'll use sed to replace the specific line with the new text.
Actually, looking at the output more carefully, I see that the sed command with
sed -n '335,342p'is returning the content. This means the file is being read correctly. The issue is with the insert command.Let me try a different approach using sed to replace lines. I'll replace line 338 (the empty line after
log := ctrl.LoggerFrom(ctx)) with the new text.Actually, looking at the output again, I see that line 337 is
log := ctrl.LoggerFrom(ctx)and line 338 is empty. I need to add the fix after line 338.Let me try using sed to insert the fix after line 337 (the log statement):
<tool_call> <function=bash_terminal> <parameter=command> sed -i '337a
\t\t// If the job object is the same as the RayCluster, we should not include
\t\t// the raycluster-generation annotation to avoid a self-patching loop.
\t\t// The annotation is useful for RayJob and RayService, where the top-level
\t\t// object needs to account for an underlying RayCluster generation. \t\tif jobObject.GetName() == rayClusterName { \t\t\treturn nil, nil \t\t}' /kueue/pkg/controller/jobs/raycluster/common.go </tool_call>Assistant
Let me verify if the file was modified:
Assistant
The sed command didn't work. Let me try a different approach - I'll create a Python script to modify the file.
<tool_call> <function=bash_terminal> <parameter=command> python3 << 'EOF' with open('/kueue/pkg/controller/jobs/raycluster/common.go', 'r') as f: content = f.read()
Find the location to insert the fix
We need to find the function GetWorkloadslicingRayClusterCustomAnnotations and add the check after the log line
old_text = '''func GetWorkloadslicingRayClusterCustomAnnotations(ctx context.Context, c client.Client, jobObject client.Object, podSets []kueue.PodSet, rayClusterName string) (map[string]string, error) { if workloadslicing.Enabled(jobObject) { log := ctrl.LoggerFrom(ctx)
rayClusterGeneration := ""'''new_text = '''func GetWorkloadslicingRayClusterCustomAnnotations(ctx context.Context, c client.Client, jobObject client.Object, podSets []kueue.PodSet, rayClusterName string) (map[string]string, error) { if workloadslicing.Enabled(jobObject) { log := ctrl.LoggerFrom(ctx)
Assistant
The Python script should have modified the file. Let me verify if the change was applied correctly.
Assistant
The file wasn't modified. Let me check what's happening. The old text might have different whitespace or there might be an issue with the string matching.
Let me try a different approach - I'll read the file, find the exact text, and print out the first few characters to debug:
<tool_call> <function=bash_terminal> <parameter=command> python3 << 'EOF' with open('/kueue/pkg/controller/jobs/raycluster/common.go', 'r') as f: content = f.read()
Let's find the function
idx = content.find('func GetWorkloadslicingRayClusterCustomAnnotations') print(f"Found at index: {idx}") if idx != -1: print(f"Context around function definition:") print(repr(content[idx:idx+300])) EOF </tool_call>
Assistant
The Python script is not outputting anything, which suggests there might be an issue with the script or the file. Let me try a different approach to understand what's happening.
Assistant
I can see the function definition. Now let me try to modify the file with the correct text. The issue is that the tab characters need to be handled correctly. Let me try again with the correct whitespace:
Assistant
The file was modified successfully. Let me verify the change:
Assistant
The fix has been applied. Now let me verify that the code compiles correctly and that the existing tests pass.
Assistant
The build failed due to missing cache configuration. Let me set the environment variable and try again:
Assistant
The code compiles successfully. Now let me run the existing tests to make sure the fix doesn't break anything:
Assistant
The test didn't run. Let me find the correct test name:
Assistant
The test is called
TestGetWorkloadslicingCustomAnnotations. Let me run it:Assistant
The existing tests pass. Now let me also check if there are any tests for RayJob or RayService that might be affected by this change:
Assistant
The RayJob tests pass. Let me also check the RayService tests:
Assistant
No tests for GetCustomAnnotations in Rayservice. Let me run all the tests for raycluster, rayjob, and rayservice to make sure nothing is broken:
Assistant
All tests pass for raycluster. Now let me run the full test suite for rayjob and rayservice:
Assistant
All tests pass. Now let me also run the tests for rayservice:
Assistant
All tests pass. Now let me verify the fix by looking at the modified code:
<tool_call> <function=bash_terminal> <parameter=command> cat /kueue/pkg/controller/jobs/raycluster/common.go | head -380 | tail -35 </tool_call>
Assistant
Let me verify the fix by looking at the modified code.
Assistant
The fix is in place. Let me verify the entire function to make sure it's correct:
Assistant
The fix is in place. Let me check the test file to understand the existing test cases and if I should add a test case for the standalone RayCluster scenario.
Assistant
Let me continue reading the test function to understand the test structure:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '1200,1250p' /kueue/pkg/controller/jobs/raycluster/common_test.go </tool_call>
Assistant
Let me continue reading the test function to understand the test structure.
Assistant
Now I understand the test structure. The test uses a ConfigMap as a wrapper object. To add a test case for the standalone RayCluster scenario, I need to add a test case where
jobObject.GetName() == rayClusterName.However, since the existing tests pass, I should also add a test case to verify that the fix works correctly. Let me add a test case for the standalone RayCluster scenario.
Actually, looking at the issue description again, the fix should prevent the self-patching loop by returning nil when the job object is the same as the RayCluster. The existing tests don't cover this case, so I should add a test case.
Assistant
The test case was added. Let me verify the change and run the tests to make sure everything works correctly.
Assistant
The command returned exit code 1, which might mean grep didn't find the text. Let me check if the test case was added correctly.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "standalone" /kueue/pkg/controller/jobs/raycluster/common_test.go </tool_call>
Assistant
Let me run the grep command without the -n option to see if the text was added.
Assistant
The grep command returned exit code 1, which means the text was not found. Let me check the end of the test cases to see if the test case was added correctly.
Assistant
Let me check the test cases definition more carefully to see if the test case was added.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '1100,1185p' /kueue/pkg/controller/jobs/raycluster/common_test.go </tool_call>
Assistant
Let me check the test cases definition to see if the test case was added.
Assistant
The test case was not added. The old_text string in the Python script might not have matched exactly. Let me check what the exact text is at the end of the test cases and add the test case correctly.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '1173,1185p' /kueue/pkg/controller/jobs/raycluster/common_test.go </tool_call>
Assistant
Let me check what's at lines 1173-1185 to see the exact text that I need to replace.
Assistant
I see the exact text now. The old_text in my Python script didn't match exactly because of the trailing whitespace or newline. Let me fix the Python script to use the correct text:
<tool_call> <function=bash_terminal> <parameter=command> python3 -c " with open('/kueue/pkg/controller/jobs/raycluster/common_test.go', 'r') as f: content = f.read()
Find the location to insert the new test case
old_text = ''' "other get error returns error": { annotations: map[string]string{ workloadslicing.EnabledAnnotationKey: workloadslicing.EnabledAnnotationValue, }, podSets: []kueue.PodSet{ {Name: "head", Count: 1}, }, rayClusterName: "test-raycluster", wantErr: true, }, }'''
Assistant
Let me verify if the test case was added successfully by running the tests.
Assistant
The test didn't pick up the new test case because the Python script didn't add it. Let me manually add the test case using a different approach.
<tool_call> <function=bash_terminal> <parameter=command> cat /kueue/pkg/controller/jobs/raycluster/common_test.go | grep -c "other get error returns error" </tool_call>
Assistant
The grep command returned 0, which means the test case was not added. Let me check the exact content of the file around the test cases to see what the actual text is.
Let me try a different approach - I'll read the file, find the exact string, and print it to understand what's happening.
Assistant
The test case is there. Let me check if my Python script failed to add the new test case because of string mismatch. Let me manually check what the test cases look like and add the test case using sed.
First, let me find the exact line number where the test cases end:
Assistant
Let me check what's around line 1178 (the closing brace of the test cases):
Assistant
I can see that the test cases end at line 1180 with
}and the next line is an empty line. Let me add the new test case before line 1180.Assistant
Let me verify that the test case was added correctly:
Assistant
The test case was added. Now let me run the tests to make sure everything works correctly:
Assistant
The new test case passes. Now let me run all the tests for raycluster, rayjob, and rayservice to make sure nothing is broken:
Assistant
All tests pass. Now let me also verify that the fix is complete by reviewing the changes:
Assistant
The changes look correct. Let me now verify the fix by running the complete test suite for the affected packages:
<tool_call> <function=bash_terminal> <parameter=command> export XDG_CACHE_HOME=/tmp/cache && cd /kueue && go test ./pkg/controller/jobs/raycluster/... ./pkg/controller/jobs/rayjob/... ./pkg/controller/jobs/rayservice/... 2>&1 | tail -10 </tool_call>
Assistant
Let me run the test command properly to verify the fix.
Assistant
All tests pass. Let me also verify that the code compiles correctly and check if there are any linting issues.
<tool_call> <function=bash_terminal> <parameter=command> export XDG_CACHE_HOME=/tmp/cache && cd /kueue && go build ./pkg/controller/jobs/raycluster/... ./pkg/controller/jobs/rayjob/... ./pkg/controller/jobs/rayservice/... </tool_call>
Assistant
Let me run the build command properly.
Assistant
The code compiles successfully. Now let me summarize the changes I made:
Summary of Changes
The issue was that standalone Kueue-managed elastic RayClusters were being continuously updated by Kueue with the
kueue.x-k8s.io/raycluster-generationannotation. This caused a self-patching loop because:- The
GetWorkloadslicingRayClusterCustomAnnotationsfunction fetches the RayCluster and returns its generation as an annotation - Writing this annotation back to the RayCluster patches it, advancing its
metadata.generation - This makes the annotation stale again
- The loop continues indefinitely
Fix
I modified the
GetWorkloadslicingRayClusterCustomAnnotationsfunction in to check if the is the same as the RayCluster. If so, the function returns to avoid adding the annotation and triggering the self-patching loop.- The
Assistant
The changes look complete. Let me now 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.