Skip to content

🐛 Fix IndexField blocking until informer is synced#3445

Merged
k8s-ci-robot merged 2 commits into
kubernetes-sigs:mainfrom
gzb1128:fix-indexfield-no-block
Jan 31, 2026
Merged

🐛 Fix IndexField blocking until informer is synced#3445
k8s-ci-robot merged 2 commits into
kubernetes-sigs:mainfrom
gzb1128:fix-indexfield-no-block

Conversation

@gzb1128

@gzb1128 gzb1128 commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

What

IndexField() was blocking until the informer cache synced, causing unnecessary delays during controller startup.

Why

The issue occurs 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. Controllers already wait for their source informers to sync during startup via WaitForCacheSync.

Fixes

Fixes #3422

@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jan 30, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jan 30, 2026

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jan 30, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Welcome @gzb1128!

It looks like this is your first PR to kubernetes-sigs/controller-runtime 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-runtime has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 30, 2026
@gzb1128 gzb1128 force-pushed the fix-indexfield-no-block branch from 57484b0 to ec55b10 Compare January 30, 2026 13:33
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 30, 2026
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
@gzb1128 gzb1128 force-pushed the fix-indexfield-no-block branch from ec55b10 to 46c335d Compare January 30, 2026 13:34
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jan 30, 2026
@alvaroaleman

Copy link
Copy Markdown
Member

/ok-to-test

Please sign the CLA and please add a test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 30, 2026
@alvaroaleman

Copy link
Copy Markdown
Member

Please sign the CLA and please add a test

Sorry, you already have, the issue is that the PR title must be updated

@gzb1128 gzb1128 changed the title Fix IndexField blocking until informer is synced 🐛 Fix IndexField blocking until informer is synced Jan 30, 2026
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
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 30, 2026
@gzb1128

gzb1128 commented Jan 30, 2026

Copy link
Copy Markdown
Contributor Author

Hi @alvaroaleman, I've added a unit test to verify that IndexField returns immediately when called before the informer cache is synced.

The test:

  • Uses FakeInformer with Synced=false to simulate an unsynced informer
  • Uses a 100ms timeout context - if IndexField blocks waiting for sync, it will timeout
  • Follows the same pattern as TestReaderWaitsForCacheSync
  • Can be run locally without etcd

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.

@alvaroaleman alvaroaleman added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jan 31, 2026

@alvaroaleman alvaroaleman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 31, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: a4939d6d77c29b79390e459b703f3271ff8e4b70

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[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

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 31, 2026
@k8s-ci-robot k8s-ci-robot merged commit aba4afe into kubernetes-sigs:main Jan 31, 2026
12 checks passed
@sbueringer

Copy link
Copy Markdown
Member

Thx!

/lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexField() unintentionally blocks until informer is synced

4 participants