Skip to content

Request watch bookmarks from SharedInformer and track untyped watch resource versions - #2818

Open
ilcm96 wants to merge 2 commits into
kubernetes-client:masterfrom
ilcm96:informer-watch-bookmarks
Open

ilcm96 wants to merge 2 commits into
kubernetes-client:masterfrom
ilcm96:informer-watch-bookmarks

Conversation

@ilcm96

@ilcm96 ilcm96 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug
/kind feature

What this PR does / why we need it:

A reconnecting SharedInformer can resume from its initial list's resource version; once the server no longer keeps it, the watch gets 410 Gone and re-lists, firing MODIFIED for every cached object. Two commits fix this:

  1. Track the watch resource version without a return type. When Watch cannot find the list function's return type, e.g. a lambda wrapper, it never recorded a resource version, so Watch and SharedInformer reconnected from the initial one. It is now read from the raw event; yielded events are unchanged.
  2. Request watch bookmarks from SharedInformer. Without allow_watch_bookmarks the server sends no BOOKMARK events, so handlers never run and a namespace- or selector-scoped watch keeps its list's resource version while nothing matching changes. The informer now sets it on watch requests (not lists).

On kind, with a lambda list_func, a watch dropped after the list's resource version expired re-listed once on master and zero times with this PR.

Which issue(s) this PR fixes:

None filed.

Special notes for your reviewer:

A custom list_func wrapper must accept allow_watch_bookmarks; all generated list functions do.

How I tested it:

  • New unit tests, each failing without its commit, check the resumed resource version through a lambda and the informer's watch arguments.
  • e2e test_informer.py and test_watch.py: 7 passed, as on master.

Does this PR introduce a user-facing change?

Watch tracks the resource version when the list function has no return type (e.g. a lambda); such a watch started without `resource_version` and `timeout_seconds` now reconnects when the server closes it instead of ending. SharedInformer requests watch bookmarks, so BOOKMARK handlers run and quiet watches avoid re-listing. A custom `list_func` must accept `allow_watch_bookmarks`.

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


When Watch cannot find the return type of the list function (no return
annotation and no ":rtype:" docstring, e.g. a lambda wrapper around a
generated list function), unmarshal_event returned the raw event before
recording its resourceVersion. Watch.resource_version stayed at the
initial value, even across BOOKMARK events, so Watch reconnected from
the initial version, replayed events and raised 410 Gone once that
version expired; SharedInformer, which copies it, re-listed.

Record the resourceVersion from the raw event dict, sharing the helper
with the deserialize=False path. Events are still returned unchanged.
As with typed list functions, such a watch started without
resource_version and timeout_seconds now reconnects from the last
event's version when the server closes the stream instead of ending,
and raises ApiException(410) if that version has expired.

Add a test that streams through a lambda wrapper and checks the tracked
resource version and the version used to reconnect.
SharedInformer never set allow_watch_bookmarks on its watch requests,
so the API server sent no BOOKMARK events. BOOKMARK handlers never ran,
and a watch with a narrow namespace or selector kept the resource
version of the last list. When such a quiet watch reconnected after the
server had dropped that version from its watch history, it got 410 Gone
and re-listed every object, firing MODIFIED for each of them.

Set allow_watch_bookmarks=True on every watch request the informer
opens. The list requests are unchanged. Watch already records the
resource version of a BOOKMARK event, so the informer now resumes from
it, and registered BOOKMARK handlers start to receive the raw bookmark
object.

Add a unit test that runs the real Watch over typed and dict list
responses and a list function without a return type, and checks the
watch arguments, the BOOKMARK handler and the resource version of the
next watch.
@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. kind/feature Categorizes issue or PR as related to a new feature. 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 Nov 28, 2026
@kubernetes-prow
kubernetes-prow Bot requested a review from roycaihw November 28, 2026 07:01
@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 roycaihw 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 a review from yliaog November 28, 2026 07:01
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. kind/feature Categorizes issue or PR as related to a new feature. 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