PodDeletionGcController extends BaseGcController<V1Pod> { @VisibleForTesting boolean isPodInPendingPhaseWithDeletionTimestamp(V1Pod pod) { if (pod == null || pod.getMetadata() == null || pod.getStatus() == null) { return false; } DateTime deletionTimestamp = pod.getMetadata().getDeletionTimestamp(); return deletionTimestamp != null && PENDING.equalsIgnoreCase(pod.getStatus().getPhase()); } @Inject  PodDeletionGcController(
            TitusRuntime titusRuntime,
            LocalScheduler scheduler,
            @Named(POD_DELETION_GC_CONTROLLER) FixedIntervalTokenBucketConfiguration tokenBucketConfiguration,
            @Named(POD_DELETION_GC_CONTROLLER) ControllerConfiguration controllerConfiguration,
            KubeApiFacade kubeApiFacade,
            KubeControllerConfiguration kubeControllerConfiguration
    ); @Override boolean shouldGc(); @Override List<V1Pod> getItemsToGc(); @Override boolean gcItem(V1Pod item); static final String POD_DELETION_GC_CONTROLLER; static final String POD_DELETION_GC_CONTROLLER_DESCRIPTION; }
@Test void podIsPendingPhaseWithDeletionTimestamp() { V1Pod pod = new V1Pod() .metadata( new V1ObjectMeta() .name(POD_NAME) .deletionTimestamp(new DateTime(clock.wallTime())) ) .spec(new V1PodSpec()) .status(new V1PodStatus().phase(PENDING)); Assertions.assertThat(podDeletionGcController.isPodInPendingPhaseWithDeletionTimestamp(pod)).isTrue(); }
@Test void podIsInRunningPhaseWithDeletionTimestamp() { V1Pod pod = new V1Pod() .metadata( new V1ObjectMeta() .name(POD_NAME) .deletionTimestamp(new DateTime(clock.wallTime())) ) .spec(new V1PodSpec()) .status(new V1PodStatus().phase(RUNNING)); Assertions.assertThat(podDeletionGcController.isPodInPendingPhaseWithDeletionTimestamp(pod)).isFalse(); }
@Test void podDoesNotHaveDeletionTimestamp() { V1Pod pod = new V1Pod() .metadata( new V1ObjectMeta() .name(POD_NAME) ) .spec(new V1PodSpec()) .status(new V1PodStatus().phase(PENDING)); Assertions.assertThat(podDeletionGcController.isPodInPendingPhaseWithDeletionTimestamp(pod)).isFalse(); }