Skip to content

Commit c11427f

Browse files
committed
Call NodeUnstage after NodeStage timeout
When NodeStage times out and does not prepare destination device and user deletes corresponding pod, the driver may continue staging the volume in background. Kubernetes must call NodeUnstage to "cancel" this operation. Therefore TearDownDevice should be called even when the target directory does not exist (yet).
1 parent f6fc735 commit c11427f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pkg/volume/util/operationexecutor/operation_generator.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
goerrors "errors"
2222
"fmt"
23+
"os"
2324
"path/filepath"
2425
"strings"
2526
"time"
@@ -1202,7 +1203,12 @@ func (og *operationGenerator) GenerateUnmapDeviceFunc(
12021203
globalMapPath := deviceToDetach.DeviceMountPath
12031204
refs, err := og.blkUtil.GetDeviceBindMountRefs(deviceToDetach.DevicePath, globalMapPath)
12041205
if err != nil {
1205-
return deviceToDetach.GenerateError("UnmapDevice.GetDeviceBindMountRefs check failed", err)
1206+
if os.IsNotExist(err) {
1207+
// Looks like SetupDevice did not complete. Fall through to TearDownDevice and mark the device as unmounted.
1208+
refs = nil
1209+
} else {
1210+
return deviceToDetach.GenerateError("UnmapDevice.GetDeviceBindMountRefs check failed", err)
1211+
}
12061212
}
12071213
if len(refs) > 0 {
12081214
err = fmt.Errorf("The device %q is still referenced from other Pods %v", globalMapPath, refs)

pkg/volume/util/volumepathhandler/volume_path_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func (v VolumePathHandler) GetDeviceBindMountRefs(devPath string, mapPath string
283283
var refs []string
284284
files, err := ioutil.ReadDir(mapPath)
285285
if err != nil {
286-
return nil, fmt.Errorf("directory cannot read %v", err)
286+
return nil, err
287287
}
288288
for _, file := range files {
289289
if file.Mode()&os.ModeDevice != os.ModeDevice {

0 commit comments

Comments
 (0)