PVCSubPathHelper { void createDirs( RuntimeIdentity identity, String workspaceId, String pvcName, Map<String, String> startOptions, String... dirs) { LOG.debug( "Preparing PVC `{}` for workspace `{}`. Directories to create: {}", pvcName, workspaceId, Arrays.toString(dirs)); execute(identity, workspaceId, pvcName, MKDIR_COMMAND_BASE, startOptions, dirs); } @Inject  PVCSubPathHelper(
      @Named("che.infra.kubernetes.pvc.jobs.memorylimit") String jobMemoryLimit,
      @Named("che.infra.kubernetes.pvc.jobs.image") String jobImage,
      @Named("che.infra.kubernetes.pvc.jobs.image.pull_policy") String imagePullPolicy,
      KubernetesNamespaceFactory factory,
      SecurityContextProvisioner securityContextProvisioner,
      ExecutorServiceWrapper executorServiceWrapper,
      RuntimeEventsPublisher eventPublisher);   }
@Test public void testSuccessfullyCreatesWorkspaceDirs() throws Exception { when(podStatus.getPhase()).thenReturn(POD_PHASE_SUCCEEDED); pvcSubPathHelper.createDirs( identity, WORKSPACE_ID, PVC_NAME, emptyMap(), WORKSPACE_ID + PROJECTS_PATH); verify(osDeployments).create(podCaptor.capture()); final List<String> actual = podCaptor.getValue().getSpec().getContainers().get(0).getCommand(); for (Container container : podCaptor.getValue().getSpec().getContainers()) { assertEquals(container.getImagePullPolicy(), "IfNotPresent"); } final List<String> expected = Stream.concat( Arrays.stream(MKDIR_COMMAND_BASE), Stream.of(JOB_MOUNT_PATH + '/' + WORKSPACE_ID + PROJECTS_PATH)) .collect(toList()); assertEquals(actual, expected); verify(osDeployments).wait(anyString(), anyInt(), any()); verify(podStatus).getPhase(); verify(osDeployments).delete(anyString()); verify(securityContextProvisioner).provision(any()); }
@Test public void testWatchLogsWhenCreatingWorkspaceDirs() throws InfrastructureException { when(podStatus.getPhase()).thenReturn(POD_PHASE_SUCCEEDED); pvcSubPathHelper.createDirs( identity, WORKSPACE_ID, PVC_NAME, ImmutableMap.of( DEBUG_WORKSPACE_START, TRUE.toString(), DEBUG_WORKSPACE_START_LOG_LIMIT_BYTES, "123"), WORKSPACE_ID + PROJECTS_PATH); verify(osDeployments).watchLogs(any(), any(), any(), any(), eq(123L)); }
@Test public void testSetMemoryLimitAndRequest() throws Exception { when(podStatus.getPhase()).thenReturn(POD_PHASE_SUCCEEDED); pvcSubPathHelper.createDirs( identity, WORKSPACE_ID, PVC_NAME, emptyMap(), WORKSPACE_ID + PROJECTS_PATH); verify(osDeployments).create(podCaptor.capture()); ResourceRequirements actual = podCaptor.getValue().getSpec().getContainers().get(0).getResources(); ResourceRequirements expected = new ResourceRequirementsBuilder() .addToLimits(of("memory", new Quantity(jobMemoryLimit))) .addToRequests(of("memory", new Quantity(jobMemoryLimit))) .build(); assertEquals(actual, expected); verify(osDeployments).wait(anyString(), anyInt(), any()); verify(podStatus).getPhase(); verify(osDeployments).delete(anyString()); verify(securityContextProvisioner).provision(any()); }