From 5a6f3a745b902f965b9242b9ff1f7ef5ac903c53 Mon Sep 17 00:00:00 2001 From: Pawan Prakash Sharma Date: Mon, 28 Mar 2022 20:01:37 +0530 Subject: [PATCH] fix(destroy): making ZFS-LocalPV aware of pool import (#406) If we are destroying a volume/snapshot and pool is not imported, the ZFS-LocalPV driver assumes that the volume/snapshot is not there and deletes the corresponding zfsvolume and zfssnap CR. Here we are checking the parent dataset presence before attempting to delete the volume or snapshot. Signed-off-by: Pawan --- pkg/zfs/zfs_util.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/zfs/zfs_util.go b/pkg/zfs/zfs_util.go index b810fe7..5c06665 100644 --- a/pkg/zfs/zfs_util.go +++ b/pkg/zfs/zfs_util.go @@ -621,6 +621,15 @@ func SetVolumeProp(vol *apis.ZFSVolume) error { // DestroyVolume deletes the zfs volume func DestroyVolume(vol *apis.ZFSVolume) error { volume := vol.Spec.PoolName + "/" + vol.Name + parentDataset := vol.Spec.PoolName + + // check if parent dataset is present or not before attempting to delete the volume + if err := getVolume(parentDataset); err != nil { + klog.Errorf( + "destroy: parent dataset %v is not present, error: %s", parentDataset, err.Error(), + ) + return err + } if err := getVolume(volume); err != nil { klog.Errorf( @@ -697,6 +706,17 @@ func DestroySnapshot(snap *apis.ZFSSnapshot) error { volume := snap.Labels[ZFSVolKey] snapDataset := snap.Spec.PoolName + "/" + volume + "@" + snap.Name + parentDataset := snap.Spec.PoolName + + // check if parent dataset is present or not before attempting to delete the snapshot + if err := getVolume(parentDataset); err != nil { + klog.Errorf( + "destroy: snapshot's(%v) parent dataset %v is not present, error: %s", + snapDataset, parentDataset, err.Error(), + ) + return err + } + if err := getVolume(snapDataset); err != nil { klog.Errorf( "destroy: snapshot %v is not present, error: %s", volume, err.Error(),