@@ -46,7 +46,6 @@ var _ volume.AttachableVolumePlugin = &cinderPlugin{}
4646const (
4747 probeVolumeInitDealy = 1 * time .Second
4848 probeVolumeFactor = 2.0
49- probeVolumeSteps = 10
5049 operationFinishInitDealy = 1 * time .Second
5150 operationFinishFactor = 1.1
5251 operationFinishSteps = 10
@@ -223,41 +222,6 @@ func (attacher *cinderDiskAttacher) VolumesAreAttached(specs []*volume.Spec, nod
223222 return volumesAttachedCheck , nil
224223}
225224
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 () (bool , 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 true , nil
244- } else {
245- // Log an error, and continue checking periodically
246- glog .Errorf ("Error: could not find attached Cinder disk %q (path: %q): %v" , volumeID , devicePath , err )
247- return false , nil
248- }
249- })
250-
251- if err != nil {
252- if err == wait .ErrWaitTimeout {
253- err = fmt .Errorf ("Volume %q failed to be probed within the alloted time" , volumeID )
254- }
255- return "" , err
256- }
257-
258- return devicePath , nil
259- }
260-
261225func (attacher * cinderDiskAttacher ) WaitForAttach (spec * volume.Spec , devicePath string , _ * v1.Pod , timeout time.Duration ) (string , error ) {
262226 // NOTE: devicePath is is path as reported by Cinder, which may be incorrect and should not be used. See Issue #33128
263227 volumeSource , _ , err := getVolumeSource (spec )
@@ -271,8 +235,37 @@ func (attacher *cinderDiskAttacher) WaitForAttach(spec *volume.Spec, devicePath
271235 return "" , fmt .Errorf ("WaitForAttach failed for Cinder disk %q: devicePath is empty." , volumeID )
272236 }
273237
274- // Using exponential backoff instead of linear
275- return attacher .waitProbeVolume (devicePath , volumeID )
238+ ticker := time .NewTicker (probeVolumeInitDealy )
239+ defer ticker .Stop ()
240+ timer := time .NewTimer (timeout )
241+ defer timer .Stop ()
242+
243+ duration := probeVolumeInitDealy
244+ for {
245+ select {
246+ case <- ticker .C :
247+ glog .V (5 ).Infof ("Checking Cinder disk %q is attached." , volumeID )
248+ probeAttachedVolume ()
249+ if ! attacher .cinderProvider .ShouldTrustDevicePath () {
250+ // Using the Cinder volume ID, find the real device path (See Issue #33128)
251+ devicePath = attacher .cinderProvider .GetDevicePath (volumeID )
252+ }
253+ exists , err := volumeutil .PathExists (devicePath )
254+ if exists && err == nil {
255+ glog .Infof ("Successfully found attached Cinder disk %q at %v." , volumeID , devicePath )
256+ return devicePath , nil
257+ } else {
258+ // Log an error, and continue checking periodically
259+ glog .Errorf ("Error: could not find attached Cinder disk %q (path: %q): %v" , volumeID , devicePath , err )
260+ // Using exponential backoff instead of linear
261+ ticker .Stop ()
262+ duration = time .Duration (float64 (duration ) * probeVolumeFactor )
263+ ticker = time .NewTicker (duration )
264+ }
265+ case <- timer .C :
266+ return "" , fmt .Errorf ("Could not find attached Cinder disk %q. Timeout waiting for mount paths to be created." , volumeID )
267+ }
268+ }
276269}
277270
278271func (attacher * cinderDiskAttacher ) GetDeviceMountPath (
0 commit comments