private Pod getNewestPod(List<Pod> items) { Pod targetPod = null; if (items != null) { for (Pod pod : items) { if (KubernetesHelper.isPodWaiting(pod) || KubernetesHelper.isPodRunning(pod)) { if (targetPod == null || (KubernetesHelper.isPodReady(pod) && KubernetesResourceUtil.isNewerResource(pod, targetPod))) { targetPod = pod; } } } } return targetPod; }
/** * Returns true if the pod is running and ready */ public static boolean isPodReady(Pod pod) { if (!isPodRunning(pod)) { return false; } PodStatus podStatus = pod.getStatus(); if (podStatus == null) { return true; } List<PodCondition> conditions = podStatus.getConditions(); if (conditions == null || conditions.isEmpty()) { return true; } // Check "ready" condition for (PodCondition condition : conditions) { if ("ready".equalsIgnoreCase(condition.getType())) { return Boolean.parseBoolean(condition.getStatus()); } } return true; }
@Override public void eventReceived(Watcher.Action action, Pod pod) { podWaitLog.info(getName(pod) + " status: " + getPodStatusDescription(pod) + getPodStatusMessagePostfix(action)); if (isAddOrModified(action) && KubernetesHelper.isPodRunning(pod) && KubernetesHelper.isPodReady(pod) && podHasEnvVars(pod, envVars)) { foundPod = pod; terminateLatch.countDown(); } }
private void onPod(Watcher.Action action, Pod pod, KubernetesClient kubernetes, String namespace, String ctrlCMessage, boolean followLog) { String name = KubernetesHelper.getName(pod); if (action.equals(Watcher.Action.DELETED)) { addedPods.remove(name); if (Objects.equals(watchingPodName, name)) { watchingPodName = null; addedPods.remove(name); } } else { if (action.equals(Watcher.Action.ADDED) || action.equals(Watcher.Action.MODIFIED)) { addedPods.put(name, pod); } } Pod watchPod = KubernetesResourceUtil.getNewestPod(addedPods.values()); newestPodName = KubernetesHelper.getName(watchPod); Logger statusLog = Objects.equals(name, newestPodName) ? context.getNewPodLog() : context.getOldPodLog(); if (!action.equals(Watcher.Action.MODIFIED) || watchingPodName == null || !watchingPodName.equals(name)) { statusLog.info("%s status: %s%s", name, getPodStatusDescription(pod), getPodStatusMessagePostfix(action)); } if (watchPod != null && KubernetesHelper.isPodRunning(watchPod)) { watchLogOfPodName(kubernetes, namespace, ctrlCMessage, followLog, watchPod, KubernetesHelper.getName(watchPod)); } }
if (items != null) { for (Pod pod : items) { if (KubernetesHelper.isPodRunning(pod) || KubernetesHelper.isPodWaiting(pod)) { if (latestPod == null || KubernetesResourceUtil.isNewerResource(pod, latestPod)) { if (ignorePodsOlderThan != null) {