Skip to content

Count the SharedInformer resync period from the last list - #2822

Open
ilcm96 wants to merge 1 commit into
kubernetes-client:masterfrom
ilcm96:informer-resync-timer
Open

ilcm96 wants to merge 1 commit into
kubernetes-client:masterfrom
ilcm96:informer-resync-timer

Conversation

@ilcm96

@ilcm96 ilcm96 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

SharedInformer restarts its resync timer whenever it reopens the watch, so a watch that keeps closing early postpones the resync forever.

This happens behind a proxy or load balancer whose idle timeout is shorter than the gaps on a quiet watch: even with bookmarks, the API server sends one only about every 60s (and ~2s before timeout_seconds). On kind behind an nginx TCP proxy, proxy_timeout 35s (the HAProxy timeout in the kubeadm HA guide) with resync_period=60 made only the initial list in 130s. With proxy_timeout 60s, the watch closed at ~60s or ~120s and resync_period=180 never resynced.

Fractional periods are probably rare, but they hit the same bug: timeout_seconds=int(1.5) ends every watch after 1s, before the resync is due.

This PR counts the resync deadline from the last list, so reconnects no longer restart it, and sets timeout_seconds to the time left, rounded up.

Which issue(s) this PR fixes:

None filed. The #2515 review asked whether the resync runs if the stream never ends; timeout_seconds covers only integer periods.

Special notes for your reviewer:

A fractional period is rounded up (1.5s resyncs every ~2s). Idle timeouts well above 60s are not affected, because bookmarks keep the watch open.

How I tested it:

  • New fake-clock unit tests; early-close and fractional cases fail without this change.
  • kind: behind 5s, 35s and 60s idle proxies, the resync ran every 10s, 60s and 180s as configured; resync_period=1.5 listed every ~2s. test_informer.py and test_watch.py e2e: 7 passed, as on master.

Does this PR introduce a user-facing change?

SharedInformer now counts `resync_period` from the last list, so the periodic resync also runs when the watch keeps reconnecting (e.g. behind a proxy with an idle timeout of a minute or less) or the period is fractional.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


The resync timer restarted whenever a watch was opened, and the watch
timeout was int(resync_period). A fractional period such as 1.5 ended
every stream after 1s, and an early watch close restarted the timer, so
the periodic resync never ran.

Keep a resync deadline set one period after each list, and set
timeout_seconds to the time left, rounded up to whole seconds. Add
fake-clock unit tests for integer, fractional and Decimal periods,
early closes, failures and a restart.
@kubernetes-prow kubernetes-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Dec 1, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ilcm96
Once this PR has been reviewed and has the lgtm label, please assign yliaog for approval. For more information see the 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

@kubernetes-prow
kubernetes-prow Bot requested review from roycaihw and yliaog December 1, 2026 13:14
@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant