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;
}
Aggregations