Skip to content

Commit

Permalink
DeviceManager: Return no error if the device not found while deleting
Browse files Browse the repository at this point in the history
Discussion on issue intel#413, raised a requirement that PMEM-CSI should handle the
DeleteVolume() call for volumes that the underlined device already deleted
manually by the admin.  So for such a volume we just ignore and return no error
in DeviceManager.DeleteVolume(). This also makes DeleteVolume() idempotent.
  • Loading branch information
avalluri committed Oct 22, 2019
1 parent 09497de commit 15766e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
21 changes: 17 additions & 4 deletions pkg/pmem-device-manager/pmd-lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package pmdmanager

import (
"fmt"
"os"
"strconv"
"strings"
"sync"

"github.com/intel/pmem-csi/pkg/ndctl"
pmemexec "github.com/intel/pmem-csi/pkg/pmem-exec"
"github.com/pkg/errors"
"k8s.io/klog"
)

Expand Down Expand Up @@ -152,11 +154,22 @@ func (lvm *pmemLvm) DeleteDevice(name string, flush bool) error {
lvmMutex.Lock()
defer lvmMutex.Unlock()

device, err := lvm.getDevice(name)
if err != nil {
var err error
var device PmemDeviceInfo

if device, err = lvm.getDevice(name); err != nil {
if os.IsNotExist(errors.Cause(err)) {
return nil
}
return err
}
if err := ClearDevice(device, flush); err != nil {

if err = ClearDevice(device, flush); err != nil {
if os.IsNotExist(errors.Cause(err)) {
// Remove device from cache
delete(lvm.devices, name)
return nil
}
return err
}

Expand Down Expand Up @@ -194,7 +207,7 @@ func (lvm *pmemLvm) getDevice(id string) (PmemDeviceInfo, error) {
return dev, nil
}

return PmemDeviceInfo{}, fmt.Errorf("Device not found with name %s", id)
return PmemDeviceInfo{}, errors.Wrapf(os.ErrNotExist, "no device found with id '%s'", id)
}

func getUncachedDevice(id string, volumeGroup string) (PmemDeviceInfo, error) {
Expand Down
13 changes: 10 additions & 3 deletions pkg/pmem-device-manager/pmd-ndctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pmdmanager

import (
"fmt"
"os"
"sync"

"github.com/intel/pmem-csi/pkg/ndctl"
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 15766e9

Please sign in to comment.