Skip to content

Commit 36eb64b

Browse files
committed
refactor: handle empty snapshot creationTime in ParseTimeToProtoTimestamp method instead of upstream
1 parent 7b329ac commit 36eb64b

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

Diff for: pkg/driver/controller_server.go

+10-13
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ func getVolSizeInBytes(capRange *csi.CapacityRange) (int64, error) {
930930
func ConvertSnapshot(in *civogo.VolumeSnapshot) (*csi.ListSnapshotsResponse_Entry, error) {
931931
snap, err := ToCSISnapshot(in)
932932
if err != nil{
933-
return nil, fmt.Errorf("filed to convert civo snapshot %s to csi snapshot: %v", in.SnapshotID, err)
933+
return nil, fmt.Errorf("failed to convert civo snapshot %s to csi snapshot: %v", in.SnapshotID, err)
934934
}
935935

936936
return &csi.ListSnapshotsResponse_Entry{
@@ -940,11 +940,12 @@ func ConvertSnapshot(in *civogo.VolumeSnapshot) (*csi.ListSnapshotsResponse_Entr
940940

941941
// ParseTimeToProtoTimestamp parses a time string in RFC3339 format to *timestamppb.Timestamp.
942942
func ParseTimeToProtoTimestamp(timeStr string) (*timestamppb.Timestamp, error) {
943-
t, err := time.Parse(time.RFC3339, timeStr)
944-
if err != nil {
945-
return nil, err
946-
}
947-
return timestamppb.New(t), nil
943+
t, err := time.Parse(time.RFC3339, timeStr)
944+
// Only return an error if timeStr is not empty
945+
if err != nil && timeStr != "" {
946+
return nil, err
947+
}
948+
return timestamppb.New(t), nil
948949
}
949950

950951
// IsSnapshotReady determines if a snapshot is ready for use
@@ -961,13 +962,9 @@ func IsSnapshotReady(state string) bool {
961962

962963

963964
func ToCSISnapshot(snap *civogo.VolumeSnapshot)(*csi.Snapshot, error){
964-
var creationTime *timestamppb.Timestamp
965-
var err error
966-
if strings.TrimSpace(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+
creationTime, err := ParseTimeToProtoTimestamp(snap.CreationTime)
966+
if err != nil {
967+
return nil, fmt.Errorf("failed to parse creation time for snapshot %s: %w", snap.SnapshotID, err)
971968
}
972969

973970
// Explicitly define which state indicates the snapshot is ready for use

0 commit comments

Comments
 (0)