Search in sources :

Example 21 with V1PodList

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));
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ListOptions(io.kubernetes.client.util.generic.options.ListOptions) V1ListMeta(io.kubernetes.client.openapi.models.V1ListMeta) Test(org.junit.Test)

Example 22 with V1PodList

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;
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1NodeList(io.kubernetes.client.openapi.models.V1NodeList) V1ConfigMapList(io.kubernetes.client.openapi.models.V1ConfigMapList) V1NodeAddress(io.kubernetes.client.openapi.models.V1NodeAddress) V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1Node(io.kubernetes.client.openapi.models.V1Node) V1StatefulSetList(io.kubernetes.client.openapi.models.V1StatefulSetList) Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) AppsV1Api(io.kubernetes.client.openapi.apis.AppsV1Api) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) ApiClient(io.kubernetes.client.openapi.ApiClient) JobMasterAPI(edu.iu.dsc.tws.proto.jobmaster.JobMasterAPI) ApiException(io.kubernetes.client.openapi.ApiException) V1Patch(io.kubernetes.client.custom.V1Patch) Configuration(io.kubernetes.client.openapi.Configuration) V1PersistentVolume(io.kubernetes.client.openapi.models.V1PersistentVolume) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Map(java.util.Map) V1PersistentVolumeClaimList(io.kubernetes.client.openapi.models.V1PersistentVolumeClaimList) V1StatefulSet(io.kubernetes.client.openapi.models.V1StatefulSet) V1ServiceList(io.kubernetes.client.openapi.models.V1ServiceList) NodeInfoUtils(edu.iu.dsc.tws.proto.utils.NodeInfoUtils) Exec(io.kubernetes.client.Exec) V1Secret(io.kubernetes.client.openapi.models.V1Secret) JobAPI(edu.iu.dsc.tws.proto.system.job.JobAPI) IOException(java.io.IOException) ProcessUtils(edu.iu.dsc.tws.rsched.utils.ProcessUtils) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ClientBuilder(io.kubernetes.client.util.ClientBuilder) Base64(java.util.Base64) List(java.util.List) V1PersistentVolumeList(io.kubernetes.client.openapi.models.V1PersistentVolumeList) OkHttpClient(okhttp3.OkHttpClient) V1SecretList(io.kubernetes.client.openapi.models.V1SecretList) V1PersistentVolumeClaim(io.kubernetes.client.openapi.models.V1PersistentVolumeClaim) V1Service(io.kubernetes.client.openapi.models.V1Service) Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) ApiException(io.kubernetes.client.openapi.ApiException)

Example 23 with V1PodList

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;
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiException(io.kubernetes.client.openapi.ApiException)

Example 24 with V1PodList

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());
    }
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiException(io.kubernetes.client.openapi.ApiException)

Example 25 with V1PodList

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();
}
Also used : PodLogs(io.kubernetes.client.PodLogs) TypeToken(com.google.gson.reflect.TypeToken) SneakyThrows(lombok.SneakyThrows) Retry(io.pravega.common.util.Retry) V1beta1CustomResourceDefinition(io.kubernetes.client.openapi.models.V1beta1CustomResourceDefinition) Cleanup(lombok.Cleanup) V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1PodStatus(io.kubernetes.client.openapi.models.V1PodStatus) TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) ApiextensionsV1beta1Api(io.kubernetes.client.openapi.apis.ApiextensionsV1beta1Api) Futures.exceptionallyExpecting(io.pravega.common.concurrent.Futures.exceptionallyExpecting) V1beta1ClusterRole(io.kubernetes.client.openapi.models.V1beta1ClusterRole) V1Patch(io.kubernetes.client.custom.V1Patch) Configuration(io.kubernetes.client.openapi.Configuration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) V1beta1ClusterRoleBinding(io.kubernetes.client.openapi.models.V1beta1ClusterRoleBinding) V1ServiceAccount(io.kubernetes.client.openapi.models.V1ServiceAccount) V1DeleteOptions(io.kubernetes.client.openapi.models.V1DeleteOptions) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) V1Secret(io.kubernetes.client.openapi.models.V1Secret) CONFLICT(javax.ws.rs.core.Response.Status.CONFLICT) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) RbacAuthorizationV1beta1Api(io.kubernetes.client.openapi.apis.RbacAuthorizationV1beta1Api) V1Status(io.kubernetes.client.openapi.models.V1Status) Collectors(java.util.stream.Collectors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Optional(java.util.Optional) ApiCallback(io.kubernetes.client.openapi.ApiCallback) PatchUtils(io.kubernetes.client.util.PatchUtils) Futures(io.pravega.common.concurrent.Futures) V1Deployment(io.kubernetes.client.openapi.models.V1Deployment) Exceptions(io.pravega.common.Exceptions) Watch(io.kubernetes.client.util.Watch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) AppsV1Api(io.kubernetes.client.openapi.apis.AppsV1Api) ApiClient(io.kubernetes.client.openapi.ApiClient) ApiException(io.kubernetes.client.openapi.ApiException) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) V1ContainerStateTerminated(io.kubernetes.client.openapi.models.V1ContainerStateTerminated) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) V1ContainerStatus(io.kubernetes.client.openapi.models.V1ContainerStatus) V1Namespace(io.kubernetes.client.openapi.models.V1Namespace) V1beta1Role(io.kubernetes.client.openapi.models.V1beta1Role) JsonSyntaxException(com.google.gson.JsonSyntaxException) Files(java.nio.file.Files) CustomObjectsApi(io.kubernetes.client.openapi.apis.CustomObjectsApi) IOException(java.io.IOException) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) Config(io.kubernetes.client.util.Config) TimeUnit(java.util.concurrent.TimeUnit) ConnectionFailed(io.pravega.test.system.framework.TestFrameworkException.Type.ConnectionFailed) Paths(java.nio.file.Paths) V1ContainerState(io.kubernetes.client.openapi.models.V1ContainerState) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) V1beta1RoleBinding(io.kubernetes.client.openapi.models.V1beta1RoleBinding) SECONDS(java.util.concurrent.TimeUnit.SECONDS) V1Pod(io.kubernetes.client.openapi.models.V1Pod) InputStream(java.io.InputStream) V1PodList(io.kubernetes.client.openapi.models.V1PodList) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) SneakyThrows(lombok.SneakyThrows)

Aggregations

V1PodList (io.kubernetes.client.openapi.models.V1PodList)42 V1Pod (io.kubernetes.client.openapi.models.V1Pod)33 Test (org.junit.Test)22 ApiException (io.kubernetes.client.openapi.ApiException)18 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)17 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)16 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)13 ApiClient (io.kubernetes.client.openapi.ApiClient)12 Watch (io.kubernetes.client.util.Watch)9 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)7 JSON (io.kubernetes.client.openapi.JSON)6 V1Status (io.kubernetes.client.openapi.models.V1Status)6 List (java.util.List)6 V1Patch (io.kubernetes.client.custom.V1Patch)5 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)5 Configuration (io.kubernetes.client.openapi.Configuration)5 AppsV1Api (io.kubernetes.client.openapi.apis.AppsV1Api)5 IOException (java.io.IOException)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 Collectors (java.util.stream.Collectors)5