Repository navigation
Conversation
SharedInformer gives no way to tell whether the initial list has been applied to the cache. A controller that starts its workers right after start() can therefore read an empty cache and conclude that objects do not exist; callers have to set a flag in a handler or sleep. Add two methods: * has_synced() returns True once the objects of a full list are in the cache and the ADDED/MODIFIED/DELETED handlers for that list have returned. It stays True afterwards, through re-lists, watch failures and stop()/start(), since the cache is kept across a restart. * wait_for_sync(timeout=None) blocks on a Condition until the informer is synced (True), the timeout passes (False) or the informer is stopped (False). On a stopped informer it returns has_synced() at once. It must not be called from an event handler, which runs on the informer thread. The e2e helper that polled the private _resource_version now uses wait_for_sync(), and the informer example waits for the initial list. Unit tests cover the state before and after the initial list, a list that keeps failing, stop() releasing a wait, and the state surviving a 410 with a failed re-list and a restart.
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ilcm96 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 |
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 type of PR is this?
/kind feature
What this PR does / why we need it:
SharedInformer.start()returns before the initial list is applied, and there is no way to tell when the cache is ready. A controller that starts its workers right away can read an empty cache and act as if objects do not exist; today callers set a flag in a handler or sleep.This adds two methods:
has_synced()returnsTrueonce a full list is in the cache and its ADDED/MODIFIED/DELETED handlers have returned. It staysTruethrough re-lists, watch failures andstop()/start()(the cache is kept across a restart).wait_for_sync(timeout=None)blocks until synced (True), until the timeout passes, or until the informer is stopped (False). It waits without polling and must not be called from an event handler.The e2e helper that polled the private
_resource_versionnow useswait_for_sync(), and the informer example waits for the initial list.Which issue(s) this PR fixes:
None.
Special notes for your reviewer:
Tested with new unit tests (state before/after the initial list, a list that keeps failing,
stop()releasing a wait, 410 with a failed re-list, restart) and on kind: with 50 ConfigMaps,wait_for_sync()returned True with all 50 in the cache and their ADDED handlers run; on a list that kept failing (404),wait_for_sync(timeout=3)returned False;stop()released a waiting call with False. Informer and watch e2e tests: 7 passed.Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: