@@ -647,28 +647,23 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
647
647
continue
648
648
}
649
649
if snapshot .VolumeID == sourceVolID {
650
- creationTime , err := ParseTimeToProtoTimestamp (snapshot .CreationTime )
651
- if err != nil {
652
- return nil , status .Error (codes .Internal , fmt .Sprintf ("failed to parse creation time: %v" , err ))
650
+ snap , err := toCSISnapshot (& snapshot )
651
+ if err != nil {
652
+ log .Error ().
653
+ Str ("snapshot_name" , snapshotName ).
654
+ Str ("source_volume_id" , sourceVolID ).
655
+ Err (err ).
656
+ Msg ("filed to convert civo snapshot to csi snapshot" )
657
+ return nil , status .Errorf (codes .Internal , "filed to convert civo snapshot %s to csi snapshot: %v" , snapshot .SnapshotID , err )
653
658
}
654
-
655
- isReady := isSnapshotReady (snapshot .State )
656
-
657
659
return & csi.CreateSnapshotResponse {
658
- Snapshot : & csi.Snapshot {
659
- SnapshotId : snapshot .SnapshotID ,
660
- SourceVolumeId : snapshot .VolumeID ,
661
- CreationTime : creationTime ,
662
- SizeBytes : int64 (snapshot .RestoreSize ),
663
- ReadyToUse : isReady ,
664
- },
660
+ Snapshot : snap ,
665
661
}, nil
666
662
}
667
663
log .Error ().
668
664
Str ("snapshot_name" , snapshotName ).
669
665
Str ("requested_source_volume_id" , sourceVolID ).
670
666
Str ("actual_source_volume_id" , snapshot .VolumeID ).
671
- Err (err ).
672
667
Msg ("Snapshot with the same name but with different SourceVolumeId already exist" )
673
668
return nil , status .Errorf (codes .AlreadyExists , "snapshot with the same name %q but with different SourceVolumeId already exist" , snapshotName )
674
669
}
@@ -933,22 +928,13 @@ func getVolSizeInBytes(capRange *csi.CapacityRange) (int64, error) {
933
928
934
929
// convertSnapshot function converts a civogo.Snapshot object(API response) into a CSI ListSnapshotsResponse_Entry
935
930
func convertSnapshot (in * civogo.VolumeSnapshot ) (* csi.ListSnapshotsResponse_Entry , error ) {
936
- creationTime , err := ParseTimeToProtoTimestamp (in . CreationTime )
937
- if err != nil {
938
- return nil , fmt .Errorf ("failed to parse creation time for snapshot %s: %w " , in .SnapshotID , err )
931
+ snap , err := toCSISnapshot (in )
932
+ if err != nil {
933
+ return nil , fmt .Errorf ("filed to convert civo snapshot %s to csi snapshot : %v " , in .SnapshotID , err )
939
934
}
940
935
941
- // Explicitly define which state indicates the snapshot is ready for use
942
- isReady := isSnapshotReady (in .State )
943
-
944
936
return & csi.ListSnapshotsResponse_Entry {
945
- Snapshot : & csi.Snapshot {
946
- SnapshotId : in .SnapshotID ,
947
- SourceVolumeId : in .VolumeID ,
948
- CreationTime : creationTime ,
949
- SizeBytes : int64 (in .RestoreSize ),
950
- ReadyToUse : isReady ,
951
- },
937
+ Snapshot : snap ,
952
938
}, nil
953
939
}
954
940
@@ -970,3 +956,22 @@ func isSnapshotReady(state string) bool {
970
956
}
971
957
return readyStates [state ]
972
958
}
959
+
960
+
961
+ func toCSISnapshot (snap * civogo.VolumeSnapshot )(* csi.Snapshot , error ){
962
+ creationTime , err := ParseTimeToProtoTimestamp (snap .CreationTime )
963
+ if err != nil {
964
+ return nil , fmt .Errorf ("failed to parse creation time for snapshot %s: %w" , snap .SnapshotID , err )
965
+ }
966
+
967
+ // Explicitly define which state indicates the snapshot is ready for use
968
+ isReady := isSnapshotReady (snap .State )
969
+
970
+ return & csi.Snapshot {
971
+ SnapshotId : snap .SnapshotID ,
972
+ SourceVolumeId : snap .VolumeID ,
973
+ CreationTime : creationTime ,
974
+ SizeBytes : int64 (snap .RestoreSize ),
975
+ ReadyToUse : isReady ,
976
+ }, nil
977
+ }
0 commit comments