Skip to content

Fix informer initial list items missing kind/apiVersion#4734

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-initial-pod-list-missing-fields
Draft

Fix informer initial list items missing kind/apiVersion#4734
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-initial-pod-list-missing-fields

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 1, 2026

The Kubernetes API omits kind/apiVersion from individual items in list responses (they're set on the list object itself), but includes them in watch events. This caused ReflectorRunnable's initial list phase to produce items with null type 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 new populateTypeMeta() to backfill kind/apiVersion on items that are missing them.
    • Primary strategy: derives item kind by stripping the "List" suffix from the list's kind (e.g. PodListPod) and uses the list's apiVersion directly.
    • Fallback: uses ModelMapper.getGroupVersionKindByClass() / preBuiltGetGroupVersionKindByClass() when the list object itself has no type metadata (e.g. in tests).
    • setKind/setApiVersion Method references are cached in the constructor (one-time reflection lookup per ReflectorRunnable instance) to avoid per-call overhead.
// Before: pods from initial list had null kind/apiVersion
informer.addEventHandler(new ResourceEventHandler<V1Pod>() {
    public void onAdd(V1Pod pod) {
        pod.getKind();       // null during initial list, "Pod" on watch events
        pod.getApiVersion(); // null during initial list, "v1" on watch events
    }
});

// After: consistently populated in both phases
pod.getKind();       // "Pod"
pod.getApiVersion(); // "v1"
  • ReflectorRunnableTest: Added 4 tests covering the primary path, ModelMapper fallback, no-overwrite of existing values, and end-to-end population through the full list flow.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 1, 2026
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 1, 2026
…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>
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Copilot
Once this PR has been reviewed and has the lgtm label, please ask for approval from brendandburns. 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

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 1, 2026
Copilot AI changed the title [WIP] Fix initial list items missing kind and apiVersion in Pod objects Fix informer initial list items missing kind/apiVersion May 1, 2026
Copilot AI requested a review from brendandburns May 1, 2026 15:13
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. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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.

Informer: Initial list items missing kind/apiVersion compared to watch events

3 participants