🐛 Fix IndexField blocking until informer is synced#3445
Conversation
|
Welcome @gzb1128! |
|
Hi @gzb1128. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
57484b0 to
ec55b10
Compare
IndexField() was blocking until the informer cache synced, causing unnecessary delays during controller startup. This happens because GetInformer() defaults to blockUntilSync=true. However, adding an index doesn't require the informer to be synced - the underlying client-go threadSafeStore.AddIndexers doesn't depend on sync state. Only List operations with field selectors need the cache to be synced. Relates to kubernetes-sigs#3422
ec55b10 to
46c335d
Compare
|
/ok-to-test Please sign the CLA and please add a test |
Sorry, you already have, the issue is that the PR title must be updated |
This test verifies that IndexField returns immediately when called before the informer cache is synced, using BlockUntilSynced(false). The test uses FakeInformer with Synced=false and a 100ms timeout context. If IndexField blocks waiting for sync, it will timeout with a clear error message. Relates to kubernetes-sigs#3422
|
Hi @alvaroaleman, I've added a unit test to verify that IndexField returns immediately when called before the informer cache is synced. The test:
I've verified that removing the fix (using BlockUntilSynced(false)) causes the test to fail with a clear timeout error, confirming the test correctly validates the non-blocking behavior. |
|
LGTM label has been added. DetailsGit tree hash: a4939d6d77c29b79390e459b703f3271ff8e4b70 |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, gzb1128 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Thx! /lgtm |
What
IndexField()was blocking until the informer cache synced, causing unnecessary delays during controller startup.Why
The issue occurs because
GetInformer()defaults toblockUntilSync=true. However, adding an index doesn't require the informer to be synced - the underlyingclient-go threadSafeStore.AddIndexersdoesn't depend on sync state.Only
Listoperations with field selectors need the cache to be synced. Controllers already wait for their source informers to sync during startup viaWaitForCacheSync.Fixes
Fixes #3422