PodDeletionGcController extends BaseGcController<V1Pod> { @VisibleForTesting boolean isPodPastDeletionTimestamp(V1Pod pod) { V1PodSpec spec = pod.getSpec(); V1ObjectMeta metadata = pod.getMetadata(); if (spec == null || metadata == null) { return false; } Long terminationGracePeriodSeconds = spec.getTerminationGracePeriodSeconds(); DateTime deletionTimestamp = metadata.getDeletionTimestamp(); if (terminationGracePeriodSeconds == null || deletionTimestamp == null) { return false; } long terminationGracePeriodMs = terminationGracePeriodSeconds * 1000L; return clock.isPast(deletionTimestamp.getMillis() + terminationGracePeriodMs + kubeControllerConfiguration.getPodsPastTerminationGracePeriodMs()); } @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 podIsPastDeletionTimestamp() { V1Pod pod = new V1Pod() .metadata( new V1ObjectMeta() .name(POD_NAME) .deletionTimestamp(new DateTime(clock.wallTime())) ) .spec( new V1PodSpec() .nodeName(NODE_NAME) .terminationGracePeriodSeconds(POD_TERMINATION_GRACE_PERIOD_SEC)) .status(null); clock.advanceTime(Duration.ofMillis(POD_TERMINATION_GRACE_PERIOD_MS + POD_DELETION_TIMESTAMP_GRACE_PERIOD + 1)); Assertions.assertThat(podDeletionGcController.isPodPastDeletionTimestamp(pod)).isTrue(); }
@Test void podIsNotPastDeletionTimestamp() { V1Pod pod = new V1Pod() .metadata( new V1ObjectMeta() .name(POD_NAME) .deletionTimestamp(new DateTime(clock.wallTime())) ) .spec( new V1PodSpec() .nodeName(NODE_NAME) .terminationGracePeriodSeconds(POD_TERMINATION_GRACE_PERIOD_SEC)) .status(null); Assertions.assertThat(podDeletionGcController.isPodPastDeletionTimestamp(pod)).isFalse(); }