@@ -9,14 +9,15 @@ import (
99 "os"
1010 "path/filepath"
1111 "reflect"
12+ "slices"
1213 "strconv"
1314 "strings"
1415
1516 "github.com/container-storage-interface/spec/lib/go/csi"
1617 "github.com/scaleway/scaleway-csi/pkg/scaleway"
1718 block "github.com/scaleway/scaleway-sdk-go/api/block/v1"
19+ "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
1820 "github.com/scaleway/scaleway-sdk-go/scw"
19- "golang.org/x/exp/slices"
2021 "google.golang.org/grpc/codes"
2122 "google.golang.org/grpc/status"
2223 "google.golang.org/protobuf/types/known/timestamppb"
@@ -520,3 +521,29 @@ func uint64ToInt64(v uint64) int64 {
520521
521522 return int64 (v )
522523}
524+
525+ // attachedScratchVolumes returns the number of attached scratch volumes, based
526+ // on the instance metadata.
527+ func attachedScratchVolumes (md * instance.Metadata ) int {
528+ var count int
529+
530+ for _ , vol := range md .Volumes {
531+ if vol .VolumeType == "scratch" {
532+ count ++
533+ }
534+ }
535+
536+ return count
537+ }
538+
539+ // maxVolumesPerNode returns the maximum number of volumes that can be attached to a node,
540+ // after substracting the system root volume and the provided number of reserved volumes.
541+ // It returns an error if the result is 0 or less.
542+ func maxVolumesPerNode (reservedCount int ) (int64 , error ) {
543+ max := scaleway .MaxVolumesPerNode - reservedCount - 1
544+ if max <= 0 {
545+ return 0 , fmt .Errorf ("max number of volumes that can be attached to this node must be at least 1, currently is %d" , max )
546+ }
547+
548+ return int64 (max ), nil
549+ }
0 commit comments