use of io.kubernetes.client.custom.PodMetricsList in project java by kubernetes-client.
the class KubectlTop method topPods.
private List<Pair<ApiType, MetricsType>> topPods(CoreV1Api api, ApiClient apiClient, String metricName) throws KubectlException, ApiException, IOException {
V1PodList pods = api.listNamespacedPod(namespace, null, null, null, null, null, null, null, null, null, null);
PodMetricsList metrics = new Metrics(apiClient).getPodMetrics(namespace);
List<V1Pod> items = pods.getItems();
Collections.sort(items, new Comparator<V1Pod>() {
@Override
public int compare(V1Pod arg0, V1Pod arg1) {
double m0 = podMetricSum(findPodMetric(arg0.getMetadata().getName(), metrics), metricName);
double m1 = podMetricSum(findPodMetric(arg1.getMetadata().getName(), metrics), metricName);
// sort high to low
return Double.compare(m0, m1) * -1;
}
});
List<Pair<ApiType, MetricsType>> result = new ArrayList<>();
for (V1Pod pod : items) {
result.add(new ImmutablePair<>((ApiType) pod, (MetricsType) findPodMetric(pod, metrics)));
}
return result;
}
Aggregations