Closed
Description
Describe the bug
NullPointerException when calling Kubectl.top if one pod is in erroneous state or down. Stacktrace:
java.lang.NullPointerException: Cannot invoke "io.kubernetes.client.custom.PodMetrics.getContainers()" because "podMetrics" is null
at io.kubernetes.client.extended.kubectl.KubectlTop.podMetricSum(KubectlTop.java:141)
at io.kubernetes.client.extended.kubectl.KubectlTop$2.compare(KubectlTop.java:166)
at io.kubernetes.client.extended.kubectl.KubectlTop$2.compare(KubectlTop.java:160)
at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.base/java.util.TimSort.sort(TimSort.java:220)
at java.base/java.util.Arrays.sort(Arrays.java:1307)
at java.base/java.util.ArrayList.sort(ArrayList.java:1805)
at java.base/java.util.Collections.sort(Collections.java:178)
at io.kubernetes.client.extended.kubectl.KubectlTop.topPods(KubectlTop.java:158)
at io.kubernetes.client.extended.kubectl.KubectlTop.execute(KubectlTop.java:68)
Client Version
io.kubernetes:client-java:23.0.0
io.kubernetes:client-java-extended:23.0.0
Kubernetes Version
1.30
Server Version: version.Info{Major:"1", Minor:"30+", GitVersion:"v1.30.11-eks-bcf3d70", GitCommit:"2fa190a24584e3b061e4c94d3b4d1608e34e5e3b", GitTreeState:"clean", BuildDate:"2025-03-24T21:51:28Z", GoVersion:"go1.23.6", Compiler:"gc", Platform:"linux/amd64"}
Java Version
Java 23
To Reproduce
Steps to reproduce the behavior:
- Have a pod that is down, completed, or in Error state, e.g. deploy a pod with an image that doesn't exist.
- Call Kubectl.top on pods:
public List<Pair<V1Pod, PodMetrics>> getPodUsage(String namespace) throws KubectlException {
return Kubectl.top(V1Pod.class, PodMetrics.class).namespace(namespace).execute();
}
Expected behavior
Just like in the CLI, I expect to get pod metrics for pods which are up.
Server (please complete the following information):
- OS: amazonlinux:2023
- Environment: container in k8s
- Cloud: AWS
Additional context
Same happens on library version 18.0.1.