PVCSubPathHelper { @VisibleForTesting void execute( RuntimeIdentity identity, String workspaceId, String pvcName, String[] commandBase, Map<String, String> startOptions, String... arguments) { execute( identity, workspaceId, identity.getInfrastructureNamespace(), pvcName, commandBase, startOptions, arguments); } @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 testLogErrorWhenJobExecutionFailed() throws Exception { when(podStatus.getPhase()).thenReturn(POD_PHASE_FAILED); pvcSubPathHelper.execute( WORKSPACE_ID, NAMESPACE, PVC_NAME, MKDIR_COMMAND_BASE, WORKSPACE_ID + PROJECTS_PATH); verify(osDeployments).create(any()); verify(osDeployments).wait(anyString(), anyInt(), any()); verify(podStatus).getPhase(); verify(osDeployments).getPodLogs(any()); verify(osDeployments).delete(anyString()); }
@Test public void testLogErrorWhenKubernetesProjectCreationFailed() throws Exception { when(osDeployments.create(any())) .thenThrow(new InfrastructureException("Kubernetes namespace creation failed")); pvcSubPathHelper.execute( WORKSPACE_ID, NAMESPACE, PVC_NAME, MKDIR_COMMAND_BASE, WORKSPACE_ID + PROJECTS_PATH); verify(k8sNamespaceFactory).access(WORKSPACE_ID, NAMESPACE); verify(osDeployments).create(any()); verify(osDeployments, never()).wait(anyString(), anyInt(), any()); }
@Test public void testLogErrorWhenKubernetesPodCreationFailed() throws Exception { when(osDeployments.create(any())) .thenThrow(new InfrastructureException("Kubernetes pod creation failed")); pvcSubPathHelper.execute( WORKSPACE_ID, NAMESPACE, PVC_NAME, MKDIR_COMMAND_BASE, WORKSPACE_ID + PROJECTS_PATH); verify(k8sNamespaceFactory).access(WORKSPACE_ID, NAMESPACE); verify(k8sNamespace).deployments(); verify(osDeployments).create(any()); verify(osDeployments, never()).wait(anyString(), anyInt(), any()); }
@Test public void testIgnoreExceptionWhenPodJobRemovalFailed() throws Exception { when(podStatus.getPhase()).thenReturn(POD_PHASE_SUCCEEDED); doThrow(InfrastructureException.class).when(osDeployments).delete(anyString()); pvcSubPathHelper.execute( WORKSPACE_ID, NAMESPACE, PVC_NAME, MKDIR_COMMAND_BASE, WORKSPACE_ID + PROJECTS_PATH); verify(osDeployments).create(any()); verify(osDeployments).wait(anyString(), anyInt(), any()); verify(podStatus).getPhase(); verify(osDeployments).delete(anyString()); }
@Test public void shouldBeAbleToConfigureImagePullPolicy() throws InfrastructureException { pvcSubPathHelper = new PVCSubPathHelper( jobMemoryLimit, jobImage, "ToBeOrNotIfPresent", k8sNamespaceFactory, securityContextProvisioner, new NoopExecutorServiceWrapper(), eventsPublisher); pvcSubPathHelper.execute( WORKSPACE_ID, NAMESPACE, PVC_NAME, MKDIR_COMMAND_BASE, WORKSPACE_ID + PROJECTS_PATH); verify(osDeployments).create(podCaptor.capture()); for (Container container : podCaptor.getValue().getSpec().getContainers()) { assertEquals(container.getImagePullPolicy(), "ToBeOrNotIfPresent"); } }