@@ -1035,6 +1035,9 @@ func (d *BlockVolumeControllerDriver) CreateSnapshot(ctx context.Context, req *c
10351035 return nil , fmt .Errorf ("duplicate snapshot %q exists" , req .Name )
10361036 }
10371037
1038+ volumeAvailableTimeoutCtx , cancel := context .WithTimeout (ctx , 45 * time .Second )
1039+ defer cancel ()
1040+
10381041 if len (snapshots ) > 0 {
10391042 //Assigning existing snapshot
10401043
@@ -1055,35 +1058,38 @@ func (d *BlockVolumeControllerDriver) CreateSnapshot(ctx context.Context, req *c
10551058 ts := timestamppb .New (snapshot .TimeCreated .Time )
10561059
10571060 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- }
10671061
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+ }
10781080 }
10791081
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 )
10801086 return & csi.CreateSnapshotResponse {
10811087 Snapshot : & csi.Snapshot {
10821088 SnapshotId : * snapshot .Id ,
10831089 SourceVolumeId : * snapshot .VolumeId ,
10841090 SizeBytes : * snapshot .SizeInMBs * client .MiB ,
10851091 CreationTime : ts ,
1086- ReadyToUse : blockVolumeAvailable ,
1092+ ReadyToUse : true ,
10871093 },
10881094 }, nil
10891095 }
@@ -1125,22 +1131,14 @@ func (d *BlockVolumeControllerDriver) CreateSnapshot(ctx context.Context, req *c
11251131
11261132 ts := timestamppb .New (snapshot .TimeCreated .Time )
11271133
1128- _ , err = d .client .BlockStorage ().AwaitVolumeBackupAvailableOrTimeout (ctx , * snapshot .Id )
1134+ _ , err = d .client .BlockStorage ().AwaitVolumeBackupAvailableOrTimeout (volumeAvailableTimeoutCtx , * snapshot .Id )
11291135 if err != nil {
11301136 if strings .Contains (err .Error (), "timed out" ) {
11311137 log .Infof ("Backup did not become available immediately after creation, controller will retry" )
11321138 snapshotMetricDimension = util .GetMetricDimensionForComponent (util .BackupCreating , util .CSIStorageType )
11331139 dimensionsMap [metrics .ComponentDimension ] = snapshotMetricDimension
11341140 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" )
11441142 } else {
11451143 log .With ("service" , "blockstorage" , "verb" , "get" , "resource" , "volumeBackup" , "statusCode" , util .GetHttpStatusCode (err )).
11461144 Errorf ("Error while waiting for backup to become available %q: %v" , req .Name , err )
0 commit comments