Search in sources :

Example 11 with ContainerStateTerminated

use of io.fabric8.kubernetes.api.model.ContainerStateTerminated in project flink-mirror by flink-ci.

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 12 with ContainerStateTerminated

use of io.fabric8.kubernetes.api.model.ContainerStateTerminated in project zalenium by zalando.

the class KubernetesContainerClient method isTerminated.

public boolean isTerminated(ContainerCreationStatus container) {
    Pod pod = client.pods().withName(container.getContainerName()).get();
    if (pod == null) {
        logger.info("Container {} has no pod - terminal.", container);
        return true;
    } else {
        List<ContainerStatus> containerStatuses = pod.getStatus().getContainerStatuses();
        Optional<ContainerStateTerminated> terminated = containerStatuses.stream().flatMap(status -> Optional.ofNullable(status.getState()).map(Stream::of).orElse(Stream.empty())).flatMap(state -> Optional.ofNullable(state.getTerminated()).map(Stream::of).orElse(Stream.empty())).findFirst();
        terminated.ifPresent(state -> logger.info("Container {} is {} - terminal.", container, state));
        return terminated.isPresent();
    }
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) PodSecurityContext(io.fabric8.kubernetes.api.model.PodSecurityContext) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) Environment(de.zalando.ep.zalenium.util.Environment) Container(io.fabric8.kubernetes.api.model.Container) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ContainerClientRegistration(de.zalando.ep.zalenium.container.ContainerClientRegistration) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MapInputStreamAdapter(de.zalando.ep.zalenium.streams.MapInputStreamAdapter) TarInputStreamGroupWrapper(de.zalando.ep.zalenium.streams.TarInputStreamGroupWrapper) CompletableFuture(java.util.concurrent.CompletableFuture) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) InetAddress(java.net.InetAddress) HostAlias(io.fabric8.kubernetes.api.model.HostAlias) SecurityContext(io.fabric8.kubernetes.api.model.SecurityContext) Response(okhttp3.Response) ContainerStatus(io.fabric8.kubernetes.api.model.ContainerStatus) ExecListener(io.fabric8.kubernetes.client.dsl.ExecListener) ContainerClient(de.zalando.ep.zalenium.container.ContainerClient) InputStreamGroupIterator(de.zalando.ep.zalenium.streams.InputStreamGroupIterator) Volume(io.fabric8.kubernetes.api.model.Volume) Logger(org.slf4j.Logger) Files(java.nio.file.Files) PodFluent(io.fabric8.kubernetes.api.model.PodFluent) Pod(io.fabric8.kubernetes.api.model.Pod) Toleration(io.fabric8.kubernetes.api.model.Toleration) ExecWatch(io.fabric8.kubernetes.client.dsl.ExecWatch) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) File(java.io.File) CountDownLatch(java.util.concurrent.CountDownLatch) Stream(java.util.stream.Stream) PodList(io.fabric8.kubernetes.api.model.PodList) ContainerStateTerminated(io.fabric8.kubernetes.api.model.ContainerStateTerminated) Paths(java.nio.file.Paths) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ContainerCreationStatus(de.zalando.ep.zalenium.container.ContainerCreationStatus) ContainerStatus(io.fabric8.kubernetes.api.model.ContainerStatus) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) Pod(io.fabric8.kubernetes.api.model.Pod) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) Stream(java.util.stream.Stream) ContainerStateTerminated(io.fabric8.kubernetes.api.model.ContainerStateTerminated)

Example 13 with ContainerStateTerminated

use of io.fabric8.kubernetes.api.model.ContainerStateTerminated in project strimzi by strimzi.

the class ConnectBuildOperator method kubernetesBuildWaitForFinish.

/**
 * Waits for the Kafka Connect build to finish and collects the results from it
 *
 * @param reconciliation        The reconciliation
 * @param namespace             Namespace of the Connect cluster
 * @param connectBuild          KafkaConnectBuild object
 *
 * @return                      Future which completes with the built image when the build is finished (or fails if it fails)
 */
