EphemeralWorkspaceAdapter { public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException { LOG.debug("Provisioning PVC strategy for workspace '{}'", identity.getWorkspaceId()); Map<String, PersistentVolumeClaim> userDefinedPVCs = new HashMap<>(k8sEnv.getPersistentVolumeClaims()); k8sEnv.getPersistentVolumeClaims().clear(); pvcProvisioner.provision(k8sEnv, userDefinedPVCs); pvcProvisioner.convertCheVolumes(k8sEnv, identity.getWorkspaceId()); subPathPrefixes.prefixVolumeMountsSubpaths(k8sEnv, identity.getWorkspaceId()); replacePVCsWithEmptyDir(k8sEnv); k8sEnv.getPersistentVolumeClaims().clear(); } @Inject  EphemeralWorkspaceAdapter(PVCProvisioner pvcProvisioner, SubPathPrefixes subPathPrefixes); void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity);  }
@Test public void testProvisioningAllPVCsInWorkspace() throws Exception { PersistentVolumeClaim pvc1 = UniqueWorkspacePVCStrategyTest.newPVC("pvc1"); PersistentVolumeClaim pvc2 = UniqueWorkspacePVCStrategyTest.newPVC("pvc2"); k8sEnv.getPersistentVolumeClaims().put("pvc1", pvc1); k8sEnv.getPersistentVolumeClaims().put("pvc2", pvc2); when(identity.getWorkspaceId()).thenReturn(EPHEMERAL_WORKSPACE_ID); ephemeralWorkspaceAdapter.provision(k8sEnv, identity); provisionOrder .verify(pvcProvisioner) .provision(k8sEnv, ImmutableMap.of("pvc1", pvc1, "pvc2", pvc2)); provisionOrder.verify(pvcProvisioner).convertCheVolumes(k8sEnv, EPHEMERAL_WORKSPACE_ID); provisionOrder .verify(subPathPrefixes) .prefixVolumeMountsSubpaths(k8sEnv, EPHEMERAL_WORKSPACE_ID); }
@Test public void testConvertsAllPVCsToEmptyDir() throws Exception { k8sEnv.getPersistentVolumeClaims().put("pvc1", mock(PersistentVolumeClaim.class)); k8sEnv.getPersistentVolumeClaims().put("pvc2", mock(PersistentVolumeClaim.class)); io.fabric8.kubernetes.api.model.Volume configMapVolume = new VolumeBuilder().withNewConfigMap().withName("configMap").endConfigMap().build(); io.fabric8.kubernetes.api.model.Volume emptyDirVolume = new VolumeBuilder().withNewEmptyDir().endEmptyDir().build(); io.fabric8.kubernetes.api.model.Volume pvcVolume = new VolumeBuilder() .withNewPersistentVolumeClaim() .withClaimName("pvc1") .endPersistentVolumeClaim() .build(); Pod pod = new PodBuilder() .withNewMetadata() .withName(POD_NAME) .endMetadata() .withNewSpec() .withVolumes( new VolumeBuilder(pvcVolume).build(), new VolumeBuilder(configMapVolume).build(), new VolumeBuilder(emptyDirVolume).build()) .endSpec() .build(); k8sEnv.addPod(pod); ephemeralWorkspaceAdapter.provision(k8sEnv, identity); assertTrue(k8sEnv.getPersistentVolumeClaims().isEmpty()); assertNull(pod.getSpec().getVolumes().get(0).getPersistentVolumeClaim()); assertEquals(pod.getSpec().getVolumes().get(0).getEmptyDir(), new EmptyDirVolumeSource()); assertEquals(pod.getSpec().getVolumes().get(1), configMapVolume); assertEquals(pod.getSpec().getVolumes().get(2), emptyDirVolume); }