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 and finding the relevant code mentioned in the issue.
Assistant
Let me explore the repository structure and find the relevant code.
Assistant
Now let me look at how
GetCustomAnnotationsis used in the RayCluster controller and the RayJob/RayService controllers.Assistant
Now let me look at how RayCluster implements GetCustomAnnotations. It's not in the grep output for the raycluster directory, so let me search.
Assistant
Let me look at where
GetCustomAnnotationsis defined in the jobframework and where the RayCluster controller calls it.Assistant
Now let me look at the RayCluster controller to find where it implements
GetCustomAnnotations.Assistant
The RayCluster controller doesn't implement
GetCustomAnnotations. Let me check the git branch and version.Assistant
This is the main branch (HEAD at 4cc62da8e). The issue is about v0.16.5, but the fix should be applied to the main branch. Let me look at the
GetWorkloadslicingRayClusterCustomAnnotationsfunction and understand the issue.The issue is that when the
jobObjectis a standalone RayCluster,GetWorkloadslicingRayClusterCustomAnnotationsfetches the same RayCluster (byrayClusterNamewhich equals the job object's name) and writes its generation back as an annotation. This causes a self-update loop.Assistant
Let me look at the existing tests for
GetWorkloadslicingRayClusterCustomAnnotations.Assistant
Let me look at how RayCluster implements the
JobWithCustomAnnotationsinterface and check the broader codebase.Assistant
Only RayJob and RayService implement
JobWithCustomAnnotationson the main branch. Let me check the release-0.16 branch to understand the actual code that has the bug.Assistant
Let me look at the full RayCluster controller file to understand its structure.
Assistant
Let me check where
GetWorkloadNameExtraPartis called and understand the full flow.Assistant
Let me look at the interface definitions in jobframework/interface.go.
Assistant
Let me check the git history to see if RayCluster ever implemented
GetCustomAnnotations.Assistant
Let me look at the diff of PR #9960 for the rayjob and rayservice controllers to understand the structure.
Assistant
Let me look at the e2e tests for standalone RayCluster elastic behavior to understand expected behavior.
Assistant
Now let me look at the full
GetWorkloadslicingRayClusterCustomAnnotationsfunction and implement the fix.Assistant
Let me check the raycluster controller tests for workload slicing / elastic standalone behavior.
Assistant
Let me check the shared
raypackage and look for any GetCustomAnnotations implementation for RayCluster.Assistant
Let me check where
UpdatePodSetsis called and how the standalone RayCluster elastic flow works.Assistant
Let me look at the
mergeAnnotationsfunction to understand when patches are applied.Assistant
Let me check the Kueue version and whether this is a release branch.
Assistant
Let me look at the raycluster webhook to understand the elastic standalone RayCluster support.
Assistant
I now have a clear understanding. The main branch supports standalone elastic RayClusters (via the webhook) but the
GetWorkloadslicingRayClusterCustomAnnotationsfunction has a latent bug: when thejobObjectis the standalone RayCluster itself (i.e.,rayClusterName == jobObject.GetName()and it's a*rayv1.RayCluster), it fetches the same RayCluster and writes its generation back as an annotation, causing a self-update loop.Let me implement the fix per the issue's explicit suggestion: omit the
raycluster-generationannotation when thejobObjectis the same standalone RayCluster asrayClusterName.Assistant
Now let me implement the fix:
Assistant
Now let me verify the build compiles:
Assistant
The build passes. Now, per the instructions, I should not add tests to the repository, but I'll create a temporary test script to verify my fix and remove it before submitting. Let me first look at the existing test's imports and helper to write a compatible temporary test.
Assistant
Let me check the
testingrayutil.MakeClusterhelper used in tests.Assistant
Now let me create a temporary test file to verify my fix:
Assistant
Let me check the
Annotationmethod exists on ClusterWrapper:Assistant
The method is
SetAnnotation, notAnnotation. Let me fix the temp test:Assistant
Let me view the temp test file to verify it's correct:
Assistant
The sed didn't work due to formatting. Let me fix it directly:
Assistant
The
.is at the end of the previous line. Let me fix it with a different approach:Assistant
Now let me run the temporary tests:
Assistant
Both tests pass. Now let me verify the existing tests still pass:
Assistant
All existing tests pass. Now let me run the full raycluster, rayjob, and rayservice test packages:
Assistant
All tests pass. Let me also run the jobframework tests since the reconciler calls
GetCustomAnnotations:Assistant
Let me build the broader controller packages to be safe:
Assistant
Let me run
go veton the changed package:Assistant
Now let me clean up the temporary test file:
Assistant
Let me verify the final state of my change:
Assistant
Let me run the full raycluster test suite once more (without the temp test) to confirm everything passes:
Assistant
Let me view the final state of the modified function to confirm correctness:
Assistant
Let me check the git history of the raycluster controller to understand if
GetCustomAnnotationswas ever present or recently changed:Assistant
Let me verify the PR #9960 commit is in the current history and check the most recent changes to common.go:
Assistant
My fix is complete and correct. Let me do a final review of the diff and run a broader set of tests to ensure nothing is broken:
Assistant
Let me also run the workloadslicing package tests:
Assistant
Let me verify the bug existed before my fix by re-creating the temp test, reverting my change, and confirming the test fails without the fix. First, re-create the temp test:
Assistant
The temp test has an unused import. Let me fix it:
Assistant
Now let me verify the bug exists without the fix (stash) and is resolved with the fix:
Assistant
The bug is confirmed: without the fix, the standalone RayCluster writes its own generation (
273390) back as an annotation (causing the self-update loop). Now let me confirm the fix resolves it:Assistant
The fix is confirmed working. Now let me clean up the temporary test file:
Assistant
The temp test file is removed. Let me do a final review of the diff and run the affected tests once more:
Assistant
Let me verify formatting with gofmt:
Assistant
Let me do a final check to ensure no temporary files remain and only the intended change is present:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.