private Future<String> kubernetesBuildWaitForFinish(Reconciliation reconciliation, String namespace, KafkaConnectBuild connectBuild) {
    return podOperator.waitFor(reconciliation, namespace, KafkaConnectResources.buildPodName(connectBuild.getCluster()), "complete", 1_000, connectBuildTimeoutMs, (ignore1, ignore2) -> kubernetesBuildPodFinished(namespace, KafkaConnectResources.buildPodName(connectBuild.getCluster()))).compose(ignore -> podOperator.getAsync(namespace, KafkaConnectResources.buildPodName(connectBuild.getCluster()))).compose(pod -> {
        if (KafkaConnectBuildUtils.buildPodSucceeded(pod)) {
            ContainerStateTerminated state = pod.getStatus().getContainerStatuses().get(0).getState().getTerminated();
            String image = state.getMessage().trim();
            LOGGER.infoCr(reconciliation, "Build completed successfully. New image is {}.", image);
            return Future.succeededFuture(image);
        } else {
            ContainerStateTerminated state = pod.getStatus().getContainerStatuses().get(0).getState().getTerminated();
            LOGGER.warnCr(reconciliation, "Build failed with code {}: {}", state.getExitCode(), state.getMessage());
            return Future.failedFuture("The Kafka Connect build failed");
        }
    });
}
Also used : Annotations(io.strimzi.operator.common.Annotations) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) ServiceAccountOperator(io.strimzi.operator.common.operator.resource.ServiceAccountOperator) BuildOperator(io.strimzi.operator.common.operator.resource.BuildOperator) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) BuildConfigOperator(io.strimzi.operator.common.operator.resource.BuildConfigOperator) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) Build(io.fabric8.openshift.api.model.Build) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) KafkaConnectBuild(io.strimzi.operator.cluster.model.KafkaConnectBuild) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Pod(io.fabric8.kubernetes.api.model.Pod) KafkaConnectDockerfile(io.strimzi.operator.cluster.model.KafkaConnectDockerfile) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Reconciliation(io.strimzi.operator.common.Reconciliation) ImagePullPolicy(io.strimzi.operator.cluster.model.ImagePullPolicy) KafkaConnectBuildUtils(io.strimzi.operator.cluster.model.KafkaConnectBuildUtils) List(java.util.List) Util(io.strimzi.operator.common.Util) ContainerStateTerminated(io.fabric8.kubernetes.api.model.ContainerStateTerminated) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) KafkaConnectResources(io.strimzi.api.kafka.model.KafkaConnectResources) ContainerStateTerminated(io.fabric8.kubernetes.api.model.ContainerStateTerminated)

Example 14 with ContainerStateTerminated

use of io.fabric8.kubernetes.api.model.ContainerStateTerminated in project strimzi-kafka-operator by strimzi.

the class ConnectBuildOperator method kubernetesBuildWaitForFinish.

/**
 * Waits for the Kafka Connect build to finish and collects the results from it
 *
 * @param reconciliation        The reconciliation
 * @param namespace             Namespace of the Connect cluster
 * @param connectBuild          KafkaConnectBuild object
 *
 * @return                      Future which completes with the built image when the build is finished (or fails if it fails)
 */
private Future<String> kubernetesBuildWaitForFinish(Reconciliation reconciliation, String namespace, KafkaConnectBuild connectBuild) {
    return podOperator.waitFor(reconciliation, namespace, KafkaConnectResources.buildPodName(connectBuild.getCluster()), "complete", 1_000, connectBuildTimeoutMs, (ignore1, ignore2) -> kubernetesBuildPodFinished(namespace, KafkaConnectResources.buildPodName(connectBuild.getCluster()))).compose(ignore -> podOperator.getAsync(namespace, KafkaConnectResources.buildPodName(connectBuild.getCluster()))).compose(pod -> {
        if (KafkaConnectBuildUtils.buildPodSucceeded(pod)) {
            ContainerStateTerminated state = pod.getStatus().getContainerStatuses().get(0).getState().getTerminated();
            String image = state.getMessage().trim();
            LOGGER.infoCr(reconciliation, "Build completed successfully. New image is {}.", image);
            return Future.succeededFuture(image);
        } else {
            ContainerStateTerminated state = pod.getStatus().getContainerStatuses().get(0).getState().getTerminated();
            LOGGER.warnCr(reconciliation, "Build failed with code {}: {}", state.getExitCode(), state.getMessage());
            return Future.failedFuture("The Kafka Connect build failed");
        }
    });
}
Also used : Annotations(io.strimzi.operator.common.Annotations) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) ServiceAccountOperator(io.strimzi.operator.common.operator.resource.ServiceAccountOperator) BuildOperator(io.strimzi.operator.common.operator.resource.BuildOperator) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) BuildConfigOperator(io.strimzi.operator.common.operator.resource.BuildConfigOperator) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) Build(io.fabric8.openshift.api.model.Build) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) KafkaConnectBuild(io.strimzi.operator.cluster.model.KafkaConnectBuild) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Pod(io.fabric8.kubernetes.api.model.Pod) KafkaConnectDockerfile(io.strimzi.operator.cluster.model.KafkaConnectDockerfile) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Reconciliation(io.strimzi.operator.common.Reconciliation) ImagePullPolicy(io.strimzi.operator.cluster.model.ImagePullPolicy) KafkaConnectBuildUtils(io.strimzi.operator.cluster.model.KafkaConnectBuildUtils) List(java.util.List) Util(io.strimzi.operator.common.Util) ContainerStateTerminated(io.fabric8.kubernetes.api.model.ContainerStateTerminated) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) KafkaConnectResources(io.strimzi.api.kafka.model.KafkaConnectResources) ContainerStateTerminated(io.fabric8.kubernetes.api.model.ContainerStateTerminated)

Example 15 with ContainerStateTerminated

use of io.fabric8.kubernetes.api.model.ContainerStateTerminated in project flink by apache.

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)

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