Search in sources :

Example 6 with PodList

use of io.fabric8.kubernetes.api.model.PodList in project fabric8-maven-plugin by fabric8io.

the class BaseBoosterIT method waitTillApplicationPodStarts.

/**
 * This variation is used in order to check for the redeployment scenario, since some
 * annotations are added while making changes in source code, and those are checked so
 * that we are able to differentiate between the redeployed pod and the previously
 * existing pod instance from previous deployment.
 *
 * @param key
 * @param value
 * @throws Exception
 */
protected void waitTillApplicationPodStarts(String key, String value) throws InterruptedException {
    logger.info("Waiting for application pod .... ");
    int nPolls = 0;
    // Keep polling till 5 minutes
    while (nPolls < APPLICATION_POD_WAIT_POLLS) {
        PodList podList = openShiftClient.pods().withLabel("app", testsuiteRepositoryArtifactId).list();
        for (Pod pod : podList.getItems()) {
            logger.info("waitTillApplicationPodStarts(" + key + ", " + value + ") -> Pod : " + pod.getMetadata().getName() + ", STATUS : " + KubernetesHelper.getPodStatus(pod) + ", isPodReady : " + KubernetesHelper.isPodReady(pod));
            if (pod.getMetadata().getAnnotations().containsKey(key)) {
                logger.info(pod.getMetadata().getName() + " is redeployed pod.");
            }
            if (pod.getMetadata().getAnnotations().containsKey(key) && pod.getMetadata().getAnnotations().get(key).equalsIgnoreCase(value) && KubernetesHelper.isPodReady(pod)) {
                logger.info("OK ✓ ... Pod wait over.");
                TimeUnit.SECONDS.sleep(10);
                return;
            }
        }
        nPolls++;
        TimeUnit.SECONDS.sleep(10);
    }
    throw new AssertionError("Pod wait timeout! Could not find application pod for " + testsuiteRepositoryArtifactId);
}
Also used : PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod)

Example 7 with PodList

use of io.fabric8.kubernetes.api.model.PodList in project zalenium by zalando.

the class KubernetesContainerClient method registerNode.

@Override
public ContainerClientRegistration registerNode(String zaleniumContainerName, URL remoteHost) {
    String podIpAddress = remoteHost.getHost();
    // The only way to lookup a pod name by IP address is by looking at all pods in the namespace it seems.
    PodList list = client.pods().withLabels(createdByZaleniumMap).list();
    String containerId = null;
    Pod currentPod = null;
    for (Pod pod : list.getItems()) {
        if (podIpAddress.equals(pod.getStatus().getPodIP())) {
            containerId = pod.getMetadata().getName();
            currentPod = pod;
            break;
        }
    }
    if (containerId == null) {
        throw new IllegalStateException("Unable to locate pod by ip address, registration will fail");
    }
    ContainerClientRegistration registration = new ContainerClientRegistration();
    List<EnvVar> podEnvironmentVariables = currentPod.getSpec().getContainers().get(0).getEnv();
    Optional<EnvVar> noVncPort = podEnvironmentVariables.stream().filter(env -> "NOVNC_PORT".equals(env.getName())).findFirst();
    if (noVncPort.isPresent()) {
        Integer noVncPortInt = Integer.decode(noVncPort.get().getValue());
        registration.setNoVncPort(noVncPortInt);
    } else {
        logger.warn(String.format("%s Couldn't find NOVNC_PORT, live preview will not work.", containerId));
    }
    registration.setIpAddress(currentPod.getStatus().getPodIP());
    registration.setContainerId(containerId);
    return registration;
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Environment(de.zalando.ep.zalenium.util.Environment) URL(java.net.URL) ContainerClientRegistration(de.zalando.ep.zalenium.container.ContainerClientRegistration) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) HostAlias(io.fabric8.kubernetes.api.model.HostAlias) Map(java.util.Map) Response(okhttp3.Response) ExecListener(io.fabric8.kubernetes.client.dsl.ExecListener) ContainerClient(de.zalando.ep.zalenium.container.ContainerClient) Volume(io.fabric8.kubernetes.api.model.Volume) Logger(org.slf4j.Logger) Pod(io.fabric8.kubernetes.api.model.Pod) ExecWatch(io.fabric8.kubernetes.client.dsl.ExecWatch) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) PodList(io.fabric8.kubernetes.api.model.PodList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Optional(java.util.Optional) ContainerCreationStatus(de.zalando.ep.zalenium.container.ContainerCreationStatus) InputStream(java.io.InputStream) PodList(io.fabric8.kubernetes.api.model.PodList) ContainerClientRegistration(de.zalando.ep.zalenium.container.ContainerClientRegistration) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) Pod(io.fabric8.kubernetes.api.model.Pod) EnvVar(io.fabric8.kubernetes.api.model.EnvVar)

Example 8 with PodList

use of io.fabric8.kubernetes.api.model.PodList in project fabric8 by fabric8io.

the class ExampleTest method testNavigationListAssertions.

