class KubeUtil {

    public static Optional<Long> findFinishedTimestamp(V1Pod pod) {
        if (pod.getStatus() == null || pod.getStatus().getContainerStatuses() == null) {
            return Optional.empty();
        }
        return pod.getStatus().getContainerStatuses().stream()
                .filter(status -> status.getState() != null && status.getState().getTerminated() != null && status.getState().getTerminated().getFinishedAt() != null)
                .findFirst()
                .map(terminatedState -> terminatedState.getState().getTerminated().getFinishedAt().getMillis());
    }

}