Skip to content

Fix informer initial list items missing kind/apiVersion#4734

Merged
k8s-ci-robot merged 4 commits intomasterfrom
copilot/fix-initial-pod-list-missing-fields
May 4, 2026
Merged

Fix informer initial list items missing kind/apiVersion#4734
k8s-ci-robot merged 4 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 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 via onAdd during the initial list phase has kind="Namespace" and apiVersion="v1" populated — validating the fix against an actual Kubernetes cluster.

@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 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
@brendandburns
Copy link
Copy Markdown
Contributor

@copilot can you add an e2e tests for this also to validate this works against an actual cluster?

@brendandburns brendandburns marked this pull request as ready for review May 2, 2026 01:16
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 2, 2026
@k8s-ci-robot k8s-ci-robot requested a review from yue9944882 May 2, 2026 01:16
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 2, 2026

@copilot can you add an e2e tests for this also to validate this works against an actual cluster?

Added InformerListTypeMetaTest in e2e/src/test/java/io/kubernetes/client/e2e/informer/ (commit 4dced83). The test starts a real Namespace informer against a cluster, waits for initial sync, and asserts that every item received via onAdd has kind="Namespace" and apiVersion="v1" set — exactly the scenario described in the bug.

@brendandburns
Copy link
Copy Markdown
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 4, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[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

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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 4, 2026
@k8s-ci-robot k8s-ci-robot merged commit 2a74118 into master May 4, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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