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();
}
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();
}
}
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");
}
});
}
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");
}
});
}
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();
}
Aggregations