diff --git a/pkg/provision/storage/perWorkspaceStorage.go b/pkg/provision/storage/perWorkspaceStorage.go index 5fcd276f4..7cf66c74b 100644 --- a/pkg/provision/storage/perWorkspaceStorage.go +++ b/pkg/provision/storage/perWorkspaceStorage.go @@ -166,6 +166,16 @@ func (p *PerWorkspaceStorageProvisioner) rewriteContainerVolumeMounts(workspaceI return nil } +// Calculates the per-workspace PVC size required for the given devworkspace based on the following rules: +// +// 1. If all volumes in the devworkspace specify their size, the computed PVC size will be used. +// +// 2. If all volumes in the devworkspace either specify their size or are ephemeral, the computed PVC size will be used. +// +// 3. If at least one volume in the devworkspace specifies its size, and the computed PVC size is greater +// than the default per-workspace PVC size, the computed PVC size will be used. +// +// 4. Container components with mountSources enabled in the devworkspace are treated as if they were volumes with an unspecified size. func getPVCSize(workspace *common.DevWorkspaceWithConfig, namespacedConfig *nsconfig.NamespacedConfig) (*resource.Quantity, error) { defaultPVCSize := *workspace.Config.Workspace.DefaultStorageSize.PerWorkspace @@ -189,6 +199,15 @@ func getPVCSize(workspace *common.DevWorkspaceWithConfig, namespacedConfig *nsco } requiredPVCSize.Add(volumeSize) } + if component.Container != nil { + if component.Container.MountSources != nil && *component.Container.MountSources { + // Edge case: If the project source code is being mounted to a container component + // then an undefined amount of persistent storage is required. + // We treat this case as if there was a volume component with no size defined. + allVolumeSizesDefined = false + continue + } + } } // Use the calculated PVC size if it's greater than default PVC size diff --git a/pkg/provision/storage/testdata/perWorkspace-storage/use-default-size-when-mount-sources-used.yaml b/pkg/provision/storage/testdata/perWorkspace-storage/use-default-size-when-mount-sources-used.yaml new file mode 100644 index 000000000..5d1b1cc71 --- /dev/null +++ b/pkg/provision/storage/testdata/perWorkspace-storage/use-default-size-when-mount-sources-used.yaml @@ -0,0 +1,39 @@ +name: "Uses default PVC size when no volumes define their size but mountSources used" + +input: + devworkspaceId: "test-workspaceid" + podAdditions: + containers: + - name: testing-container-1 + image: testing-image + volumeMounts: + - name: "projects" + mountPath: "/projects-mountpath" + initContainers: + - name: testing-initContainer-1 + image: testing-image + + workspace: + components: + - name: testing-container-1 + container: + image: testing-image-1 + mountSources: true + +output: + podAdditions: + containers: + - name: testing-container-1 + image: testing-image + volumeMounts: + - name: storage-test-workspaceid + subPath: "projects" + mountPath: "/projects-mountpath" + initContainers: + - name: testing-initContainer-1 + image: testing-image + + volumes: + - name: storage-test-workspaceid + persistentVolumeClaim: + claimName: storage-test-workspaceid