@Test(dataProvider = "testAppendPodsByPhaseStatusProvider") public void testAppendPodsByPhaseStatus(List<Pod> allFailedPods, List<String> expectedReapPodNames) { List<Pod> podResults = new ArrayList<>(); doReturn(allFailedPods).when(mockKubernetesPodFacade).lookupPods(any(), any()); reapPodLookupFilter.appendPodsByPhaseStatusAndAge(PodPhase.FAILED, podResults); Assert.assertTrue(expectedReapPodNames.stream().allMatch( podName -> { boolean found = podResults.stream().anyMatch(pod -> pod.getMetadata().getName().equals(podName)); if(!found) logger.error("Failed to find expected pod from filter: {}", podName); return found; } )); Assert.assertEquals(expectedReapPodNames.size(), podResults.size()); }
protected void appendPodsByPhaseStatusAndAge(PodPhase podPhase, List<Pod> resultPods) { List<Pod> pods = kubernetesPodFacade.lookupPods(namespace, Collections.singletonMap(STATUS_PHASE, podPhase.getLabel())); pods.stream() .filter(ReapPodLookupFilter::allContainerStatusesTerminated) .forEach(pod -> { FinalPodPhaseInfo podPhaseInfo = FinalPodPhaseInfo.fromPodStatus(pod.getMetadata().getName(), pod.getStatus()); if(podPhaseInfo.phase.hasFinished()) { if(isPodPastAge(pod, reapUpperBoundUTC)) resultPods.add(pod); } }); }
ReapPodLookupFilter implements Producer<Pod> { protected void appendPodsByPhaseStatusAndAge(PodPhase podPhase, List<Pod> resultPods) { List<Pod> pods = kubernetesPodFacade.lookupPods(namespace, Collections.singletonMap(STATUS_PHASE, podPhase.getLabel())); pods.stream() .filter(ReapPodLookupFilter::allContainerStatusesTerminated) .forEach(pod -> { FinalPodPhaseInfo podPhaseInfo = FinalPodPhaseInfo.fromPodStatus(pod.getMetadata().getName(), pod.getStatus()); if(podPhaseInfo.phase.hasFinished()) { if(isPodPastAge(pod, reapUpperBoundUTC)) resultPods.add(pod); } }); } }
ReapPodLookupFilter implements Producer<Pod> { protected void appendPodsByPhaseStatusAndAge(PodPhase podPhase, List<Pod> resultPods) { List<Pod> pods = kubernetesPodFacade.lookupPods(namespace, Collections.singletonMap(STATUS_PHASE, podPhase.getLabel())); pods.stream() .filter(ReapPodLookupFilter::allContainerStatusesTerminated) .forEach(pod -> { FinalPodPhaseInfo podPhaseInfo = FinalPodPhaseInfo.fromPodStatus(pod.getMetadata().getName(), pod.getStatus()); if(podPhaseInfo.phase.hasFinished()) { if(isPodPastAge(pod, reapUpperBoundUTC)) resultPods.add(pod); } }); } ReapPodLookupFilter(KubernetesPodFacade kubernetesPodFacade, Instant reapUpperBoundUTC); }
ReapPodLookupFilter implements Producer<Pod> { protected void appendPodsByPhaseStatusAndAge(PodPhase podPhase, List<Pod> resultPods) { List<Pod> pods = kubernetesPodFacade.lookupPods(namespace, Collections.singletonMap(STATUS_PHASE, podPhase.getLabel())); pods.stream() .filter(ReapPodLookupFilter::allContainerStatusesTerminated) .forEach(pod -> { FinalPodPhaseInfo podPhaseInfo = FinalPodPhaseInfo.fromPodStatus(pod.getMetadata().getName(), pod.getStatus()); if(podPhaseInfo.phase.hasFinished()) { if(isPodPastAge(pod, reapUpperBoundUTC)) resultPods.add(pod); } }); } 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 void appendPodsByPhaseStatusAndAge(PodPhase podPhase, List<Pod> resultPods) { List<Pod> pods = kubernetesPodFacade.lookupPods(namespace, Collections.singletonMap(STATUS_PHASE, podPhase.getLabel())); pods.stream() .filter(ReapPodLookupFilter::allContainerStatusesTerminated) .forEach(pod -> { FinalPodPhaseInfo podPhaseInfo = FinalPodPhaseInfo.fromPodStatus(pod.getMetadata().getName(), pod.getStatus()); if(podPhaseInfo.phase.hasFinished()) { if(isPodPastAge(pod, reapUpperBoundUTC)) resultPods.add(pod); } }); } 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; }