@@ -1035,6 +1035,9 @@ func (d *BlockVolumeControllerDriver) CreateSnapshot(ctx context.Context, req *c
1035
1035
return nil , fmt .Errorf ("duplicate snapshot %q exists" , req .Name )
1036
1036
}
1037
1037
1038
+ volumeAvailableTimeoutCtx , cancel := context .WithTimeout (ctx , 45 * time .Second )
1039
+ defer cancel ()
1040
+
1038
1041
if len (snapshots ) > 0 {
1039
1042
//Assigning existing snapshot
1040
1043
@@ -1055,35 +1058,38 @@ func (d *BlockVolumeControllerDriver) CreateSnapshot(ctx context.Context, req *c
1055
1058
ts := timestamppb .New (snapshot .TimeCreated .Time )
1056
1059
1057
1060
log .Infof ("Checking if backup %v has become available" , * snapshot .Id )
1058
- blockVolumeAvailable , err := isBlockVolumeAvailable (snapshot )
1059
- if err != nil {
1060
- log .Errorf ("Error while waiting for backup to become available %q: %v" , req .Name , err )
1061
- errorType = util .GetError (err )
1062
- snapshotMetricDimension = util .GetMetricDimensionForComponent (errorType , util .CSIStorageType )
1063
- dimensionsMap [metrics .ComponentDimension ] = snapshotMetricDimension
1064
- metrics .SendMetricData (d .metricPusher , metrics .BlockSnapshotProvision , time .Since (snapshot .TimeRequestReceived .Time ).Seconds (), dimensionsMap )
1065
- return nil , status .Errorf (codes .Internal , "Backup did not become available %q: %v" , req .Name , err )
1066
- }
1067
1061
1068
- if blockVolumeAvailable {
1069
- log .Info ("Snapshot is created and available." )
1070
- snapshotMetricDimension = util .GetMetricDimensionForComponent (util .Success , util .CSIStorageType )
1071
- dimensionsMap [metrics .ComponentDimension ] = snapshotMetricDimension
1072
- metrics .SendMetricData (d .metricPusher , metrics .BlockSnapshotProvision , time .Since (snapshot .TimeRequestReceived .Time ).Seconds (), dimensionsMap )
1073
- } else {
1074
- log .Infof ("Backup has not become available yet, controller will retry" )
1075
- snapshotMetricDimension = util .GetMetricDimensionForComponent (util .BackupCreating , util .CSIStorageType )
1076
- dimensionsMap [metrics .ComponentDimension ] = snapshotMetricDimension
1077
- metrics .SendMetricData (d .metricPusher , metrics .BlockSnapshotProvision , time .Since (snapshot .TimeRequestReceived .Time ).Seconds (), dimensionsMap )
1062
+ _ , err = d .client .BlockStorage ().AwaitVolumeBackupAvailableOrTimeout (volumeAvailableTimeoutCtx , * snapshot .Id )
1063
+ if err != nil {
1064
+ if strings .Contains (err .Error (), "timed out" ) {
1065
+ log .Infof ("Backup has not become available yet, controller will retry" )
1066
+ snapshotMetricDimension = util .GetMetricDimensionForComponent (util .BackupCreating , util .CSIStorageType )
1067
+ dimensionsMap [metrics .ComponentDimension ] = snapshotMetricDimension
1068
+ metrics .SendMetricData (d .metricPusher , metrics .BlockSnapshotProvision , time .Since (snapshot .TimeRequestReceived .Time ).Seconds (), dimensionsMap )
1069
+ return nil , status .Errorf (codes .DeadlineExceeded , "Timed out waiting for backup to become available" )
1070
+ } else {
1071
+ log .With ("service" , "blockstorage" , "verb" , "get" , "resource" , "volumeBackup" , "statusCode" , util .GetHttpStatusCode (err )).
1072
+ Errorf ("Error while waiting for backup to become available %q: %v" , req .Name , err )
1073
+ errorType = util .GetError (err )
1074
+ snapshotMetricDimension = util .GetMetricDimensionForComponent (errorType , util .CSIStorageType )
1075
+ dimensionsMap [metrics .ComponentDimension ] = snapshotMetricDimension
1076
+ metrics .SendMetricData (d .metricPusher , metrics .BlockSnapshotProvision , time .Since (startTime ).Seconds (), dimensionsMap )
1077
+ log .Errorf ("Backup did not become available %q: %v" , req .Name , err )
1078
+ return nil , status .Errorf (codes .Internal , "Backup did not become available %q: %v" , req .Name , err )
1079
+ }
1078
1080
}
1079
1081
1082
+ log .Info ("Snapshot is created and available." )
1083
+ snapshotMetricDimension = util .GetMetricDimensionForComponent (util .Success , util .CSIStorageType )
1084
+ dimensionsMap [metrics .ComponentDimension ] = snapshotMetricDimension
1085
+ metrics .SendMetricData (d .metricPusher , metrics .BlockSnapshotProvision , time .Since (snapshot .TimeRequestReceived .Time ).Seconds (), dimensionsMap )
1080
1086
return & csi.CreateSnapshotResponse {
1081
1087
Snapshot : & csi.Snapshot {
1082
1088
SnapshotId : * snapshot .Id ,
1083
1089
SourceVolumeId : * snapshot .VolumeId ,
1084
1090
SizeBytes : * snapshot .SizeInMBs * client .MiB ,
1085
1091
CreationTime : ts ,
1086
- ReadyToUse : blockVolumeAvailable ,
1092
+ ReadyToUse : true ,
1087
1093
},
1088
1094
}, nil
1089
1095
}
@@ -1125,22 +1131,14 @@ func (d *BlockVolumeControllerDriver) CreateSnapshot(ctx context.Context, req *c
1125
1131
1126
1132
ts := timestamppb .New (snapshot .TimeCreated .Time )
1127
1133
1128
- _ , err = d .client .BlockStorage ().AwaitVolumeBackupAvailableOrTimeout (ctx , * snapshot .Id )
1134
+ _ , err = d .client .BlockStorage ().AwaitVolumeBackupAvailableOrTimeout (volumeAvailableTimeoutCtx , * snapshot .Id )
1129
1135
if err != nil {
1130
1136
if strings .Contains (err .Error (), "timed out" ) {
1131
1137
log .Infof ("Backup did not become available immediately after creation, controller will retry" )
1132
1138
snapshotMetricDimension = util .GetMetricDimensionForComponent (util .BackupCreating , util .CSIStorageType )
1133
1139
dimensionsMap [metrics .ComponentDimension ] = snapshotMetricDimension
1134
1140
metrics .SendMetricData (d .metricPusher , metrics .BlockSnapshotProvision , time .Since (startTime ).Seconds (), dimensionsMap )
1135
- return & csi.CreateSnapshotResponse {
1136
- Snapshot : & csi.Snapshot {
1137
- SnapshotId : * snapshot .Id ,
1138
- SourceVolumeId : * snapshot .VolumeId ,
1139
- SizeBytes : * snapshot .SizeInMBs * client .MiB ,
1140
- CreationTime : ts ,
1141
- ReadyToUse : false ,
1142
- },
1143
- }, nil
1141
+ return nil , status .Errorf (codes .DeadlineExceeded , "Timed out waiting for backup to become available" )
1144
1142
} else {
1145
1143
log .With ("service" , "blockstorage" , "verb" , "get" , "resource" , "volumeBackup" , "statusCode" , util .GetHttpStatusCode (err )).
1146
1144
Errorf ("Error while waiting for backup to become available %q: %v" , req .Name , err )
0 commit comments