Skip to content

Handle dict list responses in SharedInformer initial list - #2777

Open
ilcm96 wants to merge 1 commit into
kubernetes-client:masterfrom
ilcm96:informer-dict-list
Open

ilcm96 wants to merge 1 commit into
kubernetes-client:masterfrom
ilcm96:informer-dict-list

Conversation

@ilcm96

@ilcm96 ilcm96 commented Nov 9, 2026

Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

SharedInformer cannot be used with CustomObjectsApi list functions, which return plain dicts. _initial_list read the items with getattr(resp, "items", []), which returns the bound dict.items method, so the initial list failed with TypeError: 'builtin_function_or_method' object is not iterable every 5 seconds and the cache stayed empty. The list resourceVersion was read the same way and always fell back to "0".

This PR reads items and metadata.resourceVersion from dict list responses. The model object path is unchanged; Watch and the cache key function already handle dicts.

Which issue(s) this PR fixes:

None.

Special notes for your reviewer:

The existing "0" fallback for a list response without metadata.resourceVersion is kept.

How it was tested:

  • New unit test test_initial_list_handles_dict_response in kubernetes/test/test_informer.py; it fails on master with the TypeError above.
  • kind with a namespaced CRD: on master the cache stayed empty for 15s; with this change it was populated, ADDED/DELETED arrived, and the first watch used the list's resourceVersion. kubernetes/e2e_test/test_informer.py and test_watch.py: 7 passed, same as master.

Does this PR introduce a user-facing change?

Fix `SharedInformer` never populating its cache when used with `CustomObjectsApi` list functions, which return dicts.

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


CustomObjectsApi list functions return plain dicts, so the initial list
iterated the bound dict.items method, raised TypeError and was retried
every 5 seconds forever, leaving the cache empty. The list
resourceVersion also fell back to "0".

Read items and metadata.resourceVersion from dict responses; model
responses are unchanged. Add a unit test for a dict list response.
@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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 9, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from roycaihw and yliaog November 9, 2026 11:29
@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 added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 9, 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/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant