@Test void podIsUnknownToJobManagement() { when(kubeControllerConfiguration.getPodUnknownGracePeriodMs()).thenReturn(POD_UNKNOWN_GRACE_PERIOD); V1Pod pod = new V1Pod() .metadata(new V1ObjectMeta().name(POD_NAME).creationTimestamp(new DateTime(clock.wallTime()))) .status(new V1PodStatus().phase(RUNNING)); clock.advanceTime(Duration.ofMillis(POD_UNKNOWN_GRACE_PERIOD + 1)); Map<String, Task> currentTasks = Collections.singletonMap("", mock(Task.class)); Assertions.assertThat(podGcController.isPodUnknownToJobManagement(pod, currentTasks)).isTrue(); }
@VisibleForTesting boolean isPodUnknownToJobManagement(V1Pod pod, Map<String, Task> currentTasks) { V1ObjectMeta metadata = pod.getMetadata(); V1PodStatus status = pod.getStatus(); if (metadata == null || status == null) { return true; } if (KubeUtil.isPodPhaseTerminal(status.getPhase()) || currentTasks.containsKey(metadata.getName())) { return false; } DateTime creationTimestamp = metadata.getCreationTimestamp(); return creationTimestamp != null && clock.isPast(creationTimestamp.getMillis() + kubeControllerConfiguration.getPodUnknownGracePeriodMs()); }
PodUnknownGcController extends BaseGcController<V1Pod> { @VisibleForTesting boolean isPodUnknownToJobManagement(V1Pod pod, Map<String, Task> currentTasks) { V1ObjectMeta metadata = pod.getMetadata(); V1PodStatus status = pod.getStatus(); if (metadata == null || status == null) { return true; } if (KubeUtil.isPodPhaseTerminal(status.getPhase()) || currentTasks.containsKey(metadata.getName())) { return false; } DateTime creationTimestamp = metadata.getCreationTimestamp(); return creationTimestamp != null && clock.isPast(creationTimestamp.getMillis() + kubeControllerConfiguration.getPodUnknownGracePeriodMs()); } }
PodUnknownGcController extends BaseGcController<V1Pod> { @VisibleForTesting boolean isPodUnknownToJobManagement(V1Pod pod, Map<String, Task> currentTasks) { V1ObjectMeta metadata = pod.getMetadata(); V1PodStatus status = pod.getStatus(); if (metadata == null || status == null) { return true; } if (KubeUtil.isPodPhaseTerminal(status.getPhase()) || currentTasks.containsKey(metadata.getName())) { return false; } DateTime creationTimestamp = metadata.getCreationTimestamp(); return creationTimestamp != null && clock.isPast(creationTimestamp.getMillis() + kubeControllerConfiguration.getPodUnknownGracePeriodMs()); } @Inject  PodUnknownGcController(
            TitusRuntime titusRuntime,
            LocalScheduler scheduler,
            @Named(POD_UNKNOWN_GC_CONTROLLER) FixedIntervalTokenBucketConfiguration tokenBucketConfiguration,
            @Named(POD_UNKNOWN_GC_CONTROLLER) ControllerConfiguration controllerConfiguration,
            KubeApiFacade kubeApiFacade,
            KubeControllerConfiguration kubeControllerConfiguration,
            V3JobOperations v3JobOperations
    ); }
PodUnknownGcController extends BaseGcController<V1Pod> { @VisibleForTesting boolean isPodUnknownToJobManagement(V1Pod pod, Map<String, Task> currentTasks) { V1ObjectMeta metadata = pod.getMetadata(); V1PodStatus status = pod.getStatus(); if (metadata == null || status == null) { return true; } if (KubeUtil.isPodPhaseTerminal(status.getPhase()) || currentTasks.containsKey(metadata.getName())) { return false; } DateTime creationTimestamp = metadata.getCreationTimestamp(); return creationTimestamp != null && clock.isPast(creationTimestamp.getMillis() + kubeControllerConfiguration.getPodUnknownGracePeriodMs()); } @Inject  PodUnknownGcController(
            TitusRuntime titusRuntime,
            LocalScheduler scheduler,
            @Named(POD_UNKNOWN_GC_CONTROLLER) FixedIntervalTokenBucketConfiguration tokenBucketConfiguration,
            @Named(POD_UNKNOWN_GC_CONTROLLER) ControllerConfiguration controllerConfiguration,
            KubeApiFacade kubeApiFacade,
            KubeControllerConfiguration kubeControllerConfiguration,
            V3JobOperations v3JobOperations
    ); @Override boolean shouldGc(); @Override List<V1Pod> getItemsToGc(); @Override boolean gcItem(V1Pod item); }
PodUnknownGcController extends BaseGcController<V1Pod> { @VisibleForTesting boolean isPodUnknownToJobManagement(V1Pod pod, Map<String, Task> currentTasks) { V1ObjectMeta metadata = pod.getMetadata(); V1PodStatus status = pod.getStatus(); if (metadata == null || status == null) { return true; } if (KubeUtil.isPodPhaseTerminal(status.getPhase()) || currentTasks.containsKey(metadata.getName())) { return false; } DateTime creationTimestamp = metadata.getCreationTimestamp(); return creationTimestamp != null && clock.isPast(creationTimestamp.getMillis() + kubeControllerConfiguration.getPodUnknownGracePeriodMs()); } @Inject  PodUnknownGcController(
            TitusRuntime titusRuntime,
            LocalScheduler scheduler,
            @Named(POD_UNKNOWN_GC_CONTROLLER) FixedIntervalTokenBucketConfiguration tokenBucketConfiguration,
            @Named(POD_UNKNOWN_GC_CONTROLLER) ControllerConfiguration controllerConfiguration,
            KubeApiFacade kubeApiFacade,
            KubeControllerConfiguration kubeControllerConfiguration,
            V3JobOperations v3JobOperations
    ); @Override boolean shouldGc(); @Override List<V1Pod> getItemsToGc(); @Override boolean gcItem(V1Pod item); static final String POD_UNKNOWN_GC_CONTROLLER; static final String POD_UNKNOWN_GC_CONTROLLER_DESCRIPTION; }