@@ -647,7 +647,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
647
647
continue
648
648
}
649
649
if snapshot .VolumeID == sourceVolID {
650
- snap , err := toCSISnapshot (& snapshot )
650
+ snap , err := ToCSISnapshot (& snapshot )
651
651
if err != nil {
652
652
log .Error ().
653
653
Str ("snapshot_name" , snapshotName ).
@@ -704,7 +704,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
704
704
return nil , status .Error (codes .Internal , fmt .Sprintf ("failed to parse creation time: %v" , err ))
705
705
}
706
706
707
- isReady := isSnapshotReady (snapshot .State )
707
+ isReady := IsSnapshotReady (snapshot .State )
708
708
709
709
return & csi.CreateSnapshotResponse {
710
710
Snapshot : & csi.Snapshot {
@@ -783,7 +783,7 @@ func (d *Driver) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsReques
783
783
Msg ("Failed to list snapshot from Civo API" )
784
784
return nil , status .Errorf (codes .Internal , "failed to list snapshot %q: %v" , snapshotID , err )
785
785
}
786
- entry , err := convertSnapshot (snapshot )
786
+ entry , err := ConvertSnapshot (snapshot )
787
787
if err != nil {
788
788
log .Error ().
789
789
Err (err ).
@@ -820,7 +820,7 @@ func (d *Driver) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsReques
820
820
return nil , status .Errorf (codes .Internal , "failed to list snapshot %q: %v" , snapshotID , err )
821
821
}
822
822
823
- entry , err := convertSnapshot (snapshot )
823
+ entry , err := ConvertSnapshot (snapshot )
824
824
if err != nil {
825
825
log .Error ().
826
826
Err (err ).
@@ -854,7 +854,7 @@ func (d *Driver) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsReques
854
854
entries := []* csi.ListSnapshotsResponse_Entry {}
855
855
for _ , snapshot := range snapshots {
856
856
if snapshot .VolumeID == sourceVolumeID {
857
- entry , err := convertSnapshot (& snapshot )
857
+ entry , err := ConvertSnapshot (& snapshot )
858
858
if err != nil {
859
859
log .Error ().
860
860
Err (err ).
@@ -890,7 +890,7 @@ func (d *Driver) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsReques
890
890
entries := []* csi.ListSnapshotsResponse_Entry {}
891
891
892
892
for _ , snap := range snapshots {
893
- entry , err := convertSnapshot (& snap )
893
+ entry , err := ConvertSnapshot (& snap )
894
894
if err != nil {
895
895
log .Error ().
896
896
Err (err ).
@@ -926,9 +926,9 @@ func getVolSizeInBytes(capRange *csi.CapacityRange) (int64, error) {
926
926
return bytes , nil
927
927
}
928
928
929
- // convertSnapshot function converts a civogo.Snapshot object(API response) into a CSI ListSnapshotsResponse_Entry
930
- func convertSnapshot (in * civogo.VolumeSnapshot ) (* csi.ListSnapshotsResponse_Entry , error ) {
931
- snap , err := toCSISnapshot (in )
929
+ // ConvertSnapshot function converts a civogo.Snapshot object(API response) into a CSI ListSnapshotsResponse_Entry
930
+ func ConvertSnapshot (in * civogo.VolumeSnapshot ) (* csi.ListSnapshotsResponse_Entry , error ) {
931
+ snap , err := ToCSISnapshot (in )
932
932
if err != nil {
933
933
return nil , fmt .Errorf ("filed to convert civo snapshot %s to csi snapshot: %v" , in .SnapshotID , err )
934
934
}
@@ -947,31 +947,37 @@ func ParseTimeToProtoTimestamp(timeStr string) (*timestamppb.Timestamp, error) {
947
947
return timestamppb .New (t ), nil
948
948
}
949
949
950
- // isSnapshotReady determines if a snapshot is ready for use
951
- func isSnapshotReady (state string ) bool {
950
+ // IsSnapshotReady determines if a snapshot is ready for use
951
+ func IsSnapshotReady (state string ) bool {
952
952
// Define the states that indicate the snapshot is ready
953
953
readyStates := map [string ]bool {
954
954
"Ready" : true ,
955
955
"Available" : true , // Add other states if applicable
956
956
}
957
- return readyStates [state ]
957
+ // Check if the state exists in the map, return false if not found
958
+ _ , exists := readyStates [state ]
959
+ return exists
958
960
}
959
961
960
962
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 )
963
+ func ToCSISnapshot (snap * civogo.VolumeSnapshot )(* csi.Snapshot , error ){
964
+ var creationTime * timestamppb.Timestamp
965
+ var err error
966
+ if snap .CreationTime != "" {
967
+ creationTime , err = ParseTimeToProtoTimestamp (snap .CreationTime )
968
+ if err != nil {
969
+ return nil , fmt .Errorf ("failed to parse creation time for snapshot %s: %w" , snap .SnapshotID , err )
970
+ }
965
971
}
966
972
967
973
// Explicitly define which state indicates the snapshot is ready for use
968
- isReady := isSnapshotReady (snap .State )
974
+ isReady := IsSnapshotReady (snap .State )
969
975
970
976
return & csi.Snapshot {
971
977
SnapshotId : snap .SnapshotID ,
972
- SourceVolumeId : snap .VolumeID ,
973
- CreationTime : creationTime ,
974
- SizeBytes : int64 (snap .RestoreSize ),
975
- ReadyToUse : isReady ,
978
+ SourceVolumeId : snap .VolumeID ,
979
+ CreationTime : creationTime ,
980
+ SizeBytes : int64 (snap .RestoreSize ),
981
+ ReadyToUse : isReady ,
976
982
}, nil
977
983
}
0 commit comments