@Test public void testInvalidTimeFormatString() { Assert.assertFalse( reapPodLookupFilter.isPodPastAge( createPod("thePod", PodPhase.FAILED, createStatus("invalid time string")), REAP_UPPER_BOUND_UTC)); }
protected static boolean isPodPastAge(Pod pod, Instant reapUpperBoundUTC) { String finishedAtString; if(pod.getStatus().getContainerStatuses() != null && pod.getStatus().getContainerStatuses().size() > 0) { finishedAtString = pod.getStatus().getContainerStatuses().get(0).getState().getTerminated().getFinishedAt(); } else { logger.warn("Abnormal pod exit detected. Using start time for reap evaluation. Pod={} ExitReason={}", pod.getMetadata().getName(), pod.getStatus().getReason()); finishedAtString = pod.getStatus().getStartTime(); } Instant finishedInstant; try { finishedInstant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(finishedAtString)); } catch(DateTimeParseException e) { logger.error("Failed to parse the finished time [{}]. Skipping reap for pod={}", finishedAtString, pod.getMetadata().getName()); return false; } return InstantUtil.isAfterOrEqual(reapUpperBoundUTC, finishedInstant); }
ReapPodLookupFilter implements Producer<Pod> { protected static boolean isPodPastAge(Pod pod, Instant reapUpperBoundUTC) { String finishedAtString; if(pod.getStatus().getContainerStatuses() != null && pod.getStatus().getContainerStatuses().size() > 0) { finishedAtString = pod.getStatus().getContainerStatuses().get(0).getState().getTerminated().getFinishedAt(); } else { logger.warn("Abnormal pod exit detected. Using start time for reap evaluation. Pod={} ExitReason={}", pod.getMetadata().getName(), pod.getStatus().getReason()); finishedAtString = pod.getStatus().getStartTime(); } Instant finishedInstant; try { finishedInstant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(finishedAtString)); } catch(DateTimeParseException e) { logger.error("Failed to parse the finished time [{}]. Skipping reap for pod={}", finishedAtString, pod.getMetadata().getName()); return false; } return InstantUtil.isAfterOrEqual(reapUpperBoundUTC, finishedInstant); } }
ReapPodLookupFilter implements Producer<Pod> { protected static boolean isPodPastAge(Pod pod, Instant reapUpperBoundUTC) { String finishedAtString; if(pod.getStatus().getContainerStatuses() != null && pod.getStatus().getContainerStatuses().size() > 0) { finishedAtString = pod.getStatus().getContainerStatuses().get(0).getState().getTerminated().getFinishedAt(); } else { logger.warn("Abnormal pod exit detected. Using start time for reap evaluation. Pod={} ExitReason={}", pod.getMetadata().getName(), pod.getStatus().getReason()); finishedAtString = pod.getStatus().getStartTime(); } Instant finishedInstant; try { finishedInstant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(finishedAtString)); } catch(DateTimeParseException e) { logger.error("Failed to parse the finished time [{}]. Skipping reap for pod={}", finishedAtString, pod.getMetadata().getName()); return false; } return InstantUtil.isAfterOrEqual(reapUpperBoundUTC, finishedInstant); } ReapPodLookupFilter(KubernetesPodFacade kubernetesPodFacade, Instant reapUpperBoundUTC); }
ReapPodLookupFilter implements Producer<Pod> { protected static boolean isPodPastAge(Pod pod, Instant reapUpperBoundUTC) { String finishedAtString; if(pod.getStatus().getContainerStatuses() != null && pod.getStatus().getContainerStatuses().size() > 0) { finishedAtString = pod.getStatus().getContainerStatuses().get(0).getState().getTerminated().getFinishedAt(); } else { logger.warn("Abnormal pod exit detected. Using start time for reap evaluation. Pod={} ExitReason={}", pod.getMetadata().getName(), pod.getStatus().getReason()); finishedAtString = pod.getStatus().getStartTime(); } Instant finishedInstant; try { finishedInstant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(finishedAtString)); } catch(DateTimeParseException e) { logger.error("Failed to parse the finished time [{}]. Skipping reap for pod={}", finishedAtString, pod.getMetadata().getName()); return false; } return InstantUtil.isAfterOrEqual(reapUpperBoundUTC, finishedInstant); } ReapPodLookupFilter(KubernetesPodFacade kubernetesPodFacade, Instant reapUpperBoundUTC); ReapPodLookupFilter withPodPhases(PodPhase... podPhases); ReapPodLookupFilter withNamespace(String namespace); @Override ProducerResult<Pod> produce(Instant processEndTime); @Override void reset(); @Override String toString(); }
ReapPodLookupFilter implements Producer<Pod> { protected static boolean isPodPastAge(Pod pod, Instant reapUpperBoundUTC) { String finishedAtString; if(pod.getStatus().getContainerStatuses() != null && pod.getStatus().getContainerStatuses().size() > 0) { finishedAtString = pod.getStatus().getContainerStatuses().get(0).getState().getTerminated().getFinishedAt(); } else { logger.warn("Abnormal pod exit detected. Using start time for reap evaluation. Pod={} ExitReason={}", pod.getMetadata().getName(), pod.getStatus().getReason()); finishedAtString = pod.getStatus().getStartTime(); } Instant finishedInstant; try { finishedInstant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(finishedAtString)); } catch(DateTimeParseException e) { logger.error("Failed to parse the finished time [{}]. Skipping reap for pod={}", finishedAtString, pod.getMetadata().getName()); return false; } return InstantUtil.isAfterOrEqual(reapUpperBoundUTC, finishedInstant); } ReapPodLookupFilter(KubernetesPodFacade kubernetesPodFacade, Instant reapUpperBoundUTC); ReapPodLookupFilter withPodPhases(PodPhase... podPhases); ReapPodLookupFilter withNamespace(String namespace); @Override ProducerResult<Pod> produce(Instant processEndTime); @Override void reset(); @Override String toString(); static final int DEFAULT_POD_REAP_AGE_MINUTES; }