use of io.fabric8.kubernetes.api.model.ContainerState in project fabric8 by fabric8io.
the class SessionPodsAreReady method call.
@Override
public Boolean call() throws Exception {
boolean result = true;
List<Pod> pods = notNullList(kubernetesClient.pods().inNamespace(session.getNamespace()).list().getItems());
if (pods.isEmpty()) {
result = false;
session.getLogger().warn("No pods are available yet, waiting...");
}
for (Pod pod : pods) {
if (!KubernetesHelper.isPodReady(pod)) {
PodStatus podStatus = pod.getStatus();
int restartCount = 0;
if (podStatus != null) {
if ("Succeeded".equals(podStatus.getPhase())) {
// that have finished. see: OSFUSE-317
continue;
}
List<ContainerStatus> containerStatuses = podStatus.getContainerStatuses();
for (ContainerStatus containerStatus : containerStatuses) {
if (restartCount == 0) {
Integer restartCountValue = containerStatus.getRestartCount();
if (restartCountValue != null) {
restartCount = restartCountValue.intValue();
}
}
ContainerState state = containerStatus.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());
} else {
session.getLogger().warn("Waiting for container:" + containerName + ".");
}
}
}
}
result = false;
String name = KubernetesHelper.getName(pod);
File yamlFile = new File(session.getBaseDir(), "target/test-pod-status/" + name + ".yml");
yamlFile.getParentFile().mkdirs();
try {
KubernetesHelper.saveYaml(pod, yamlFile);
} catch (IOException e) {
session.getLogger().warn("Failed to write " + yamlFile + ". " + e);
}
if (KubernetesHelper.isPodRunning(pod)) {
List<Container> containers = pod.getSpec().getContainers();
for (Container container : containers) {
File logFile = LogHelpers.getLogFileName(session.getBaseDir(), name, container, restartCount);
String log = kubernetesClient.pods().inNamespace(session.getNamespace()).withName(name).inContainer(container.getName()).getLog();
IOHelpers.writeFully(logFile, log);
}
}
}
}
return result;
}
Aggregations