Skip to content
Draft
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
21 changes: 21 additions & 0 deletions modules/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package storage
import (
"encoding/json"
"fmt"
"slices"

corev1 "k8s.io/api/core/v1"
)
Expand Down Expand Up @@ -175,3 +176,23 @@ func (s *Volume) ToCoreVolume() (*corev1.Volume, error) {
}
return coreVolume, nil
}

// DuplicateExtraMountCheck - This function takes an ExtraMount as input and validates that there are no duplicate
// mounts that could cause conflicts when we try to define Kubernetes objects.
// If any duplcates are found, we will return an error so that this function can be used in a webhook.
func DuplicateExtraMountCheck(volMounts []VolMounts) error {

var errors error
var existingMountPaths []string

for _, vol := range volMounts {
for _, mount := range vol.Mounts {
if slices.Contains(existingMountPaths, mount.MountPath) {
return fmt.Errorf("mountPaths must be unique for each extraMount. Duplicate found: %s", mount.MountPath)
}
existingMountPaths = append(existingMountPaths, mount.MountPath)
}
}

return errors
}
Loading