@@ -9,14 +9,15 @@ import (
9
9
"os"
10
10
"path/filepath"
11
11
"reflect"
12
+ "slices"
12
13
"strconv"
13
14
"strings"
14
15
15
16
"github.com/container-storage-interface/spec/lib/go/csi"
16
17
"github.com/scaleway/scaleway-csi/pkg/scaleway"
17
18
block "github.com/scaleway/scaleway-sdk-go/api/block/v1"
19
+ "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
18
20
"github.com/scaleway/scaleway-sdk-go/scw"
19
- "golang.org/x/exp/slices"
20
21
"google.golang.org/grpc/codes"
21
22
"google.golang.org/grpc/status"
22
23
"google.golang.org/protobuf/types/known/timestamppb"
@@ -520,3 +521,29 @@ func uint64ToInt64(v uint64) int64 {
520
521
521
522
return int64 (v )
522
523
}
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