fix: register scale-up expectations before creating sandboxes#393
Open
oindrilakha12-ui wants to merge 1 commit into
Open
fix: register scale-up expectations before creating sandboxes#393oindrilakha12-ui wants to merge 1 commit into
oindrilakha12-ui wants to merge 1 commit into
Conversation
e459a0d to
f4d97de
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Moving ExpectScale before r.Create fixes a race condition where the creation event can be delivered to the informer before the expectation is registered. In such cases, the ObserveScale call in the event handler fails to find a matching expectation, leading the controller to believe a creation is still pending and blocking reconciliation for up to 30s. Also added ObserveScale in the error path of r.Create to ensure any registered expectations are cleared if creation fails. Updated unit tests to manually clear expectations between successive Reconcile calls, as the fake client does not trigger the event handlers that would normally satisfy expectations. Fixes openkruise#392
f4d97de to
1cefb71
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixed a critical race condition in the
SandboxSetcontroller whereExpectScalewas called afterr.Create.Why
Under high load or high QPS, the Kubernetes API server can deliver the
Createevent to the controller's informer faster than the controller can execute the next line of code. Ifr.Createsucceeds but theCreateevent is processed beforeExpectScaleis called:ObserveScale(in the event handler) finds no registered expectation for that sandbox and is a no-op.ExpectScaleis then called, registering an expectation that will never be satisfied by an event (since the event already passed).SatisfiesExpectationscheck then blocks any further reconciliation for thatSandboxSetuntil the expectation times out (default 30 seconds).This results in severe "stalls" in warm pool replenishment.
Changes
scaleUpExpectation.ExpectScalebefore ther.Createcall.ObserveScalein ther.Createerror path to ensure failed creations don't leave orphaned expectations.TestReconcile_BasicScaleto manually clear expectations between reconcile calls. This is necessary because the fake test client doesn't trigger the watch events that would normally clear expectations in a real cluster.Testing
go test ./pkg/controller/sandboxset/...✅ (All tests pass with the expectation cleanup).Fixes #392