Skip to content

fix(controller): prevent RestartInProgress condition loss due to stal… - #324

Merged
cheyang merged 1 commit into
sgl-project:mainfrom
Syspretor:fix/condition-missing
May 6, 2026
Merged

cheyang merged 1 commit into
sgl-project:mainfrom
Syspretor:fix/condition-missing

Conversation

@Syspretor

Copy link
Copy Markdown
Collaborator

…e cache race

When the PodReconciler triggers a restart (RecreateRBGOnPodRestart), the RestartInProgress condition was being permanently lost from the RBG status after the restart completed. This caused e2e test "standalone role with restartPolicy" to time out waiting for RestartInProgress=False.

Root cause: a read-modify-write race between two controllers sharing the same RBG status subresource.

  1. PodReconciler.setRestartCondition() used the caching client to read the
    RBG before Status().Update(). If the informer cache had not yet synced
    the RBG controller's latest status writes (Ready condition,
    RoleStatuses), the pod controller would overwrite those fields with
    stale data.

  2. RoleBasedGroupReconciler.updateRBGStatus() patches status via SSA with
    Force=true. It only checked the API reader for RestartInProgress. If
    the pod controller had not yet committed its write, the condition would
    be absent from the patch and SSA Force=true would remove it from API.

Fixes:

  • PodReconciler: add apiReader (non-caching) and use it in setRestartCondition to always read the authoritative API state before updating, avoiding informer cache staleness.
  • updateRBGStatus: check both the cached rbg AND the API reader for RestartInProgress (defense-in-depth), only falling back to the API reader when the cache does not have it.

Ancillary reconcile error "workload generation not equal to observed generation" is expected and self-resolving: after the pod controller deletes and recreates a Deployment, the Deployment controller needs time to update ObservedGeneration to match Generation.

Ⅰ. 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.

…e cache race

When the PodReconciler triggers a restart (RecreateRBGOnPodRestart), the
RestartInProgress condition was being permanently lost from the RBG status
after the restart completed. This caused e2e test "standalone role with
restartPolicy" to time out waiting for RestartInProgress=False.

Root cause: a read-modify-write race between two controllers sharing the
same RBG status subresource.

1) PodReconciler.setRestartCondition() used the caching client to read the
   RBG before Status().Update(). If the informer cache had not yet synced
   the RBG controller's latest status writes (Ready condition,
   RoleStatuses), the pod controller would overwrite those fields with
   stale data.

2) RoleBasedGroupReconciler.updateRBGStatus() patches status via SSA with
   Force=true. It only checked the API reader for RestartInProgress. If
   the pod controller had not yet committed its write, the condition would
   be absent from the patch and SSA Force=true would remove it from API.

Fixes:
- PodReconciler: add apiReader (non-caching) and use it in
  setRestartCondition to always read the authoritative API state before
  updating, avoiding informer cache staleness.
- updateRBGStatus: check both the cached rbg AND the API reader for
  RestartInProgress (defense-in-depth), only falling back to the API
  reader when the cache does not have it.

Ancillary reconcile error "workload generation not equal to observed
generation" is expected and self-resolving: after the pod controller
deletes and recreates a Deployment, the Deployment controller needs time
to update ObservedGeneration to match Generation.
@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!

@Syspretor
Syspretor requested review from cheyang and diw-zw May 6, 2026 06:47

@cheyang cheyang left a comment

Copy link
Copy Markdown
Collaborator

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 ea0730c into sgl-project:main May 6, 2026
9 of 10 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.

2 participants