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).
This commit is contained in:
Jan Safranek 2020-03-02 12:54:02 +01:00
parent f6fc73573c
commit c11427fef5
2 changed files with 8 additions and 2 deletions

View File

@ -20,6 +20,7 @@ import (
"context"
goerrors "errors"
"fmt"
"os"
"path/filepath"
"strings"
"time"
@ -1202,7 +1203,12 @@ func (og *operationGenerator) GenerateUnmapDeviceFunc(
globalMapPath := deviceToDetach.DeviceMountPath
refs, err := og.blkUtil.GetDeviceBindMountRefs(deviceToDetach.DevicePath, globalMapPath)
if err != nil {
return deviceToDetach.GenerateError("UnmapDevice.GetDeviceBindMountRefs check failed", err)
if os.IsNotExist(err) {
// Looks like SetupDevice did not complete. Fall through to TearDownDevice and mark the device as unmounted.
refs = nil
} else {
return deviceToDetach.GenerateError("UnmapDevice.GetDeviceBindMountRefs check failed", err)
}
}
if len(refs) > 0 {
err = fmt.Errorf("The device %q is still referenced from other Pods %v", globalMapPath, refs)

View File

@ -283,7 +283,7 @@ func (v VolumePathHandler) GetDeviceBindMountRefs(devPath string, mapPath string
var refs []string
files, err := ioutil.ReadDir(mapPath)
if err != nil {
return nil, fmt.Errorf("directory cannot read %v", err)
return nil, err
}
for _, file := range files {
if file.Mode()&os.ModeDevice != os.ModeDevice {