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–214pkg/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.NameSuggested fix
Extract a shared function (e.g., in pkg/provision/storage/shared.go) that accepts a subPathFunc parameter:
funcrewriteContainerVolumeMounts(
workspaceId, pvcNamestring,
podAdditions*v1alpha1.PodAdditions,
workspace*dw.DevWorkspaceTemplateSpec,
restrictedFields []string,
subPathFuncfunc(workspaceId, volumeNamestring) 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, namestring) string { returnwid+"/"+name }
// PerWorkspaceStorageProvisioner:subPathFunc:=func(_, namestring) string { returnname }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.