use of io.fabric8.kubernetes.api.model.ContainerStateTerminated in project flink by splunk.
the class KubernetesPod method getTerminatedDiagnostics.
public String getTerminatedDiagnostics() {
final StringBuilder sb = new StringBuilder();
sb.append("Pod terminated, container termination statuses: [");
if (getInternalResource().getStatus() != null) {
sb.append(getInternalResource().getStatus().getContainerStatuses().stream().filter(containerStatus -> containerStatus.getState() != null && containerStatus.getState().getTerminated() != null).map((containerStatus) -> {
final ContainerStateTerminated containerStateTerminated = containerStatus.getState().getTerminated();
return String.format("%s(exitCode=%d, reason=%s, message=%s)", containerStatus.getName(), containerStateTerminated.getExitCode(), containerStateTerminated.getReason(), containerStateTerminated.getMessage());
}).collect(Collectors.joining(",")));
}
sb.append("]");
if (PodPhase.Failed.name().equals(getInternalResource().getStatus().getPhase())) {
sb.append(String.format(", pod status: %s(reason=%s, message=%s)", getInternalResource().getStatus().getPhase(), getInternalResource().getStatus().getReason(), getInternalResource().getStatus().getMessage()));
}
return sb.toString();
}
use of io.fabric8.kubernetes.api.model.ContainerStateTerminated in project kubernetes-client by fabric8io.
the class PodStatusUtilTest method isInitializing_should_return_false_if_pod_has_initContainerStatus_with_state_with_exit_code_0.
@Test
public void isInitializing_should_return_false_if_pod_has_initContainerStatus_with_state_with_exit_code_0() {
// given
Pod pod = pod("some pod").statusBuilder().initContainerStatuses(containerStatus(false, containerState(containerStateTerminated(0, null), null, null))).build().build();
// when
boolean initializing = PodStatusUtil.isInitializing(pod);
// then
assertThat(initializing).isFalse();
}
use of io.fabric8.kubernetes.api.model.ContainerStateTerminated in project kubernetes-client by fabric8io.
the class PodStatusUtilTest method isRunning_should_return_true_if_pod_has_running_container_and_another_that_is_completed_and_ready_condition_is_true.
@Test
public void isRunning_should_return_true_if_pod_has_running_container_and_another_that_is_completed_and_ready_condition_is_true() {
// given
Pod pod = pod("some pod").statusBuilder().containerStatuses(runningReady, containerStatus(false, containerState(containerStateTerminated(null, "Completed"), null, null))).podConditions(condition("Ready", "true")).build().build();
// when
boolean running = PodStatusUtil.isRunning(pod);
// then
assertThat(running).isTrue();
}
use of io.fabric8.kubernetes.api.model.ContainerStateTerminated in project kubernetes-client by fabric8io.
the class PodStatusUtilTest method isRunning_should_return_false_if_pod_has_running_container_and_another_that_is_completed_and_ready_condition_is_false.
@Test
public void isRunning_should_return_false_if_pod_has_running_container_and_another_that_is_completed_and_ready_condition_is_false() {
// given
Pod pod = pod("some pod").statusBuilder().containerStatuses(runningReady, containerStatus(false, containerState(containerStateTerminated(null, "Completed"), null, null))).podConditions(condition("Ready", "false")).build().build();
// when
boolean running = PodStatusUtil.isRunning(pod);
// then
assertThat(running).isFalse();
}
use of io.fabric8.kubernetes.api.model.ContainerStateTerminated in project styx by spotify.
the class KubernetesPodEventTranslator method isInErrorState.
private static Optional<Event> isInErrorState(WorkflowInstance workflowInstance, Pod pod, Optional<ContainerStatus> mainContainerStatusOpt) {
final PodStatus status = pod.getStatus();
final String phase = status.getPhase();
if ("NodeLost".equals(pod.getStatus().getReason())) {
return Optional.of(Event.runError(workflowInstance, "Lost node running pod"));
}
switch(phase) {
case "Pending":
// check if one or more docker contains failed to pull their image, a possible silent error
return mainContainerStatusOpt.flatMap(KubernetesPodEventTranslator::imageError).map(msg -> Event.runError(workflowInstance, msg));
case "Succeeded":
case "Failed":
if (mainContainerStatusOpt.isEmpty()) {
return Optional.of(Event.runError(workflowInstance, "Could not find our container in pod"));
}
final ContainerStatus containerStatus = mainContainerStatusOpt.get();
final ContainerStateTerminated terminated = containerStatus.getState().getTerminated();
if (terminated == null) {
return Optional.of(Event.runError(workflowInstance, "Unexpected null terminated status"));
}
return Optional.empty();
case "Unknown":
return Optional.of(Event.runError(workflowInstance, "Pod entered Unknown phase"));
default:
return Optional.empty();
}
}
Aggregations