Summary
CommonStorageProvisioner.rewriteContainerVolumeMounts and PerWorkspaceStorageProvisioner.rewriteContainerVolumeMounts contain ~80 lines of nearly identical code. The only difference is a single expression in the SubPath computation.
Files
pkg/provision/storage/commonStorage.go lines 136–214
pkg/provision/storage/perWorkspaceStorage.go lines 101–179
What's duplicated
Both methods perform the same steps:
- Build a
devfileVolumes map from workspace components
- Build an
additionalVolumes map from podAdditions.Volumes
- Build an
overridesVolumes map via overrides.GetVolumesFromOverrides
- Add the implicit projects volume
- Define and call a
rewriteVolumeMounts closure for both Containers and InitContainers
- Append the PVC volume to
podAdditions.Volumes
The only difference is the SubPath value:
// CommonStorage (line 190):
containers[cIdx].VolumeMounts[vmIdx].SubPath = fmt.Sprintf("%s/%s", workspaceId, vm.Name)
// PerWorkspaceStorage (line 155):
containers[cIdx].VolumeMounts[vmIdx].SubPath = vm.Name
Suggested fix
Extract a shared function (e.g., in pkg/provision/storage/shared.go) that accepts a subPathFunc parameter:
func rewriteContainerVolumeMounts(
workspaceId, pvcName string,
podAdditions *v1alpha1.PodAdditions,
workspace *dw.DevWorkspaceTemplateSpec,
restrictedFields []string,
subPathFunc func(workspaceId, volumeName string) string,
) error {
// ... shared logic ...
containers[cIdx].VolumeMounts[vmIdx].SubPath = subPathFunc(workspaceId, vm.Name)
// ...
}
Then each provisioner calls it with the appropriate SubPath transformation:
// CommonStorageProvisioner:
subPathFunc := func(wid, name string) string { return wid + "/" + name }
// PerWorkspaceStorageProvisioner:
subPathFunc := func(_, name string) string { return name }
Why this matters
When someone fixes a bug or adds a feature to the volume mount rewriting logic, they must update both methods identically. The identical // TODO: comment in both methods confirms they were copy-pasted and have already diverged in intent.
Verification
Run make test — existing tests for both storage provisioners should continue to pass with no changes.
Summary
CommonStorageProvisioner.rewriteContainerVolumeMountsandPerWorkspaceStorageProvisioner.rewriteContainerVolumeMountscontain ~80 lines of nearly identical code. The only difference is a single expression in the SubPath computation.Files
pkg/provision/storage/commonStorage.golines 136–214pkg/provision/storage/perWorkspaceStorage.golines 101–179What's duplicated
Both methods perform the same steps:
devfileVolumesmap from workspace componentsadditionalVolumesmap frompodAdditions.VolumesoverridesVolumesmap viaoverrides.GetVolumesFromOverridesrewriteVolumeMountsclosure for bothContainersandInitContainerspodAdditions.VolumesThe only difference is the SubPath value:
Suggested fix
Extract a shared function (e.g., in
pkg/provision/storage/shared.go) that accepts asubPathFuncparameter:Then each provisioner calls it with the appropriate SubPath transformation:
Why this matters
When someone fixes a bug or adds a feature to the volume mount rewriting logic, they must update both methods identically. The identical
// TODO:comment in both methods confirms they were copy-pasted and have already diverged in intent.Verification
Run
make test— existing tests for both storage provisioners should continue to pass with no changes.