@@ -9,12 +9,12 @@ import (
9
9
"sync"
10
10
11
11
"github.com/container-storage-interface/spec/lib/go/csi"
12
- "github.com/golang/protobuf/ptypes"
13
12
"github.com/scaleway/scaleway-csi/scaleway"
14
13
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
15
14
"github.com/scaleway/scaleway-sdk-go/scw"
16
15
"google.golang.org/grpc/codes"
17
16
"google.golang.org/grpc/status"
17
+ "google.golang.org/protobuf/types/known/timestamppb"
18
18
"k8s.io/klog/v2"
19
19
)
20
20
@@ -506,7 +506,7 @@ func (d *controllerService) ListVolumes(ctx context.Context, req *csi.ListVolume
506
506
}
507
507
}
508
508
509
- volumesResp , err := d .scaleway .ListVolumes (& instance.ListVolumesRequest {}, scw .WithAllPages ())
509
+ volumesResp , err := d .scaleway .ListVolumes (& instance.ListVolumesRequest {}, scw .WithContext ( ctx ), scw . WithAllPages ())
510
510
if err != nil {
511
511
return nil , status .Error (codes .Internal , err .Error ())
512
512
}
@@ -605,12 +605,7 @@ func (d *controllerService) CreateSnapshot(ctx context.Context, req *csi.CreateS
605
605
}
606
606
607
607
if snapshot .CreationDate != nil {
608
- creationTime , err := ptypes .TimestampProto (* snapshot .CreationDate )
609
- if err != nil {
610
- return nil , status .Error (codes .Internal , err .Error ())
611
- }
612
- snapshotResp .CreationTime = creationTime
613
-
608
+ snapshotResp .CreationTime = timestamppb .New (* snapshot .CreationDate )
614
609
}
615
610
616
611
return & csi.CreateSnapshotResponse {
@@ -636,11 +631,7 @@ func (d *controllerService) CreateSnapshot(ctx context.Context, req *csi.CreateS
636
631
}
637
632
638
633
if snapshotResp .Snapshot .CreationDate != nil {
639
- creationTime , err := ptypes .TimestampProto (* snapshotResp .Snapshot .CreationDate )
640
- if err != nil {
641
- return nil , status .Error (codes .Internal , err .Error ())
642
- }
643
- snapshotProtoResp .CreationTime = creationTime
634
+ snapshotProtoResp .CreationTime = timestamppb .New (* snapshotResp .Snapshot .CreationDate )
644
635
}
645
636
646
637
return & csi.CreateSnapshotResponse {
@@ -689,23 +680,41 @@ func (d *controllerService) ListSnapshots(ctx context.Context, req *csi.ListSnap
689
680
}
690
681
691
682
// TODO fix zones
692
- snapshotID , _ , _ := getSnapshotIDAndZone (req .GetSnapshotId ())
693
- sourceVolumeID , _ , _ := getSourceVolumeIDAndZone (req .GetSourceVolumeId ())
683
+ snapshotID , snapshotZone , _ := getSnapshotIDAndZone (req .GetSnapshotId ())
684
+ sourceVolumeID , sourceVolumeZone , _ := getSourceVolumeIDAndZone (req .GetSourceVolumeId ())
694
685
695
- // TODO all zones
696
- snapshotsResp , err := d .scaleway .ListSnapshots (& instance.ListSnapshotsRequest {}, scw .WithAllPages ())
697
- if err != nil {
698
- return nil , status .Error (codes .Internal , err .Error ())
699
- }
700
686
snapshots := []* instance.Snapshot {}
701
- for _ , snap := range snapshotsResp .Snapshots {
702
- if snapshotID != "" && snap .ID == snapshotID {
703
- snapshots = []* instance.Snapshot {snap }
704
- break
687
+ switch {
688
+ case req .SnapshotId != "" :
689
+ snapshotResp , err := d .scaleway .GetSnapshot (& instance.GetSnapshotRequest {
690
+ SnapshotID : snapshotID ,
691
+ Zone : snapshotZone ,
692
+ }, scw .WithContext (ctx ))
693
+ if err != nil {
694
+ // not found should return empty list
695
+ if _ , ok := err .(* scw.ResourceNotFoundError ); ok {
696
+ return & csi.ListSnapshotsResponse {
697
+ Entries : []* csi.ListSnapshotsResponse_Entry {},
698
+ }, nil
699
+ }
700
+ return nil , status .Error (codes .Internal , err .Error ())
701
+ }
702
+ snapshots = []* instance.Snapshot {snapshotResp .Snapshot }
703
+ case sourceVolumeID != "" :
704
+ snapshotsResp , err := d .scaleway .ListSnapshots (& instance.ListSnapshotsRequest {
705
+ BaseVolumeID : & sourceVolumeID ,
706
+ Zone : sourceVolumeZone ,
707
+ }, scw .WithContext (ctx ), scw .WithAllPages ())
708
+ if err != nil {
709
+ return nil , status .Error (codes .Internal , err .Error ())
705
710
}
706
- if sourceVolumeID != "" && snap .BaseVolume != nil && snap .BaseVolume .ID == sourceVolumeID || snapshotID == "" && sourceVolumeID == "" {
707
- snapshots = append (snapshots , snap )
711
+ snapshots = snapshotsResp .Snapshots
712
+ default :
713
+ snapshotsResp , err := d .scaleway .ListSnapshots (& instance.ListSnapshotsRequest {}, scw .WithContext (ctx ), scw .WithAllPages ())
714
+ if err != nil {
715
+ return nil , status .Error (codes .Internal , err .Error ())
708
716
}
717
+ snapshots = snapshotsResp .Snapshots
709
718
}
710
719
711
720
nextPage := ""
@@ -738,11 +747,7 @@ func (d *controllerService) ListSnapshots(ctx context.Context, req *csi.ListSnap
738
747
}
739
748
740
749
if snap .CreationDate != nil {
741
- creationTime , err := ptypes .TimestampProto (* snap .CreationDate )
742
- if err != nil {
743
- return nil , status .Error (codes .Internal , err .Error ())
744
- }
745
- snapshotProtoResp .CreationTime = creationTime
750
+ snapshotProtoResp .CreationTime = timestamppb .New (* snap .CreationDate )
746
751
}
747
752
748
753
snapshotsEntries = append (snapshotsEntries , & csi.ListSnapshotsResponse_Entry {
0 commit comments