Skip to content
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