Search in sources :

Example 41 with V1PodList

use of io.kubernetes.client.openapi.models.V1PodList in project java by kubernetes-client.

the class ExpandedExample method getPods.

/**
 * List all pod names in all namespaces in k8s cluster
 *
 * @return
 * @throws ApiException
 */
public static List<String> getPods() throws ApiException {
    V1PodList v1podList = COREV1_API.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null);
    List<String> podList = v1podList.getItems().stream().map(v1Pod -> v1Pod.getMetadata().getName()).collect(Collectors.toList());
    return podList;
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1NamespaceList(io.kubernetes.client.openapi.models.V1NamespaceList) Logger(org.slf4j.Logger) V1DeploymentList(io.kubernetes.client.openapi.models.V1DeploymentList) LoggerFactory(org.slf4j.LoggerFactory) V1PodList(io.kubernetes.client.openapi.models.V1PodList) IOException(java.io.IOException) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) Collectors(java.util.stream.Collectors) AppsV1Api(io.kubernetes.client.openapi.apis.AppsV1Api) Config(io.kubernetes.client.util.Config) ApiClient(io.kubernetes.client.openapi.ApiClient) ApiException(io.kubernetes.client.openapi.ApiException) List(java.util.List) Configuration(io.kubernetes.client.openapi.Configuration) V1DeploymentSpec(io.kubernetes.client.openapi.models.V1DeploymentSpec) Optional(java.util.Optional) V1Deployment(io.kubernetes.client.openapi.models.V1Deployment) V1ServiceList(io.kubernetes.client.openapi.models.V1ServiceList)

Example 42 with V1PodList

use of io.kubernetes.client.openapi.models.V1PodList in project druid by druid-io.

the class DefaultK8sApiClient method listPods.

@Override
public DiscoveryDruidNodeList listPods(String podNamespace, String labelSelector, NodeRole nodeRole) {
    try {
        V1PodList podList = coreV1Api.listNamespacedPod(podNamespace, null, null, null, null, labelSelector, 0, null, null, null);
        Preconditions.checkState(podList != null, "WTH: NULL podList");
        Map<String, DiscoveryDruidNode> allNodes = new HashMap();
        for (V1Pod podDef : podList.getItems()) {
            DiscoveryDruidNode node = getDiscoveryDruidNodeFromPodDef(nodeRole, podDef);
            allNodes.put(node.getDruidNode().getHostAndPortToUse(), node);
        }
        return new DiscoveryDruidNodeList(podList.getMetadata().getResourceVersion(), allNodes);
    } catch (ApiException ex) {
        throw new RE(ex, "Expection in listing pods, code[%d] and error[%s].", ex.getCode(), ex.getResponseBody());
    }
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) RE(org.apache.druid.java.util.common.RE) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) HashMap(java.util.HashMap) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiException(io.kubernetes.client.openapi.ApiException)

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