@@ -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
@@ -529,22 +533,36 @@ func (gceCS *GCEControllerServer) ListVolumes(ctx context.Context, req *csi.List
529
533
// https://cloud.google.com/compute/docs/reference/beta/disks/list
530
534
if req .MaxEntries < 0 {
531
535
return nil , status .Error (codes .InvalidArgument , fmt .Sprintf (
532
- "ListVolumes got max entries request %v. GCE only supports values between 0-500" , req .MaxEntries ))
533
- }
534
- var maxEntries int64 = int64 (req .MaxEntries )
535
- if maxEntries > 500 {
536
- klog .Warningf ("ListVolumes requested max entries of %v, GCE only supports values <=500 so defaulting value back to 500" , maxEntries )
537
- maxEntries = 500
536
+ "ListVolumes got max entries request %v. GCE only supports values >0" , req .MaxEntries ))
538
537
}
539
- diskList , nextToken , err := gceCS .CloudProvider .ListDisks (ctx , maxEntries , req .StartingToken )
540
- if err != nil {
541
- if gce .IsGCEInvalidError (err ) {
542
- return nil , status .Error (codes .Aborted , fmt .Sprintf ("ListVolumes error with invalid request: %v" , err ))
538
+
539
+ offset := 0
540
+ var ok bool
541
+ if req .StartingToken == "" {
542
+ diskList , _ , err := gceCS .CloudProvider .ListDisks (ctx )
543
+ if err != nil {
544
+ if gce .IsGCEInvalidError (err ) {
545
+ return nil , status .Error (codes .Aborted , fmt .Sprintf ("ListVolumes error with invalid request: %v" , err ))
546
+ }
547
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("Unknown list disk error: %v" , err ))
543
548
}
544
- return nil , status .Error (codes .Internal , fmt .Sprintf ("Unknown list disk error: %v" , err ))
549
+ gceCS .disks = diskList
550
+ gceCS .seen = map [string ]int {}
551
+ } else {
552
+ offset , ok = gceCS .seen [req .StartingToken ]
553
+ if ! ok {
554
+ return nil , status .Error (codes .Aborted , fmt .Sprintf ("ListVolumes error with invalid startingToken: %s" , req .StartingToken ))
555
+ }
556
+ }
557
+
558
+ var maxEntries int = int (req .MaxEntries )
559
+ if maxEntries == 0 {
560
+ maxEntries = len (gceCS .disks )
545
561
}
562
+
546
563
entries := []* csi.ListVolumesResponse_Entry {}
547
- for _ , d := range diskList {
564
+ for i := 0 ; i + offset < len (gceCS .disks ) && i < maxEntries ; i ++ {
565
+ d := gceCS .disks [i + offset ]
548
566
users := []string {}
549
567
for _ , u := range d .Users {
550
568
users = append (users , cleanSelfLink (u ))
@@ -559,6 +577,12 @@ func (gceCS *GCEControllerServer) ListVolumes(ctx context.Context, req *csi.List
559
577
})
560
578
}
561
579
580
+ nextToken := ""
581
+ if len (entries )+ offset < len (gceCS .disks ) {
582
+ nextToken = string (uuid .NewUUID ())
583
+ gceCS .seen [nextToken ] = len (entries ) + offset
584
+ }
585
+
562
586
return & csi.ListVolumesResponse {
563
587
Entries : entries ,
564
588
NextToken : nextToken ,
0 commit comments