use of io.kubernetes.client.openapi.models.V1PodList in project java by kubernetes-client.
the class SharedInformerFactoryTest method testNamespaceScopedNewInformerUsingGenericApi.
@Test
public void testNamespaceScopedNewInformerUsingGenericApi() {
SharedInformerFactory factory = new SharedInformerFactory();
SharedInformer<V1Pod> podInformer = factory.sharedIndexInformerFor(genericKubernetesApi, V1Pod.class, 0, "default");
assertThat(podInformer).isNotNull();
when(genericKubernetesApi.list(eq("default"), any(ListOptions.class))).thenReturn(new KubernetesApiResponse<V1PodList>(new V1PodList().metadata(new V1ListMeta().resourceVersion("0"))));
factory.startAllRegisteredInformers();
await().timeout(Duration.ofSeconds(2)).until(podInformer::hasSynced);
verify(genericKubernetesApi, atLeastOnce()).list(eq("default"), any(ListOptions.class));
}
use of io.kubernetes.client.openapi.models.V1PodList in project twister2 by DSC-SPIDAL.
the class KubernetesController method getUploaderWebServerPods.
public List<String> getUploaderWebServerPods(String uploaderLabel) {
V1PodList podList = null;
try {
podList = coreApi.listNamespacedPod(namespace, null, null, null, null, uploaderLabel, null, null, null, null);
} catch (ApiException e) {
LOG.log(Level.SEVERE, "Exception when getting uploader pod list.", e);
throw new RuntimeException(e);
}
List<String> podNames = podList.getItems().stream().map(v1pod -> v1pod.getMetadata().getName()).collect(Collectors.toList());
return podNames;
}
use of io.kubernetes.client.openapi.models.V1PodList in project twister2 by DSC-SPIDAL.
the class PodWatchUtils method getNodeIP.
/**
* get the IP of the node where the pod with that name is running
*/
public static String getNodeIP(String namespace, String jobID, String podIP) {
if (apiClient == null || coreApi == null) {
createApiInstances();
}
// this is better but it does not work with another installation
// String podNameLabel = "statefulset.kubernetes.io/pod-name=" + podName;
String workerRoleLabel = KubernetesUtils.workerPodLabelSelector(jobID);
V1PodList podList = null;
try {
podList = coreApi.listNamespacedPod(namespace, null, null, null, null, workerRoleLabel, null, null, null, null);
} catch (ApiException e) {
LOG.log(Level.SEVERE, "Exception when getting PodList.", e);
throw new RuntimeException(e);
}
for (V1Pod pod : podList.getItems()) {
if (podIP.equals(pod.getStatus().getPodIP())) {
return pod.getStatus().getHostIP();
}
}
return null;
}
use of io.kubernetes.client.openapi.models.V1PodList in project twister2 by DSC-SPIDAL.
the class PodWatchUtils method testGetPodList.
/**
* a test method to see whether kubernetes java client can connect to kubernetes master
* and get the pod list
*/
public static void testGetPodList(String namespace) {
if (apiClient == null || coreApi == null) {
createApiInstances();
}
LOG.info("Getting the pod list for the namespace: " + namespace);
V1PodList list = null;
try {
list = coreApi.listNamespacedPod(namespace, null, null, null, null, null, null, null, null, null);
} catch (ApiException e) {
String logMessage = "Exception when getting the pod list: \n" + "exCode: " + e.getCode() + "\n" + "responseBody: " + e.getResponseBody();
LOG.log(Level.SEVERE, logMessage, e);
throw new RuntimeException(e);
}
LOG.info("Number of pods in the received list: " + list.getItems().size());
for (V1Pod item : list.getItems()) {
LOG.info(item.getMetadata().getName());
}
}
use of io.kubernetes.client.openapi.models.V1PodList in project pravega by pravega.
the class K8sClient method getPodsWithLabels.
/**
* Method to fetch all pods which match a set of labels.
* @param namespace Namespace on which the pod(s) reside.
* @param labels Name of the label.
* @return Future representing the list of pod status.
*/
@SneakyThrows(ApiException.class)
public CompletableFuture<V1PodList> getPodsWithLabels(String namespace, Map<String, String> labels) {
CoreV1Api api = new CoreV1Api();
log.debug("Current number of http interceptors {}", api.getApiClient().getHttpClient().networkInterceptors().size());
String labelSelector = labels.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.joining());
K8AsyncCallback<V1PodList> callback = new K8AsyncCallback<>("listPods-" + labels);
api.listNamespacedPodAsync(namespace, PRETTY_PRINT, ALLOW_WATCH_BOOKMARKS, null, null, labelSelector, null, null, null, false, callback);
return callback.getFuture();
}
Aggregations