Skip to content

Fix NPE in KubectlTop - skip pods which are down #4087

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ private static PodMetrics findPodMetric(V1Pod pod, PodMetricsList list) {

public static double podMetricSum(PodMetrics podMetrics, String metricName) {
double sum = 0;
if (podMetrics == null) {
return 0;
}
for (ContainerMetrics containerMetrics : podMetrics.getContainers()) {
Quantity value = containerMetrics.getUsage().get(metricName);
if (value != null) {
Expand Down Expand Up @@ -170,7 +173,11 @@ public int compare(V1Pod arg0, V1Pod arg1) {

List<Pair<ApiType, MetricsType>> result = new ArrayList<>();
for (V1Pod pod : items) {
result.add(new ImmutablePair<>((ApiType) pod, (MetricsType) findPodMetric(pod, metrics)));
PodMetrics podMetrics = findPodMetric(pod, metrics);
if (podMetrics == null) {
continue;
}
result.add(new ImmutablePair<>((ApiType) pod, (MetricsType) podMetrics));
}
return result;
}
Expand Down
Loading