diff --git a/src/main/java/cz/xtf/docker/DockerContainer.java b/src/main/java/cz/xtf/docker/DockerContainer.java index 6b551513..3ada78af 100644 --- a/src/main/java/cz/xtf/docker/DockerContainer.java +++ b/src/main/java/cz/xtf/docker/DockerContainer.java @@ -1,8 +1,13 @@ package cz.xtf.docker; +import static cz.xtf.openshift.OpenShiftUtils.admin; + +import java.net.InetAddress; import java.net.URI; +import java.net.UnknownHostException; import java.nio.charset.StandardCharsets; import java.util.Collection; +import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; import java.util.regex.Matcher; @@ -16,6 +21,7 @@ import cz.xtf.TestConfiguration; import cz.xtf.openshift.OpenshiftUtil; +import io.fabric8.kubernetes.api.model.NodeAddress; import io.fabric8.kubernetes.api.model.Pod; public class DockerContainer { @@ -60,6 +66,17 @@ public static DockerContainer createForPod(Pod pod) { public static DockerContainer createForPod(Pod pod, String containerLabel) { String host = pod.getSpec().getNodeName(); + try { + // attempt to treat the node name as a hostname + InetAddress.getByName(host); + } catch (UnknownHostException e) { + // try the node external address if exists + Optional nodeAddress = admin().client().nodes().withName(host).get().getStatus().getAddresses().stream().filter(addr -> "ExternalIP".equals(addr.getType())).findFirst(); + if (nodeAddress.isPresent()) { + host = nodeAddress.get().getAddress(); + } + } + String containerId = URI.create(pod.getStatus().getContainerStatuses().stream() .filter(containerStats -> containerStats.getName().equals(containerLabel)) .findFirst().get().getContainerID()