@Test
public void testNavigationListAssertions() throws Exception {
    final String id1 = "abc";
    final String id2 = "def";
    Map<String, String> labels1 = new HashMap<>();
    labels1.put("foo", "bar");
    Map<String, String> labels2 = new HashMap<>();
    labels2.put("whatnot", "cheese");
    final Pod pod1 = new Pod();
    pod1.setMetadata(new ObjectMeta());
    pod1.getMetadata().setName(id1);
    pod1.getMetadata().setLabels(labels1);
    final Pod pod2 = new Pod();
    pod2.setMetadata(new ObjectMeta());
    pod2.getMetadata().setName(id2);
    pod2.getMetadata().setLabels(labels2);
    final PodList emptyPodList = new PodList();
    final PodList podList = new PodList();
    podList.setItems(new ArrayList<Pod>(Arrays.asList(pod1, pod2)));
    assertThat(emptyPodList).describedAs("emptyPodList").items().isEmpty();
    assertThat(podList).describedAs("podListWith2Items").items().first().metadata().name().isEqualTo(id1);
    assertThat(podList).describedAs("podListWith2Items").items().last().metadata().name().isEqualTo(id2);
    assertAssertionError(new Block() {

        @Override
        public void invoke() throws Exception {
            assertThat(podList).describedAs("podListWith2Items").items().item(-1).isNotNull();
        }
    });
    assertAssertionError(new Block() {

        @Override
        public void invoke() throws Exception {
            assertThat(podList).describedAs("podListWith2Items").items().item(2).isNotNull();
        }
    });
    assertAssertionError(new Block() {

        @Override
        public void invoke() throws Exception {
            assertThat(podList).describedAs("podListWith2Items").items().first().metadata().name().isEqualTo("shouldNotMatch");
        }
    });
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) HashMap(java.util.HashMap) Block(io.fabric8.utils.Block) Test(org.junit.Test)

Example 9 with PodList

use of io.fabric8.kubernetes.api.model.PodList in project fabric8 by fabric8io.

the class Example method listPods.

protected static void listPods(KubernetesClient kube) {
    System.out.println("\n\nLooking up pods");
    System.out.println("=========================================================================");
    PodList pods = kube.pods().list();
    // System.out.println("Got pods: " + pods);
    List<Pod> items = pods.getItems();
    for (Pod item : items) {
        System.out.println("Pod " + KubernetesHelper.getName(item) + " with ip: " + item.getStatus().getPodIP() + " created: " + item.getMetadata().getCreationTimestamp());
        PodSpec spec = item.getSpec();
        if (spec != null) {
            List<Container> containers = spec.getContainers();
            if (containers != null) {
                for (Container container : containers) {
                    System.out.println("Container " + container.getImage() + " " + container.getCommand() + " ports: " + container.getPorts());
                }
            }
        }
        Map<String, ContainerStatus> currentContainers = KubernetesHelper.getCurrentContainers(item);
        System.out.println("Has " + currentContainers.size() + " container(s)");
        Set<Map.Entry<String, ContainerStatus>> entries = currentContainers.entrySet();
        for (Map.Entry<String, ContainerStatus> entry : entries) {
            String id = entry.getKey();
            ContainerStatus info = entry.getValue();
            System.out.println("Current container: " + id + " info: " + info);
        }
    }
    System.out.println();
}
Also used : PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Container(io.fabric8.kubernetes.api.model.Container) ContainerStatus(io.fabric8.kubernetes.api.model.ContainerStatus) Map(java.util.Map)

Example 10 with PodList

use of io.fabric8.kubernetes.api.model.PodList in project fabric8 by fabric8io.

the class PodResourceProvider method lookup.

@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
    KubernetesClient client = this.clientInstance.get();
    Session session = sessionInstance.get();
    String name = getPodName(qualifiers);
    if (name != null) {
        return client.pods().inNamespace(session.getNamespace()).withName(name).get();
    }
    // Gets the first pod found that matches the labels.
    Map<String, String> labels = getLabels(qualifiers);
    PodList list = client.pods().inNamespace(session.getNamespace()).withLabels(labels).list();
    List<Pod> pods = notNullList(list.getItems());
    if (!pods.isEmpty()) {
        return pods.get(0);
    }
    return null;
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) Session(io.fabric8.arquillian.kubernetes.Session)

Aggregations

PodList (io.fabric8.kubernetes.api.model.PodList)32 Pod (io.fabric8.kubernetes.api.model.Pod)30 Test (org.junit.Test)8 DoneablePod (io.fabric8.kubernetes.api.model.DoneablePod)7 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)7 Watch (io.fabric8.kubernetes.client.Watch)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Watcher (io.fabric8.kubernetes.client.Watcher)5 ContainerStatus (io.fabric8.kubernetes.api.model.ContainerStatus)4 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)4 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 Service (io.fabric8.kubernetes.api.model.Service)3 ServiceList (io.fabric8.kubernetes.api.model.ServiceList)3 PodResource (io.fabric8.kubernetes.client.dsl.PodResource)3 Session (io.fabric8.arquillian.kubernetes.Session)2 Controller (io.fabric8.kubernetes.api.Controller)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ConfigMapList (io.fabric8.kubernetes.api.model.ConfigMapList)2