Skip to content

fix(role-instance): fix update role instance status conflict#220

Merged
cheyang merged 6 commits intosgl-project:mainfrom
Syspretor:fix/update-conflict
Mar 18, 2026
Merged

fix(role-instance): fix update role instance status conflict#220
cheyang merged 6 commits intosgl-project:mainfrom
Syspretor:fix/update-conflict

Conversation

@Syspretor
Copy link
Copy Markdown
Collaborator

Ⅰ. Motivation

Ⅱ. Modifications

Ⅲ. Does this pull request fix one issue?

fixes #XXXX

Ⅳ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Ⅴ. Describe how to verify it

VI. Special notes for reviews

Checklist

  • Format your code make fmt.
  • Add unit tests or integration tests.
  • Update the documentation related to the change.

@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to eliminate RoleInstance status update conflicts by switching the status update to a RetryOnConflict pattern that re-GETs the latest object before updating the status subresource.

Changes:

  • Add retry.RetryOnConflict around RoleInstance status updates.
  • Re-fetch the RoleInstance (Get by namespace/name) before calling Status().Update.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/reconciler/roleinstance/instance_status.go
Comment thread pkg/reconciler/roleinstance/instance_status.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to address conflicts when updating RoleInstance / RoleInstanceSet status by changing how status writes are performed during reconciliation.

Changes:

  • Add RetryOnConflict + re-Get before updating RoleInstance status to reduce update conflicts.
  • Switch RoleInstanceSet status update from Status().Patch(MergeFrom(...)) to Status().Update(...) within an existing RetryOnConflict loop.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/reconciler/roleinstanceset/statelessmode/status.go Changes status write to Status().Update inside the existing conflict-retry loop.
pkg/reconciler/roleinstance/instance_status.go Wraps RoleInstance status updates in RetryOnConflict and refreshes object before updating.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/reconciler/roleinstance/instance_status.go
Comment thread pkg/reconciler/roleinstance/instance_status.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to reduce/update conflicts when writing RoleInstance / RoleInstanceSet status, in the presence of concurrent status writers (e.g., readiness/inplace controllers).

Changes:

  • Switched RoleInstanceSet stateless-mode status writes from Status().Patch(MergeFrom(...)) to Status().Update(...) inside a conflict-retry loop.
  • Updated RoleInstance status writes to use RetryOnConflict with a fresh GET, and attempted to preserve externally-owned conditions during status updates.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/reconciler/roleinstanceset/statelessmode/status.go Changes stateless RoleInstanceSet status persistence from Patch to Update (still retried on conflict).
pkg/reconciler/roleinstance/instance_status.go Adds retry-on-conflict status updates and condition “merge” logic intended to prevent overwriting concurrent condition updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/reconciler/roleinstance/instance_status.go
Comment thread pkg/reconciler/roleinstance/instance_status.go Outdated
Copy link
Copy Markdown
Collaborator

@cheyang cheyang left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to address status update conflicts for RoleInstance / RoleInstanceSet reconciliation by changing how status updates are performed, including retry-on-conflict behavior and preserving concurrently-written status conditions.

Changes:

  • Switch RoleInstanceSet (stateless mode) status update to Status().Update() within a RetryOnConflict loop.
  • Add RetryOnConflict + live-object refetch for RoleInstance status updates, attempting to preserve externally-owned conditions.
  • Introduce a helper to define which RoleInstance condition types are controller-owned vs externally-owned.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/reconciler/roleinstanceset/statelessmode/status.go Changes RoleInstanceSet status write path to use Status().Update() after a fresh GET in conflict retries.
pkg/reconciler/roleinstance/instance_status.go Adds conflict-retry status updates for RoleInstance and attempts to preserve externally-written conditions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/reconciler/roleinstance/instance_status.go Outdated
Comment thread pkg/reconciler/roleinstance/instance_status.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to address RoleInstance status update conflicts caused by concurrent writers by changing how status updates are performed (retrying on conflicts and attempting to preserve externally-owned conditions).

Changes:

  • Update RoleInstanceSet (stateless mode) status update logic to use Status().Update() after a fresh GET within RetryOnConflict.
  • Add conflict-retry logic to RoleInstance status updates and attempt to preserve externally-owned status conditions across updates.
  • Introduce an explicit “controller-owned condition types” set to decide which conditions should/shouldn’t be preserved.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
