class PodOperationUtil {
  private static final Logger LOG = LoggerFactory.getLogger(PodOperationUtil.class);

  private PodOperationUtil() {
  }

  /**
   * Gets PodOperations for Pods specific to a controller
   *
   * @param podOperations {@link PodOperationsImpl} generic PodOperations class without any pod configured
   * @param controllerPodList List of pods based on a label that are related to a Controller
   * @param controllerUid UID of Controller
   * @return returns list of PodOperations with pods whose owner's UID is of the provided controller
   */
  public static List<PodResource> getFilteredPodsForLogs(PodOperationsImpl podOperations, PodList controllerPodList,
      String controllerUid) {
    List<PodResource> pods = new ArrayList<>();
    for (Pod pod : controllerPodList.getItems()) {
      OwnerReference ownerReference = KubernetesResourceUtil.getControllerUid(pod);
      if (ownerReference != null && ownerReference.getUid().equals(controllerUid)) {
        pods.add(podOperations.withName(pod.getMetadata().getName()));
      }
    }
    return pods;
  }

  public static PodOperationsImpl getGenericPodOperations(OperationContext context, PodOperationContext podOperationContext) {
    return new PodOperationsImpl(
        podOperationContext,
        context.withName(null).withApiGroupName(null).withApiGroupVersion("v1"));
  }

  public static List<PodResource> getPodOperationsForController(OperationContext context,
      PodOperationContext podOperationContext, String controllerUid, Map<String, String> selectorLabels) {
    return getPodOperationsForController(
        PodOperationUtil.getGenericPodOperations(context, podOperationContext), controllerUid,
        selectorLabels);
  }

  public static LogWatch watchLog(List<PodResource> podResources, OutputStream out) {
    return findFirstPodResource(podResources).map(it -> it.watchLog(out)).orElse(null);
  }

  public static Reader getLogReader(List<PodResource> podResources) {
    return findFirstPodResource(podResources).map(Loggable::getLogReader).orElse(null);
  }

  public static InputStream getLogInputStream(List<PodResource> podResources) {
    return findFirstPodResource(podResources).map(Loggable::getLogInputStream).orElse(null);
  }

  private static Optional<PodResource> findFirstPodResource(List<PodResource> podResources) {
    if (!podResources.isEmpty()) {
      if (podResources.size() > 1) {
        LOG.debug("Found {} pods, Using first one to get log", podResources.size());
      }
      return Optional.ofNullable(podResources.get(0));
    }
    return Optional.empty();
  }

  public static String getLog(List<PodResource> podOperationList, Boolean isPretty) {
    StringBuilder stringBuilder = new StringBuilder();
    for (PodResource podOperation : podOperationList) {
      stringBuilder.append(podOperation.getLog(isPretty));
    }
    return stringBuilder.toString();
  }

  public static List<PodResource> getPodOperationsForController(PodOperationsImpl podOperations, String controllerUid,
      Map<String, String> selectorLabels) {
    PodList controllerPodList = podOperations.withLabels(selectorLabels).list();

    return PodOperationUtil.getFilteredPodsForLogs(podOperations, controllerPodList, controllerUid);
  }

  public static Pod waitUntilReadyOrTerminal(PodResource podOperation, int logWaitTimeoutMs) {<FILL_FUNCTION_BODY>}

  static boolean isReadyOrTerminal(Pod p) {
    // we'll treat missing as an exit condition - there's no expectation that we should wait for a pod that doesn't exist
    return p == null || Readiness.isPodReady(p) || Optional.ofNullable(p.getStatus()).map(PodStatus::getPhase)
        .filter(phase -> !Arrays.asList("Pending", "Unknown").contains(phase)).isPresent();
  }
}

    AtomicReference<Pod> podRef = new AtomicReference<>();
    try {
      // Wait for Pod to become ready or succeeded
      podOperation.waitUntilCondition(p -> {
        podRef.set(p);
        return isReadyOrTerminal(p);
      },
          logWaitTimeoutMs,
          TimeUnit.MILLISECONDS);
    } catch (KubernetesClientTimeoutException timeout) {
      LOG.debug("Timed out waiting for Pod to become Ready: {}, will still proceed", timeout.getMessage());
    } catch (Exception otherException) {
      LOG.warn("Error while waiting for Pod to become Ready", otherException);
    }
    return podRef.get();
  
<no_super_class>