/*** * Creates pod from resources * @param namespace * @param configName * @throws Exception */ public void createPodFromTemplate(String namespace, String configName) throws Exception { List<HasMetadata> resources = client.load(getClass().getResourceAsStream(configName)).inNamespace(namespace).get(); HasMetadata resource = resources.get(0); Pod podRes = client.pods().inNamespace(namespace).create((Pod) resource); Pod result = client.pods().inNamespace(namespace) .withName(podRes.getMetadata().getName()).waitUntilReady(5, TimeUnit.SECONDS); log.info("Pod created {}", result.getMetadata().getName()); }
private void waitUntilContainerIsReady() throws IOException { try { Pod pod = client.pods().inNamespace(namespace).withName(podName) .waitUntilReady(CONTAINER_READY_TIMEOUT, TimeUnit.MINUTES); if (pod == null || pod.getStatus() == null || pod.getStatus().getContainerStatuses() == null) { throw new IOException("Failed to execute shell script inside container " + "[" + containerName + "] of pod [" + podName + "]." + "Failed to get container status"); } for (ContainerStatus info : pod.getStatus().getContainerStatuses()) { if (info.getName().equals(containerName)) { if (info.getReady()) { return; } else { // container died in the meantime throw new IOException("container [" + containerName + "] of pod [" + podName + "] is not ready, state is " + info.getState()); } } } throw new IOException("container [" + containerName + "] does not exist in pod [" + podName + "]"); } catch (InterruptedException | KubernetesClientTimeoutException e) { throw new IOException("Failed to execute shell script inside container " + "[" + containerName + "] of pod [" + podName + "]." + " Timed out waiting for container to become ready!", e); } } };