static Optional<ContainerStatus> getMainContainerStatus(Pod pod) { return readPodWorkflowInstance(pod) .flatMap(wfi -> pod.getStatus().getContainerStatuses().stream() .filter(status -> isMainContainer(status.getName(), pod)) .findAny()); }
/** * Log the last lines of containers logs */ private void logLastLines(List<ContainerStatus> containers, String podId, String namespace, KubernetesSlave slave, Map<String, Integer> errors, KubernetesClient client) { for (ContainerStatus containerStatus : containers) { String containerName = containerStatus.getName(); PrettyLoggable<String, LogWatch> tailingLines = client.pods().inNamespace(namespace) .withName(podId).inContainer(containerStatus.getName()).tailingLines(30); String log = tailingLines.getLog(); if (!StringUtils.isBlank(log)) { String msg = errors != null ? String.format(" exited with error %s", errors.get(containerName)) : ""; LOGGER.log(Level.SEVERE, "Error in provisioning; agent={0}, template={1}. Container {2}{3}. Logs: {4}", new Object[]{slave, slave.getTemplate(), containerName, msg, tailingLines.getLog()}); } } }
if(status.getName().startsWith(nodeName)&&status.getReady())
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); } } };
public HashMap<String, String> getLogsOfTerminatedPods(String namespace) { HashMap<String, String> terminatedPodsLogs = new HashMap<>(); try { client.pods().inNamespace(namespace).list().getItems().forEach(pod -> { pod.getStatus().getContainerStatuses().forEach(containerStatus -> { log.info("pod:'{}' : restart count '{}'", pod.getMetadata().getName(), containerStatus.getRestartCount()); if (containerStatus.getRestartCount() > 0) { terminatedPodsLogs.put( pod.getMetadata().getName(), client.pods().inNamespace(namespace) .withName(pod.getMetadata().getName()) .inContainer(containerStatus.getName()) .terminated().getLog()); } }); }); } catch (Exception allExceptions) { log.warn("Searching in terminated pods failed! No logs of terminated pods will be stored."); allExceptions.printStackTrace(); } return terminatedPodsLogs; }
cs.put("image", it.getImage()); cs.put("imageId", it.getImageID()); cs.put("name", it.getName()); cs.put("ready", it.getReady()); cs.put("restartCount", it.getRestartCount());
public ContainerStatusFluentImpl(ContainerStatus instance){ this.withContainerID(instance.getContainerID()); this.withImage(instance.getImage()); this.withImageID(instance.getImageID()); this.withLastState(instance.getLastState()); this.withName(instance.getName()); this.withReady(instance.getReady()); this.withRestartCount(instance.getRestartCount()); this.withState(instance.getState()); }
public ContainerStatusBuilder(ContainerStatus instance,Boolean validationEnabled){ this.fluent = this; this.withContainerID(instance.getContainerID()); this.withImage(instance.getImage()); this.withImageID(instance.getImageID()); this.withLastState(instance.getLastState()); this.withName(instance.getName()); this.withReady(instance.getReady()); this.withRestartCount(instance.getRestartCount()); this.withState(instance.getState()); this.validationEnabled = validationEnabled; }
public ContainerStatusBuilder(ContainerStatusFluent<?> fluent,ContainerStatus instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withContainerID(instance.getContainerID()); fluent.withImage(instance.getImage()); fluent.withImageID(instance.getImageID()); fluent.withLastState(instance.getLastState()); fluent.withName(instance.getName()); fluent.withReady(instance.getReady()); fluent.withRestartCount(instance.getRestartCount()); fluent.withState(instance.getState()); this.validationEnabled = validationEnabled; } public ContainerStatusBuilder(ContainerStatus instance){
public ContainerStatusBuilder( ContainerStatusFluent<?> fluent , ContainerStatus instance ){ this.fluent = fluent; fluent.withContainerID(instance.getContainerID()); fluent.withImage(instance.getImage()); fluent.withImageID(instance.getImageID()); fluent.withLastState(instance.getLastState()); fluent.withName(instance.getName()); fluent.withReady(instance.getReady()); fluent.withRestartCount(instance.getRestartCount()); fluent.withState(instance.getState()); } public ContainerStatusBuilder( ContainerStatus instance ){
public ContainerStatusBuilder( ContainerStatusFluent<?> fluent , ContainerStatus instance ){ this.fluent = fluent; fluent.withContainerID(instance.getContainerID()); fluent.withImage(instance.getImage()); fluent.withImageID(instance.getImageID()); fluent.withLastState(instance.getLastState()); fluent.withName(instance.getName()); fluent.withReady(instance.getReady()); fluent.withRestartCount(instance.getRestartCount()); fluent.withState(instance.getState()); } public ContainerStatusBuilder( ContainerStatus instance ){
public ContainerStatusBuilder( ContainerStatus instance ){ this.fluent = this; this.withContainerID(instance.getContainerID()); this.withImage(instance.getImage()); this.withImageID(instance.getImageID()); this.withLastState(instance.getLastState()); this.withName(instance.getName()); this.withReady(instance.getReady()); this.withRestartCount(instance.getRestartCount()); this.withState(instance.getState()); }
public ContainerStatusBuilder( ContainerStatus instance ){ this.fluent = this; this.withContainerID(instance.getContainerID()); this.withImage(instance.getImage()); this.withImageID(instance.getImageID()); this.withLastState(instance.getLastState()); this.withName(instance.getName()); this.withReady(instance.getReady()); this.withRestartCount(instance.getRestartCount()); this.withState(instance.getState()); }
if (state != null) { ContainerStateWaiting waiting = state.getWaiting(); String containerName = containerStatus.getName(); if (waiting != null) { session.getLogger().warn("Waiting for container:" + containerName + ". Reason:" + waiting.getReason());