Skip to content

Commit 7d8b81c

Browse files
SLH335RocketRene
andcommitted
fix: nil context on volume detach and state change
Co-authored-by: René Kuhn <[email protected]>
1 parent 93cab39 commit 7d8b81c

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

plugin.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (d plugin) Mount(r *volume.MountRequest) (*volume.MountResponse, error) {
183183

184184
if vol.Status == "creating" || vol.Status == "detaching" {
185185
logger.Infof("Volume is in '%s' state, wait for 'available'...", vol.Status)
186-
if vol, err = d.waitOnVolumeState(logger.Context, vol, "available"); err != nil {
186+
if vol, err = d.waitOnVolumeState(vol, "available"); err != nil {
187187
logger.Error(err.Error())
188188
return nil, err
189189
}
@@ -195,12 +195,12 @@ func (d plugin) Mount(r *volume.MountRequest) (*volume.MountResponse, error) {
195195

196196
if len(vol.Attachments) > 0 {
197197
logger.Debug("Volume already attached, detaching first")
198-
if vol, err = d.detachVolume(logger.Context, vol); err != nil {
198+
if vol, err = d.detachVolume(vol); err != nil {
199199
logger.WithError(err).Error("Error detaching volume")
200200
return nil, err
201201
}
202202

203-
if vol, err = d.waitOnVolumeState(logger.Context, vol, "available"); err != nil {
203+
if vol, err = d.waitOnVolumeState(vol, "available"); err != nil {
204204
logger.WithError(err).Error("Error detaching volume")
205205
return nil, err
206206
}
@@ -304,7 +304,7 @@ func (d plugin) Remove(r *volume.RemoveRequest) error {
304304

305305
if len(vol.Attachments) > 0 {
306306
logger.Debug("Volume still attached, detaching first")
307-
if vol, err = d.detachVolume(logger.Context, vol); err != nil {
307+
if vol, err = d.detachVolume(vol); err != nil {
308308
logger.WithError(err).Error("Error detaching volume")
309309
return err
310310
}
@@ -348,7 +348,7 @@ func (d plugin) Unmount(r *volume.UnmountRequest) error {
348348
if err != nil {
349349
logger.WithError(err).Error("Error retriving volume")
350350
} else {
351-
_, err = d.detachVolume(logger.Context, vol)
351+
_, err = d.detachVolume(vol)
352352
if err != nil {
353353
logger.WithError(err).Error("Error detaching volume")
354354
}
@@ -385,9 +385,9 @@ func (d plugin) getByName(name string) (*volumes.Volume, error) {
385385
return volume, err
386386
}
387387

388-
func (d plugin) detachVolume(ctx context.Context, vol *volumes.Volume) (*volumes.Volume, error) {
388+
func (d plugin) detachVolume(vol *volumes.Volume) (*volumes.Volume, error) {
389389
for _, att := range vol.Attachments {
390-
err := volumeattach.Delete(ctx, d.computeClient, att.ServerID, att.ID).ExtractErr()
390+
err := volumeattach.Delete(context.Background(), d.computeClient, att.ServerID, att.ID).ExtractErr()
391391
if err != nil {
392392
return nil, err
393393
}
@@ -396,15 +396,15 @@ func (d plugin) detachVolume(ctx context.Context, vol *volumes.Volume) (*volumes
396396
return vol, nil
397397
}
398398

399-
func (d plugin) waitOnVolumeState(ctx context.Context, vol *volumes.Volume, status string) (*volumes.Volume, error) {
399+
func (d plugin) waitOnVolumeState(vol *volumes.Volume, status string) (*volumes.Volume, error) {
400400
if vol.Status == status {
401401
return vol, nil
402402
}
403403

404404
for i := 1; i <= 10; i++ {
405405
time.Sleep(500 * time.Millisecond)
406406

407-
vol, err := volumes.Get(ctx, d.blockClient, vol.ID).Extract()
407+
vol, err := volumes.Get(context.Background(), d.blockClient, vol.ID).Extract()
408408
if err != nil {
409409
return nil, err
410410
}
@@ -414,7 +414,7 @@ func (d plugin) waitOnVolumeState(ctx context.Context, vol *volumes.Volume, stat
414414
}
415415
}
416416

417-
log.WithContext(ctx).Debugf("Volume did not become %s: %+v", status, vol)
417+
log.Debugf("Volume status did not change to %s: %+v", status, vol)
418418

419-
return nil, fmt.Errorf("Volume status did became %s", status)
419+
return nil, fmt.Errorf("Volume status changed to %s", status)
420420
}

0 commit comments

Comments
 (0)