Skip to content

fix(sandboxcr): bind Sandbox mutations to the authorized incarnation - #823

Open
AnshulPatil2005 wants to merge 1 commit into
openkruise:masterfrom
AnshulPatil2005:fix/sandbox-incarnation-delete
Open

AnshulPatil2005 wants to merge 1 commit into
openkruise:masterfrom
AnshulPatil2005:fix/sandbox-incarnation-delete

Conversation

@AnshulPatil2005

Copy link
Copy Markdown

I. Describe what this PR does

Covers the direct Sandbox writes from #792, not the whole issue.

InplaceRefresh and retryUpdate both re-read by ObjectKey and adopt whatever comes back, and deleteSandbox was a bare client.Delete. So once a same-name Sandbox exists, an operation authorized against the old one can refresh onto the new one, update it, or delete it.

Both re-reads now reject an object whose UID differs from the one the caller holds, and the delete sends the UID as a precondition so the API server cannot resolve the name onto a replacement.

A mismatch surfaces as NotFound. From the caller's side the Sandbox it was authorized for really is gone, and the API layer already maps not-found to 404, so nothing new is needed there to stop the operation.

An object with no UID was never read from the API server, so there is nothing to compare against and the check is skipped. That keeps synthetic wrappers working rather than failing them closed on a comparison that cannot be made.

II. Does this pull request fix one issue?

Refs #792. Direct Sandbox writes only.

III. Describe how to verify it

go test ./pkg/sandbox-manager/infra/sandboxcr/ -run TestSandbox_IncarnationBinding -count=1

The table covers same UID, a replacement UID, and both synthetic cases. The delete case reads the applied DeleteOptions through an interceptor and asserts the precondition is present with a real UID and absent without one.

IV. Special notes for reviews

Deliberately partial, and I would rather check the scope than guess at it. Snapshot and TrafficPolicy are the derived-resource half of the issue and they need a different shape of fix: binding the Pod incarnation, not just the Sandbox. If you would prefer this landed as one change covering all of it, say so and I will fold them in rather than split it.

The other thing worth a second opinion is NotFound as the mismatch error. It composes with the existing client.IgnoreNotFound call sites, which is the reason I picked it, but that also means any caller already swallowing not-found will swallow this too. If you would rather it were a distinct typed error that cannot be ignored by accident, that is an easy change.

TestInfra_ClaimSandbox, TestCloneSandbox_WithRateLimiter and TestCloneSandbox_TrafficAccessToken fail for me on a clean master as well, and the failing TestInfra_ClaimSandbox subtest changes between runs, so they look flaky rather than related.

@kruise-bot
kruise-bot requested review from AiRanthem and zmberg August 14, 2026 10:56
@kruise-bot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign airanthem for approval by writing /assign @airanthem in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.08%. Comparing base (1781b7c) to head (d0da0d2).

Files with missing lines Patch % Lines
pkg/sandbox-manager/infra/sandboxcr/sandbox.go 73.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #823   +/-   ##
=======================================
  Coverage   83.08%   83.08%           
=======================================
  Files         259      259           
  Lines       22555    22568   +13     
=======================================
+ Hits        18739    18750   +11     
- Misses       3093     3094    +1     
- Partials      723      724    +1     
Flag Coverage Δ
unittests 83.08% <73.33%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AnshulPatil2005
AnshulPatil2005 force-pushed the fix/sandbox-incarnation-delete branch from 606b9e6 to 23d987a Compare September 4, 2026 04:27
Authorization resolves one specific Sandbox, but the re-reads and the delete
below resolve by namespace and name only. A Sandbox recreated under the same
name in that window is adopted and mutated in place of the one the caller was
authorized for. An ordinary informer propagation delay is enough.

InplaceRefresh and retryUpdate now reject a re-read whose UID differs from the
object the caller holds, and deleteSandbox sends the UID as a delete
precondition so the API server cannot resolve the name onto a replacement.

A mismatch surfaces as NotFound: the Sandbox the caller was authorized for is
gone, which is what the API layer should report rather than acting on its
successor. An object with no UID was never read from the API server, so there
is nothing to compare and the check is skipped.

This covers the direct Sandbox writes in openkruise#792. The derived-resource
boundaries, Snapshot and TrafficPolicy, are untouched.

Refs openkruise#792

Signed-off-by: Anshul <anshulpatil1022@gmail.com>
@AnshulPatil2005
AnshulPatil2005 force-pushed the fix/sandbox-incarnation-delete branch from 23d987a to d0da0d2 Compare September 5, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants