-
Notifications
You must be signed in to change notification settings - Fork 2k
Informer: Initial list items missing kind/apiVersion compared to watch events #4006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Unfortunately, I believe that this is the expected behavior based on the Kubernetes API Server responses. The initial list is based on a list operation (similar to But the remaining watch data is populated in the individual resources. We might be able to hack this together via the |
@brendandburns
Looks like they are populated:
And the minimal working code to reproduce the scenario: public class TestInformers {
public static void main(String[] args) throws InterruptedException, IOException {
ApiClient apiClient = Config.defaultClient();
apiClient.setReadTimeout(0);
SharedInformerFactory factory = new SharedInformerFactory(apiClient);
CoreV1Api coreV1Api = new CoreV1Api(apiClient);
SharedIndexInformer<V1Pod> podInformer =
factory.sharedIndexInformerFor(
(CallGeneratorParams params) -> {
return coreV1Api
.listPodForAllNamespaces()
.resourceVersion(params.resourceVersion)
.watch(params.watch)
.timeoutSeconds(params.timeoutSeconds)
.buildCall(null);
},
V1Pod.class,
V1PodList.class);
podInformer.addEventHandler(
new ResourceEventHandler<V1Pod>() {
@Override
public void onAdd(V1Pod pod) {
if (pod.getApiVersion() == null || pod.getKind() == null) {
System.out.printf("Pod %s has no apiVersion or kind%n", pod.getMetadata().getName());
} else {
System.out.printf(
"Pod %s added with apiVersion %s and kind %s%n",
pod.getMetadata().getName(), pod.getApiVersion(), pod.getKind());
}
}
@Override
public void onUpdate(V1Pod oldPod, V1Pod newPod) {
}
@Override
public void onDelete(V1Pod pod, boolean deletedFinalStateUnknown) {
}
});
factory.startAllRegisteredInformers();
Thread.sleep(10_000);
factory.stopAllRegisteredInformers();
}
} Output:
|
Hrm, thanks for drilling into the reproduction, I'll see if I can figure out what is going wrong in the parsing then. |
Describe the bug
When using informers, the initial list operation returns a
V1PodList
where the nestedPod
objects do not have thekind
andapiVersion
fields populated (they are null). However, when the informer subsequently receives watch events, the individualPod
objects contain the expected kind (e.g. "Pod") and apiVersion (e.g. "v1"). This inconsistency in the returned data can lead to confusion and issues for applications that depend on these fields being consistently set.Client Version
23.0.0
Kubernetes Version
1.30
Java Version
Java 17
To Reproduce
Steps to reproduce the behavior:
Expected behavior
It is expected that all Pod objects processed by the informer should consistently contain the kind and apiVersion fields.
Additional context
This behavior leads to an inconsistency within the same informer callback - first receiving Pods with incomplete metadata followed by Pods with the correct metadata. This makes it harder to rely on these fields for subsequent processing, and it is unclear whether this is an intentional design choice for efficiency or an oversight in the client’s deserialization process. It would be beneficial if the client could ensure that the nested objects always include the metadata
The text was updated successfully, but these errors were encountered: