Skip to content

[ray-operator] Update RayCluster status on validation failure#4975

Open
yoonseo-han wants to merge 2 commits into
ray-project:masterfrom
yoonseo-han:fix/raycluster-validation-status
Open

[ray-operator] Update RayCluster status on validation failure#4975
yoonseo-han wants to merge 2 commits into
ray-project:masterfrom
yoonseo-han:fix/raycluster-validation-status

Conversation

@yoonseo-han

Copy link
Copy Markdown

Why are these changes needed?

When RayCluster metadata, spec, or upgrade strategy validation fails, the operator only logs an error and emits a Kubernetes Event, then returns early without updating .status.

As a result, status.observedGeneration can stay stale, and there is no condition indicating validation failed unlike RayJob and RayService

This change updates RayCluster status immediately on user input validation failure:
-> Sets observedGeneration, LastUpdateTime, and RayClusterProvisioned=False with reason=ValidationFailed, following the RayService pattern.

Related issue number

Closes #4974

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • This PR is not tested :(
Screenshot 2026-07-04 at 5 58 27 PM

Signed-off-by: Yoonseo Han <yooncer00@gmail.com>
Comment thread ray-operator/controllers/ray/raycluster_controller.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c0f5f586c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1571 to +1573
Type: string(rayv1.RayClusterProvisioned),
Status: metav1.ConditionFalse,
Reason: rayv1.RayClusterValidationFailed,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve RayClusterProvisioned once it is true

When an already-provisioned RayCluster is later edited to an invalid spec, this validation path unconditionally overwrites RayClusterProvisioned=True with False/ValidationFailed. That condition is documented and tested as sticky after the cluster becomes ready for the first time, so clients watching it will see a provisioned cluster regress simply because a new generation failed validation; consider preserving an existing true RayClusterProvisioned and reporting validation failure separately.

Useful? React with 👍 / 👎.

Comment on lines +1569 to +1570
if features.Enabled(features.RayClusterStatusConditions) {
meta.SetStatusCondition(&newInstance.Status.Conditions, metav1.Condition{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Persist validation status when conditions are disabled

When RayClusterStatusConditions is disabled, this block adds no condition, leaving ObservedGeneration and LastUpdateTime as the only status changes. updateRayClusterStatus intentionally ignores diffs that only touch those two fields, so invalid RayClusters in that supported feature-gate configuration still return without any status update and observedGeneration remains stale.

Useful? React with 👍 / 👎.


r := &RayClusterReconciler{
Client: fakeClient,
Recorder: &record.FakeRecorder{},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Initialize the fake recorder before emitting events

This new test path calls handleRayClusterValidationError, which records a Kubernetes event before updating status. A zero-value record.FakeRecorder has no Events channel, so Eventf blocks when it tries to send the event; use record.NewFakeRecorder(...) here (and in the analogous new reconcile test) so the validation tests can complete instead of hanging until the test timeout.

Useful? React with 👍 / 👎.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 6d36d2a. Configure here.

Comment thread ray-operator/controllers/ray/raycluster_controller.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d36d2a43c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1614 to +1619
meta.SetStatusCondition(&newInstance.Status.Conditions, metav1.Condition{
Type: string(rayv1.RayClusterValid),
Status: metav1.ConditionTrue,
Reason: rayv1.RayClusterSpecValid,
Message: "RayCluster metadata and spec are valid",
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mark Valid true despite reconciliation errors

If a user fixes a previously invalid RayCluster but this same reconcile later hits an operational error (for example while creating a Pod or Service), this block is skipped and the old Valid=False/ValidationFailed condition is preserved even though metadata/spec validation already passed. Consumers can continue to see the current valid generation as invalid until a later fully clean reconcile, so set the Valid condition based on validation success independently of reconcileErr.

Useful? React with 👍 / 👎.

@yoonseo-han
yoonseo-han force-pushed the fix/raycluster-validation-status branch from 6d36d2a to 01fad32 Compare July 5, 2026 00:20

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01fad32ba1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1603 to +1606
Type: string(rayv1.RayClusterValid),
Status: metav1.ConditionTrue,
Reason: rayv1.RayClusterSpecValid,
Message: "RayCluster metadata and spec are valid",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Set observedGeneration on the Valid condition

When a previously invalid RayCluster is corrected, this call replaces Valid=False with Valid=True but leaves the condition's ObservedGeneration at the zero value because the literal omits it. Consumers that follow condition generations cannot tell that the validation pass applies to the edited spec, unlike the validation-failure path above which sets the current generation; set it to newInstance.Generation when marking validation success.

Useful? React with 👍 / 👎.

Signed-off-by: Yoonseo Han <yooncer00@gmail.com>
@yoonseo-han
yoonseo-han force-pushed the fix/raycluster-validation-status branch from 01fad32 to 7e5b17e Compare July 5, 2026 00:36
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@yoonseo-han

Copy link
Copy Markdown
Author

Addressed feedback based on AI reveiw

  • Split validation status into a new RayClusterValid condition instead of overwriting RayClusterProvisioned so a previously-provisioned cluster no longer regresses to Provisioned=False when a later generation fails validation.
  • No status update when RayClusterStatusConditions gate is off
  • Valid=True only set when reconcileErr == nil → Reworked so validation success is reported independent of unrelated reconcile errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][RayCluster] Validation failure should update status, not only emit Events

1 participant