pkg/reconciler/roleinstanceset/statelessmode/status.go Switches RoleInstanceSet status write path to Status().Update() inside a retry loop.
pkg/reconciler/roleinstance/instance_status.go Adds retry-on-conflict status updates and logic intended to preserve externally-owned conditions during status writes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/reconciler/roleinstance/instance_status.go
Comment thread pkg/reconciler/roleinstance/instance_status.go Outdated
Comment thread pkg/reconciler/roleinstance/instance_status.go
Comment thread pkg/reconciler/roleinstance/instance_status.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to reduce/update-conflict errors when updating RoleInstance / RoleInstanceSet status by switching to conflict-retry update patterns and attempting to preserve concurrently-written status conditions.

Changes:

  • RoleInstanceSet (stateless mode): switch status write to Status().Update() inside RetryOnConflict.
  • RoleInstance: add RetryOnConflict status update flow that refetches the live object and attempts to carry forward externally-owned conditions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/reconciler/roleinstanceset/statelessmode/status.go Updates RoleInstanceSet status using refetch + RetryOnConflict + Status().Update().
pkg/reconciler/roleinstance/instance_status.go Adds conflict-retry status update and condition “ownership” logic to avoid clobbering concurrent condition writers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/reconciler/roleinstance/instance_status.go
Comment thread pkg/reconciler/roleinstance/instance_status.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to address RoleInstance / RoleInstanceSet status update conflicts by adjusting how status updates are performed under concurrent writers (Kubernetes resourceVersion conflicts and concurrent status condition updates).

Changes:

  • Switch RoleInstanceSet (stateless mode) status updates to use Status().Update() (still under RetryOnConflict).
  • Add RetryOnConflict to RoleInstance status updates and attempt to preserve “externally-owned” status conditions during updates.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
pkg/reconciler/roleinstanceset/statelessmode/status.go Changes status update strategy for RoleInstanceSet to use Status().Update() within a conflict-retry loop.
pkg/reconciler/roleinstance/instance_status.go Introduces conflict-retry for RoleInstance status updates and condition merging logic intended to avoid clobbering concurrent condition writers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return nil
}
return err
}
Comment on lines +64 to +83
// The rule for inclusion is:
// - Controller-computed types (Ready, AllPodsReady, FailedScale, FailedUpdate) are
// always generated fresh each reconcile and must win over the live object.
// - RoleInstanceInPlaceUpdateReady and RoleInstanceCustomReady are written by
// external controllers, but setInstanceConditions always copies them from
// instance.Status into newStatus (via getInstanceInplaceUpdateReadyCondition and
// the custom-condition passthrough). They are therefore already present in
// newStatus.Conditions, so they must be listed here to prevent a duplicate entry
// being appended from the live clone.
func controllerOwnedConditionTypes() sets.Set[workloadsv1alpha2.RoleInstanceConditionType] {
return sets.New[workloadsv1alpha2.RoleInstanceConditionType](
// Computed by this controller on every reconcile.
workloadsv1alpha2.RoleInstanceReady,
workloadsv1alpha2.RoleInstanceAllPodsReady,
workloadsv1alpha2.RoleInstanceFailedScale,
workloadsv1alpha2.RoleInstanceFailedUpdate,
// Written externally but always copied into newStatus by setInstanceConditions,
// so they are already present and must not be appended again from the live clone.
workloadsv1alpha2.RoleInstanceInPlaceUpdateReady,
workloadsv1alpha2.RoleInstanceCustomReady,
Comment on lines +67 to +84
// - RoleInstanceInPlaceUpdateReady and RoleInstanceCustomReady are written by
// external controllers, but setInstanceConditions always copies them from
// instance.Status into newStatus (via getInstanceInplaceUpdateReadyCondition and
// the custom-condition passthrough). They are therefore already present in
// newStatus.Conditions, so they must be listed here to prevent a duplicate entry
// being appended from the live clone.
func controllerOwnedConditionTypes() sets.Set[workloadsv1alpha2.RoleInstanceConditionType] {
return sets.New[workloadsv1alpha2.RoleInstanceConditionType](
// Computed by this controller on every reconcile.
workloadsv1alpha2.RoleInstanceReady,
workloadsv1alpha2.RoleInstanceAllPodsReady,
workloadsv1alpha2.RoleInstanceFailedScale,
workloadsv1alpha2.RoleInstanceFailedUpdate,
// Written externally but always copied into newStatus by setInstanceConditions,
// so they are already present and must not be appended again from the live clone.
workloadsv1alpha2.RoleInstanceInPlaceUpdateReady,
workloadsv1alpha2.RoleInstanceCustomReady,
)
Comment on lines +344 to +345
clone.Status = *newStatus
clone.Status.Conditions = append(clone.Status.Conditions, liveCustomConditions...)
Copy link
Copy Markdown
Collaborator

@cheyang cheyang left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@cheyang cheyang merged commit 91bfb7e into sgl-project:main Mar 18, 2026
12 checks passed
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.

3 participants