GetWorkspacePVCInfo determines the PVC name and workspace path based on the storage provisioner used. This function can be used by both backup and restore operations to ensure consistent PVC resolution logic. Returns: - pvcName: The name of the PVC that stores workspace data - workspacePath: The pa
( ctx context.Context, workspace *dw.DevWorkspace, config *controllerv1alpha1.OperatorConfiguration, k8sClient client.Client, log logr.Logger, )
| 35 | // - workspacePath: The path within the PVC where workspace data is stored |
| 36 | // - error: Any error that occurred during PVC resolution |
| 37 | func GetWorkspacePVCInfo( |
| 38 | ctx context.Context, |
| 39 | workspace *dw.DevWorkspace, |
| 40 | config *controllerv1alpha1.OperatorConfiguration, |
| 41 | k8sClient client.Client, |
| 42 | log logr.Logger, |
| 43 | ) (pvcName string, workspacePath string, err error) { |
| 44 | workspaceWithConfig := &common.DevWorkspaceWithConfig{} |
| 45 | workspaceWithConfig.DevWorkspace = workspace |
| 46 | workspaceWithConfig.Config = config |
| 47 | |
| 48 | storageProvisioner, err := storage.GetProvisioner(workspaceWithConfig) |
| 49 | if err != nil { |
| 50 | return "", "", err |
| 51 | } |
| 52 | |
| 53 | if _, ok := storageProvisioner.(*storage.PerWorkspaceStorageProvisioner); ok { |
| 54 | pvcName := common.PerWorkspacePVCName(workspace.Status.DevWorkspaceId) |
| 55 | return pvcName, constants.DefaultProjectsSourcesRoot, nil |
| 56 | |
| 57 | } else if _, ok := storageProvisioner.(*storage.CommonStorageProvisioner); ok { |
| 58 | if !storageProvisioner.NeedsStorage(&workspace.Spec.Template) { |
| 59 | // No storage provisioned for this workspace |
| 60 | return "", "", nil |
| 61 | } |
| 62 | pvcName := constants.DefaultWorkspacePVCName |
| 63 | if config.Workspace != nil && config.Workspace.PVCName != "" { |
| 64 | pvcName = config.Workspace.PVCName |
| 65 | } |
| 66 | return pvcName, workspace.Status.DevWorkspaceId + constants.DefaultProjectsSourcesRoot, nil |
| 67 | } |
| 68 | return "", "", nil |
| 69 | } |
no test coverage detected