Skip to content

fix: auto-mount path collisions #1378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pkg/provision/automount/projected.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"

"github.com/devfile/devworkspace-operator/pkg/common"
"github.com/devfile/devworkspace-operator/pkg/dwerrors"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"
)
Expand Down Expand Up @@ -53,6 +54,9 @@ func mergeProjectedVolumes(resources *Resources) (*Resources, error) {
volumeNameToVolume[volume.Name] = volume
}

// Map of merged volume names -> bool, for not merging the same volume twice
// This can happen due to different subpath volume mounts, where the mount path is the same. In this case, there should be only one volume.
mergedVolumeNames := map[string]bool{}
for _, mountPath := range mountPathOrder {
volumeMounts := mountPathToVolumeMounts[mountPath]
switch len(volumeMounts) {
Expand All @@ -62,7 +66,12 @@ func mergeProjectedVolumes(resources *Resources) (*Resources, error) {
// No projected volume necessary
mergedResources.VolumeMounts = append(mergedResources.VolumeMounts, volumeMounts[0])
volume := volumeNameToVolume[volumeMounts[0].Name]
mergedResources.Volumes = append(mergedResources.Volumes, volume)

_, isMerged := mergedVolumeNames[volume.Name]
if !isMerged {
mergedResources.Volumes = append(mergedResources.Volumes, volume)
mergedVolumeNames[volume.Name] = true
}
default:
vm, vol, err := generateProjectedVolume(mountPath, volumeMounts, volumeNameToVolume)
if err != nil {
Expand Down Expand Up @@ -164,7 +173,9 @@ func checkCanUseProjectedVolumes(volumeMounts []corev1.VolumeMount, volumeNameTo
for _, vm := range volumeMounts {
problemNames = append(problemNames, formatVolumeDescription(volumeNameToVolume[vm.Name]))
}
return fmt.Errorf("auto-mounted volumes from (%s) have the same mount path", strings.Join(problemNames, ", "))
return &dwerrors.FailError{
Message: fmt.Sprintf("auto-mounted volumes from (%s) have the same mount path", strings.Join(problemNames, ", ")),
}
}
return nil
}
Loading