diff --git a/pkg/pmem-device-manager/pmd-lvm.go b/pkg/pmem-device-manager/pmd-lvm.go index 22572c7e91..61385ccf74 100644 --- a/pkg/pmem-device-manager/pmd-lvm.go +++ b/pkg/pmem-device-manager/pmd-lvm.go @@ -2,6 +2,7 @@ package pmdmanager import ( "fmt" + "os" "strconv" "strings" "sync" @@ -157,6 +158,11 @@ func (lvm *pmemLvm) DeleteDevice(name string, flush bool) error { return err } if err := ClearDevice(device, flush); err != nil { + if os.IsNotExist(err) { + // Remove device from cache + delete(lvm.devices, name) + return nil + } return err } diff --git a/pkg/pmem-device-manager/pmd-ndctl.go b/pkg/pmem-device-manager/pmd-ndctl.go index b9fe6e3297..4ea9fd3ef1 100644 --- a/pkg/pmem-device-manager/pmd-ndctl.go +++ b/pkg/pmem-device-manager/pmd-ndctl.go @@ -2,6 +2,7 @@ package pmdmanager import ( "fmt" + "os" "sync" "github.com/intel/pmem-csi/pkg/ndctl" @@ -143,12 +144,18 @@ func (pmem *pmemNdctl) DeleteDevice(name string, flush bool) error { device, err := pmem.getDevice(name) if err != nil { - return err + // Assume not found device as already deleted + // and return no error + return nil } - err = ClearDevice(device, flush) - if err != nil { + if err := ClearDevice(device, flush); err != nil { + // Device might have already deleted + if os.IsNotExist(err) { + return nil + } return err } + return pmem.ctx.DestroyNamespaceByName(name) }