@@ -29,6 +29,7 @@ import (
29
29
"google.golang.org/grpc/codes"
30
30
"google.golang.org/grpc/status"
31
31
"k8s.io/apimachinery/pkg/util/sets"
32
+ "k8s.io/apimachinery/pkg/util/uuid"
32
33
"k8s.io/klog"
33
34
34
35
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
@@ -39,6 +40,9 @@ type GCEControllerServer struct {
39
40
Driver * GCEDriver
40
41
CloudProvider gce.GCECompute
41
42
43
+ disks []* compute.Disk
44
+ seen map [string ]int
45
+
42
46
// A map storing all volumes with ongoing operations so that additional
43
47
// operations for that same volume (as defined by Volume Key) return an
44
48
// Aborted error
@@ -524,22 +528,36 @@ func (gceCS *GCEControllerServer) ListVolumes(ctx context.Context, req *csi.List
524
528
// https://cloud.google.com/compute/docs/reference/beta/disks/list
525
529
if req .MaxEntries < 0 {
526
530
return nil , status .Error (codes .InvalidArgument , fmt .Sprintf (
527
- "ListVolumes got max entries request %v. GCE only supports values between 0-500" , req .MaxEntries ))
528
- }
529
- var maxEntries int64 = int64 (req .MaxEntries )
530
- if maxEntries > 500 {
531
- klog .Warningf ("ListVolumes requested max entries of %v, GCE only supports values <=500 so defaulting value back to 500" , maxEntries )
532
- maxEntries = 500
531
+ "ListVolumes got max entries request %v. GCE only supports values >0" , req .MaxEntries ))
533
532
}
534
- diskList , nextToken , err := gceCS .CloudProvider .ListDisks (ctx , maxEntries , req .StartingToken )
535
- if err != nil {
536
- if gce .IsGCEInvalidError (err ) {
537
- return nil , status .Error (codes .Aborted , fmt .Sprintf ("ListVolumes error with invalid request: %v" , err ))
533
+
534
+ offset := 0
535
+ var ok bool
536
+ if req .StartingToken == "" {
537
+ diskList , _ , err := gceCS .CloudProvider .ListDisks (ctx )
538
+ if err != nil {
539
+ if gce .IsGCEInvalidError (err ) {
540
+ return nil , status .Error (codes .Aborted , fmt .Sprintf ("ListVolumes error with invalid request: %v" , err ))
541
+ }
542
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("Unknown list disk error: %v" , err ))
538
543
}
539
- return nil , status .Error (codes .Internal , fmt .Sprintf ("Unknown list disk error: %v" , err ))
544
+ gceCS .disks = diskList
545
+ gceCS .seen = map [string ]int {}
546
+ } else {
547
+ offset , ok = gceCS .seen [req .StartingToken ]
548
+ if ! ok {
549
+ return nil , status .Error (codes .Aborted , fmt .Sprintf ("ListVolumes error with invalid startingToken: %s" , req .StartingToken ))
550
+ }
551
+ }
552
+
553
+ var maxEntries int = int (req .MaxEntries )
554
+ if maxEntries == 0 {
555
+ maxEntries = len (gceCS .disks )
540
556
}
557
+
541
558
entries := []* csi.ListVolumesResponse_Entry {}
542
- for _ , d := range diskList {
559
+ for i := 0 ; i + offset < len (gceCS .disks ) && i < maxEntries ; i ++ {
560
+ d := gceCS .disks [i + offset ]
543
561
users := []string {}
544
562
for _ , u := range d .Users {
545
563
users = append (users , cleanSelfLink (u ))
@@ -554,6 +572,12 @@ func (gceCS *GCEControllerServer) ListVolumes(ctx context.Context, req *csi.List
554
572
})
555
573
}
556
574
575
+ nextToken := ""
576
+ if len (entries )+ offset < len (gceCS .disks ) {
577
+ nextToken = string (uuid .NewUUID ())
578
+ gceCS .seen [nextToken ] = len (entries ) + offset
579
+ }
580
+
557
581
return & csi.ListVolumesResponse {
558
582
Entries : entries ,
559
583
NextToken : nextToken ,
0 commit comments