Search in sources :

Example 1 with ContainerClientRegistration

use of de.zalando.ep.zalenium.container.ContainerClientRegistration 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)

Aggregations

ContainerClient (de.zalando.ep.zalenium.container.ContainerClient)1 ContainerClientRegistration (de.zalando.ep.zalenium.container.ContainerClientRegistration)1 ContainerCreationStatus (de.zalando.ep.zalenium.container.ContainerCreationStatus)1 Environment (de.zalando.ep.zalenium.util.Environment)1 DoneablePod (io.fabric8.kubernetes.api.model.DoneablePod)1 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)1 HostAlias (io.fabric8.kubernetes.api.model.HostAlias)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 PodList (io.fabric8.kubernetes.api.model.PodList)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 Volume (io.fabric8.kubernetes.api.model.Volume)1 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 ExecListener (io.fabric8.kubernetes.client.dsl.ExecListener)1 ExecWatch (io.fabric8.kubernetes.client.dsl.ExecWatch)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 InetAddress (java.net.InetAddress)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1