PerWorkspacePVCStrategy extends CommonPVCStrategy { @Override protected PersistentVolumeClaim createCommonPVC(String workspaceId) { String pvcName = pvcNamePrefix + '-' + workspaceId; PersistentVolumeClaim perWorkspacePVC = newPVC(pvcName, pvcAccessMode, pvcQuantity, pvcStorageClassName); putLabel(perWorkspacePVC.getMetadata(), CHE_WORKSPACE_ID_LABEL, workspaceId); return perWorkspacePVC; } @Inject  PerWorkspacePVCStrategy(
      @Named("che.infra.kubernetes.pvc.name") String pvcName,
      @Named("che.infra.kubernetes.pvc.quantity") String pvcQuantity,
      @Named("che.infra.kubernetes.pvc.access_mode") String pvcAccessMode,
      @Named("che.infra.kubernetes.pvc.precreate_subpaths") boolean preCreateDirs,
      @Named("che.infra.kubernetes.pvc.storage_class_name") String pvcStorageClassName,
      @Named("che.infra.kubernetes.pvc.wait_bound") boolean waitBound,
      PVCSubPathHelper pvcSubPathHelper,
      KubernetesNamespaceFactory factory,
      EphemeralWorkspaceAdapter ephemeralWorkspaceAdapter,
      PVCProvisioner pvcProvisioner,
      PodsVolumes podsVolumes,
      SubPathPrefixes subpathPrefixes); @Override void cleanup(Workspace workspace); static final String PER_WORKSPACE_STRATEGY; }
@Test public void shouldReturnPVCPerWorkspace() throws Exception { PersistentVolumeClaim commonPVC = strategy.createCommonPVC(WORKSPACE_ID); assertEquals(commonPVC.getMetadata().getName(), PVC_NAME_PREFIX + "-" + WORKSPACE_ID); assertEquals(commonPVC.getMetadata().getLabels().get(CHE_WORKSPACE_ID_LABEL), WORKSPACE_ID); assertEquals(commonPVC.getSpec().getStorageClassName(), PVC_STORAGE_CLASS_NAME); }
@Test public void shouldReturnNullStorageClassNameWhenStorageClassNameIsEmptyOrNull() throws Exception { String[] storageClassNames = {"", null}; for (String storageClassName : storageClassNames) { final PerWorkspacePVCStrategy strategy = new PerWorkspacePVCStrategy( PVC_NAME_PREFIX, PVC_QUANTITY, PVC_ACCESS_MODE, true, storageClassName, true, pvcSubPathHelper, factory, ephemeralWorkspaceAdapter, volumeConverter, podsVolumes, subpathPrefixes); final PersistentVolumeClaim commonPVC = strategy.createCommonPVC(WORKSPACE_ID); assertNull(commonPVC.getSpec().getStorageClassName()); } }