Fix informer initial list items missing kind/apiVersion#4734
Fix informer initial list items missing kind/apiVersion#4734k8s-ci-robot merged 4 commits intomasterfrom
Conversation
…om list metadata or ModelMapper Agent-Logs-Url: https://github.com/kubernetes-client/java/sessions/717d58ee-9dd8-47b6-ba67-22c111fcaa80 Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Agent-Logs-Url: https://github.com/kubernetes-client/java/sessions/717d58ee-9dd8-47b6-ba67-22c111fcaa80 Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
|
@copilot can you add an e2e tests for this also to validate this works against an actual cluster? |
Agent-Logs-Url: https://github.com/kubernetes-client/java/sessions/1eef68a6-942c-42a6-ab82-3d58e74eb0aa Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Added |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brendandburns, Copilot 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 |
The Kubernetes API omits
kind/apiVersionfrom individual items in list responses (they're set on the list object itself), but includes them in watch events. This causedReflectorRunnable's initial list phase to produce items withnulltype metadata, while subsequent watch events would have them populated — an inconsistency that breaks any code relying on these fields being consistently set.Changes
ReflectorRunnable: After fetching the initial list, calls newpopulateTypeMeta()to backfillkind/apiVersionon items that are missing them."List"suffix from the list'skind(e.g.PodList→Pod) and uses the list'sapiVersiondirectly.ModelMapper.getGroupVersionKindByClass()/preBuiltGetGroupVersionKindByClass()when the list object itself has no type metadata (e.g. in tests).setKind/setApiVersionMethodreferences are cached in the constructor (one-time reflection lookup perReflectorRunnableinstance) to avoid per-call overhead.ReflectorRunnableTest: Added 4 unit tests covering the primary path, ModelMapper fallback, no-overwrite of existing values, and end-to-end population through the full list flow.InformerListTypeMetaTest(e2e): Added an e2e test that starts a real Namespace informer against a cluster, waits for initial sync, and asserts that every item received viaonAddduring the initial list phase haskind="Namespace"andapiVersion="v1"populated — validating the fix against an actual Kubernetes cluster.