Source:
<code>private void handleStartingPodStatus(CompletableFuture<Void> podRunningFuture, Pod pod) { PodStatus status = pod.getStatus(); String podPhase = status.getPhase(); if (POD_STATUS_PHASE_RUNNING.equals(podPhase)) { Map<String, String> terminatedContainers = new HashMap<>(); <START> for (ContainerStatus cs : status.getContainerStatuses()) { <END> ContainerStateTerminated terminated = cs.getState().getTerminated(); if (terminated != null) { terminatedContainers.put( cs.getName(), "reason = " + terminated.getReason() + ", message = " + terminated.getMessage()); } } if (terminatedContainers.isEmpty()) { podRunningFuture.complete(null); } else { String errorMessage = "The following containers have terminated:\n" + terminatedContainers .entrySet() .stream() .map(e -> e.getKey() + ": " + e.getValue()) .collect(Collectors.joining("" + "\n")); podRunningFuture.completeExceptionally(new InfrastructureException(errorMessage)); } return; } if (POD_STATUS_PHASE_SUCCEEDED.equals(podPhase)) { podRunningFuture.completeExceptionally( new InfrastructureException( "Pod container has been terminated. Container must be configured to use a non-terminating command.")); return; } if (POD_STATUS_PHASE_FAILED.equals(podPhase)) { String exceptionMessage = "Pod '" + pod.getMetadata().getName() + "' failed to start."; String reason = pod.getStatus().getReason(); if (Strings.isNullOrEmpty(reason)) { try { String podLog = clientFactory .create(workspaceId) .pods() .inNamespace(namespace) .withName(pod.getMetadata().getName()) .getLog(); exceptionMessage = exceptionMessage.concat(" Pod logs: ").concat(podLog); } catch (InfrastructureException | KubernetesClientException e) { exceptionMessage = exceptionMessage.concat(" Error occurred while fetching pod logs: " + e.getMessage()); } } else { exceptionMessage = exceptionMessage.concat(" Reason: ").concat(reason); } podRunningFuture.completeExceptionally(new InfrastructureException(exceptionMessage)); LOG.warn(exceptionMessage); } }</code><technical_language>imho stream here</technical_language>

Target:
private void handleStartingPodStatus(CompletableFuture<Void> podRunningFuture, Pod pod) { PodStatus status = pod.getStatus(); String podPhase = status.getPhase(); if (POD_STATUS_PHASE_RUNNING.equals(podPhase)) { Map<String, String> terminatedContainers = new HashMap<>(); for (ContainerStatus cs : status.getContainerStatuses()) { ContainerStateTerminated terminated = cs.getState().getTerminated(); if (terminated != null) { terminatedContainers.put( cs.getName(), format( "reason = '%s', exit code = %d, message = '%s'", terminated.getReason(), terminated.getExitCode(), terminated.getMessage())); } } if (terminatedContainers.isEmpty()) { podRunningFuture.complete(null); } else { String errorMessage = "The following containers have terminated:\n" + terminatedContainers .entrySet() .stream() .map(e -> e.getKey() + ": " + e.getValue()) .collect(Collectors.joining("" + "\n")); podRunningFuture.completeExceptionally(new InfrastructureException(errorMessage)); } return; } if (POD_STATUS_PHASE_SUCCEEDED.equals(podPhase)) { podRunningFuture.completeExceptionally( new InfrastructureException( "Pod container has been terminated. Container must be configured to use a non-terminating command.")); return; } if (POD_STATUS_PHASE_FAILED.equals(podPhase)) { String exceptionMessage = "Pod '" + pod.getMetadata().getName() + "' failed to start."; String reason = pod.getStatus().getReason(); if (Strings.isNullOrEmpty(reason)) { try { String podLog = clientFactory .create(workspaceId) .pods() .inNamespace(namespace) .withName(pod.getMetadata().getName()) .getLog(); exceptionMessage = exceptionMessage.concat(" Pod logs: ").concat(podLog); } catch (InfrastructureException | KubernetesClientException e) { exceptionMessage = exceptionMessage.concat(" Error occurred while fetching pod logs: " + e.getMessage()); } } else { exceptionMessage = exceptionMessage.concat(" Reason: ").concat(reason); } podRunningFuture.completeExceptionally(new InfrastructureException(exceptionMessage)); LOG.warn(exceptionMessage); } }