@@ -44,7 +44,9 @@ var _ volume.Attacher = &cinderDiskAttacher{}
4444var _ volume.AttachableVolumePlugin = & cinderPlugin {}
4545
4646const (
47- checkSleepDuration = 5 * time .Second
47+ probeVolumeInitDealy = 1 * time .Second
48+ probeVolumeFactor = 2.0
49+ probeVolumeSteps = 10
4850 operationFinishInitDealy = 1 * time .Second
4951 operationFinishFactor = 1.1
5052 operationFinishSteps = 10
@@ -221,6 +223,38 @@ func (attacher *cinderDiskAttacher) VolumesAreAttached(specs []*volume.Spec, nod
221223 return volumesAttachedCheck , nil
222224}
223225
226+ func (attacher * cinderDiskAttacher ) waitProbeVolume (devicePath , volumeID string ) (string , error ) {
227+ backoff := wait.Backoff {
228+ Duration : probeVolumeInitDealy ,
229+ Factor : probeVolumeFactor ,
230+ Steps : probeVolumeSteps ,
231+ }
232+
233+ err := wait .ExponentialBackoff (backoff , func () (string , error ) {
234+ glog .V (5 ).Infof ("Checking Cinder disk %q is attached." , volumeID )
235+ probeAttachedVolume ()
236+ if ! attacher .cinderProvider .ShouldTrustDevicePath () {
237+ // Using the Cinder volume ID, find the real device path (See Issue #33128)
238+ devicePath = attacher .cinderProvider .GetDevicePath (volumeID )
239+ }
240+ exists , err := volumeutil .PathExists (devicePath )
241+ if exists && err == nil {
242+ glog .Infof ("Successfully found attached Cinder disk %q at %v." , volumeID , devicePath )
243+ return devicePath , nil
244+ }
245+ else {
246+ // Log an error, and continue checking periodically
247+ glog .Errorf ("Error: could not find attached Cinder disk %q (path: %q): %v" , volumeID , devicePath , err )
248+ }
249+ })
250+
251+ if err == wait .ErrWaitTimeout {
252+ err = fmt .Errorf ("Volume %q failed to be probed within the alloted time" , volumeID )
253+ }
254+
255+ return "" , err
256+ }
257+
224258func (attacher * cinderDiskAttacher ) WaitForAttach (spec * volume.Spec , devicePath string , _ * v1.Pod , timeout time.Duration ) (string , error ) {
225259 // NOTE: devicePath is is path as reported by Cinder, which may be incorrect and should not be used. See Issue #33128
226260 volumeSource , _ , err := getVolumeSource (spec )
@@ -234,32 +268,8 @@ func (attacher *cinderDiskAttacher) WaitForAttach(spec *volume.Spec, devicePath
234268 return "" , fmt .Errorf ("WaitForAttach failed for Cinder disk %q: devicePath is empty." , volumeID )
235269 }
236270
237- ticker := time .NewTicker (checkSleepDuration )
238- defer ticker .Stop ()
239- timer := time .NewTimer (timeout )
240- defer timer .Stop ()
241-
242- for {
243- select {
244- case <- ticker .C :
245- glog .V (5 ).Infof ("Checking Cinder disk %q is attached." , volumeID )
246- probeAttachedVolume ()
247- if ! attacher .cinderProvider .ShouldTrustDevicePath () {
248- // Using the Cinder volume ID, find the real device path (See Issue #33128)
249- devicePath = attacher .cinderProvider .GetDevicePath (volumeID )
250- }
251- exists , err := volumeutil .PathExists (devicePath )
252- if exists && err == nil {
253- glog .Infof ("Successfully found attached Cinder disk %q at %v." , volumeID , devicePath )
254- return devicePath , nil
255- } else {
256- // Log an error, and continue checking periodically
257- glog .Errorf ("Error: could not find attached Cinder disk %q (path: %q): %v" , volumeID , devicePath , err )
258- }
259- case <- timer .C :
260- return "" , fmt .Errorf ("Could not find attached Cinder disk %q. Timeout waiting for mount paths to be created." , volumeID )
261- }
262- }
271+ // Using exponential backoff instead of linear
272+ return attacher .waitProbeVolume (devicePath , volumeID )
263273}
264274
265275func (attacher * cinderDiskAttacher ) GetDeviceMountPath (
0 commit comments