Search in sources :

Example 16 with ContainerStateTerminated

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();
}
Also used : VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) Objects(java.util.Objects) ContainerStateTerminated(io.fabric8.kubernetes.api.model.ContainerStateTerminated) Pod(io.fabric8.kubernetes.api.model.Pod) Collectors(java.util.stream.Collectors) ContainerStateTerminated(io.fabric8.kubernetes.api.model.ContainerStateTerminated)

Example 17 with ContainerStateTerminated

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();
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) Test(org.junit.Test)

Example 18 with ContainerStateTerminated

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();
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) Test(org.junit.Test)

Example 19 with ContainerStateTerminated

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();
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) Test(org.junit.Test)

Example 20 with ContainerStateTerminated

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();
    }
}
Also used : PodStatus(io.fabric8.kubernetes.api.model.PodStatus) KubernetesDockerRunner.getMainContainerStatus(com.spotify.styx.docker.KubernetesDockerRunner.getMainContainerStatus) ContainerStatus(io.fabric8.kubernetes.api.model.ContainerStatus) ByteString(okio.ByteString) ContainerStateTerminated(io.fabric8.kubernetes.api.model.ContainerStateTerminated)

Aggregations

ContainerStateTerminated (io.fabric8.kubernetes.api.model.ContainerStateTerminated)12 Pod (io.fabric8.kubernetes.api.model.Pod)12 Test (org.junit.Test)8 ContainerStatus (io.fabric8.kubernetes.api.model.ContainerStatus)6 ContainerState (io.fabric8.kubernetes.api.model.ContainerState)5 RunState (com.spotify.styx.state.RunState)4 PodStatus (io.fabric8.kubernetes.api.model.PodStatus)4 Objects (java.util.Objects)4 KubernetesPodEventTranslatorTest.terminatedContainerState (com.spotify.styx.docker.KubernetesPodEventTranslatorTest.terminatedContainerState)3 State (com.spotify.styx.state.RunState.State)3 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)3 List (java.util.List)3 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ContainerStateWaiting (io.fabric8.kubernetes.api.model.ContainerStateWaiting)2 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 Build (io.fabric8.openshift.api.model.Build)2 KafkaConnectResources (io.strimzi.api.kafka.model.KafkaConnectResources)2 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)2 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)2