From c11427fef5b03018c9b4823b35fb9dfe541f339d Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Mon, 2 Mar 2020 12:54:02 +0100 Subject: [PATCH] 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). --- pkg/volume/util/operationexecutor/operation_generator.go | 8 +++++++- pkg/volume/util/volumepathhandler/volume_path_handler.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index 9f86cf93f8e..5a98946c6f3 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -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) diff --git a/pkg/volume/util/volumepathhandler/volume_path_handler.go b/pkg/volume/util/volumepathhandler/volume_path_handler.go index 9c0983bbf73..6f198302dc0 100644 --- a/pkg/volume/util/volumepathhandler/volume_path_handler.go +++ b/pkg/volume/util/volumepathhandler/volume_path_handler.go @@ -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 {