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 exploring the repository structure to understand the codebase.
Assistant
Let me explore the key files related to the issue.
Assistant
Now let me look at the reconciler where
GetCustomAnnotationsis called:Assistant
Now let me see the interface and find related calls:
Assistant
Let me look at the RayCluster controller code to see the GetCustomAnnotations implementation:
Assistant
Let me look at the whole raycluster_controller.go:
Assistant
Let me check the git log and see if there's any commit related to this:
Assistant
Let me check the current branch:
Assistant
Let me search for any related PR:
Assistant
Let me look at the upstream PR #10160 referenced in the issue. Let me check the GitHub PRs:
Assistant
Let me understand the issue better - the issue mentions
GetCustomAnnotationsis being called for a standalone RayCluster, but it's not in the current code. Let me look at the diffs related to GetCustomAnnotations in the rayservice and rayjob to see if this is being called for the standalone RayCluster too:Assistant
Let me check the release branches:
Assistant
Let me look at PR #10160 in the git log to see if it has been merged:
Assistant
Let me look at the recent ray-cluster test files to see if GetCustomAnnotations is added in tests:
Assistant
Let me look at the common_test.go to see the test setup:
Assistant
Now let me look at the current
RayClustercontroller to understand if we should add aGetCustomAnnotationsto it. The issue says the bug exists in the current state, so I think:- Either the issue description is correct that there's a
GetCustomAnnotationsfor RayCluster that needs to be added - Or the fix is in
GetWorkloadslicingRayClusterCustomAnnotationsonly
Let me check if there's a missing method in RayCluster that should call
GetWorkloadslicingRayClusterCustomAnnotations. Looking at the existing test for RayCluster:- Either the issue description is correct that there's a
Assistant
Now let me understand the issue clearly. The issue is about a self-triggering loop where:
GetCustomAnnotationsis called for a standalone RayClusterGetWorkloadslicingRayClusterCustomAnnotationsfetches the RayCluster and writes its generation back to itself- The patch advances the generation, making the annotation stale
- The reconciler triggers again, repeating the cycle
The fix is to not write the
kueue.x-k8s.io/raycluster-generationannotation when thejobObjectis the same standalone RayCluster asrayClusterName. Let me first reproduce the issue, then apply the fix:Assistant
Let me first create a script to reproduce the issue:
Assistant
Hmm, the annotations came back as empty. Let me check why. The reason is that
workloadslicing.Enabledchecks for the annotation, but I need to also check how theEnabledfunction works.Assistant
The annotation key is
kueue.x-k8s.io/elastic-job. Let me fix my reproduce script:Assistant
I've successfully reproduced the issue. The annotation
kueue.x-k8s.io/raycluster-generation:5is being written for a standalone RayCluster with generation 5. Now let me apply the fix as described in the issue:Assistant
Now let me apply the fix:
Assistant
Let me navigate to that line first.
Assistant
Now I can see the function. Let me apply the fix:
Assistant
Now let me verify the fix by running the reproduce script:
Assistant
The fix is working. The annotation
kueue.x-k8s.io/raycluster-generationis no longer written for a standalone RayCluster, but thekueue.x-k8s.io/raycluster-podset-replica-sizesannotation is still written.Now let me also test the case for a RayJob (where the jobObject is NOT the same as the rayClusterName):
Assistant
The fix is working correctly. Now let me run the existing tests to make sure my fix doesn't break anything:
Assistant
I see the test is failing because when the RayCluster is not found, the original behavior was to include an empty generation annotation. My fix changed that behavior for the "rayCluster not found" case, but it shouldn't because
jobObject.GetName() != rayClusterNamein that test case. Let me preserve the original behavior:Assistant
Wait, the test "raycluster_not_found_returns_annotations_with_empty_generation" has the jobObject as "test-object" and rayClusterName as "nonexistent-raycluster", which are different. So this test should pass with my fix now. Let me verify:
Assistant
All existing tests pass. Now let me run the reproduce script again to verify the fix:
Assistant
Now let me check if the RayCluster needs to have a
GetCustomAnnotationsmethod:Assistant
Let me search more carefully to see if there's a GetCustomAnnotations for RayCluster somewhere:
Assistant
Looking at this, I see that the RayCluster doesn't currently have a
GetCustomAnnotationsmethod. The issue description suggests that for standalone RayClusters, this method is being called. Let me check whether the RayCluster needs to be updated to implement theJobWithCustomAnnotationsinterface, and if so, also add the fix there:Assistant
Let me search the entire repository for
GetCustomAnnotationscalls:Assistant
Now let me also add a test case to the existing test to verify the fix:
Assistant
Let me look at the full test file to understand the test structure:
Assistant
Let me look at the current state of the fix:
Assistant
Let me run all the tests to make sure everything is working:
Assistant
Let me run the wider tests:
Assistant
All tests pass. Let me also verify the fix works correctly with the original reproduce script:
Assistant
The fix is working. Now let me also check the diff to see my changes:
Assistant
Let me also run a broader set of tests to make sure my fix doesn't break anything:
Assistant
All tests pass. Now let me also check if the fix would address the issue if the RayCluster were to have a
GetCustomAnnotationsmethod. Let me look at the issue more carefully and see if I need to addGetCustomAnnotationsto the RayCluster:Assistant
Let me check if there are any other tests that might be affected:
Assistant
The e2e and integration tests fail because they need a Kubernetes environment. The unit tests pass. Let me check the package tests for ray cluster:
Assistant
All existing tests pass. Let me also check the
TestGetCustomAnnotationstest for RayJob:Assistant
All tests pass. Let me also verify by looking at the full test output:
Assistant
Let me also check if
GetWorkloadslicingRayClusterCustomAnnotationsis called from anywhere else:Assistant
The function is only called from RayJob and RayService. My fix is appropriate as it ensures the function will work correctly if the RayCluster is later updated to implement
JobWithCustomAnnotations.Let me verify the final state of the fix:
Assistant
Let me clean up the reproduce scripts:
Assistant
Let me check if the issue suggests adding
GetCustomAnnotationsto the RayCluster:Assistant
Let me check the PR that added PR #10160 to see if it also adds
GetCustomAnnotationsto the RayCluster:Assistant
Let me look at the commit details to see if there's a more recent PR that adds
GetCustomAnnotationsto the RayCluster:Assistant
Let me check if there's a release-0.16 branch with this code:
Assistant
Let me check the RayCluster controller more carefully:
Assistant
Let me check the v0.16.5 version of the RayCluster controller:
Assistant
Let me check the e2e tests for the standalone RayCluster:
Assistant
No tests in test/ directly use these functions. Good.
Let me also check the e2e tests for the standalone RayCluster:
Assistant
Let me look at this e2e test:
Assistant
Let me look at the e2e test for standalone RayCluster with elastic-job annotation:
Assistant
This is a RayJob test with autoscaling, not a standalone RayCluster. So the bug isn't currently being tested.
Let me also check the test for the raycluster to see how it's used:
Assistant
Let me check the RayCluster controller tests to see if they expect
GetCustomAnnotationsto be called:Assistant
Let me look at the final state of the fix:
Assistant
Let me run the full test suite for the relevant packages:
Assistant
All tests pass. Now let me also write a small script to verify the fix in detail with various scenarios:
Assistant
All test cases pass. Let me clean up the test file:
Assistant
Now let me also think about whether to add
GetCustomAnnotationsto the RayCluster. Looking at the issue once more:Assistant
Let me check the v0.16.5 release to see if the RayCluster has
GetCustomAnnotations:Assistant
The issue is forward-looking - the bug doesn't currently exist in v0.16.5 or master because the RayCluster doesn't have a
GetCustomAnnotationsmethod. However, the fix inGetWorkloadslicingRayClusterCustomAnnotationsis correct and will prevent the bug if/when the RayCluster is updated to implementJobWithCustomAnnotations.Let me do a final review of the fix:
Assistant
The fix is clean and minimal. Let me also verify the build passes:
Assistant
Now let me also run all the tests one more time to ensure nothing else is broken:
Assistant
All tests pass. Now let me also do a final check by looking at the diff:
Assistant
The fix is complete. Let me provide a summary of what I did:
Summary
Issue: 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. This is a self-triggered loop in the RayCluster custom annotation path.Root Cause: When
GetCustomAnnotationsis called for a standalone RayCluster, it callsGetWorkloadslicingRayClusterCustomAnnotations(ctx, c, j.Object(), podSets, j.Name). This 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, which triggers another reconcile.Assistant
Now let me go through the checklist one more time to ensure I've done everything:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.