From 45015bf063f21c57bce566fa8f600be0331fc01b Mon Sep 17 00:00:00 2001 From: Pawan Date: Thu, 4 Jun 2020 21:57:28 +0530 Subject: [PATCH] fix(pvc): fixing stale ZFSVolume CR issue when deleting pending PVC PVC will not bound if there are wrong parameters/poolname in the storageclass, the ZFSVolume CR will be still created and will remain in Pending State, deletion of the PVC will delete PVC and since PVC is not bound, ZFS-LocalPV driver will not get the delete call and will leave the ZFSVolume CR hanging there. Reverting the behavior introduced in https://github.com/openebs/zfs-localpv/pull/121, Now PVC will be bound but still ZFSVolume will be in Pending state until the volume is created. Signed-off-by: Pawan --- changelogs/unreleased/145-pawanpraka1 | 1 + pkg/driver/controller.go | 22 ---------------------- pkg/zfs/mount.go | 4 ++-- pkg/zfs/zfs_util.go | 8 +++++--- 4 files changed, 8 insertions(+), 27 deletions(-) create mode 100644 changelogs/unreleased/145-pawanpraka1 diff --git a/changelogs/unreleased/145-pawanpraka1 b/changelogs/unreleased/145-pawanpraka1 new file mode 100644 index 0000000..c2c75da --- /dev/null +++ b/changelogs/unreleased/145-pawanpraka1 @@ -0,0 +1 @@ +fixing stale ZFSVolume resource issue when deleting the pvc in pending state diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index 0d4c976..a2892b4 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -209,16 +209,6 @@ func (cs *controller) CreateVolume( return nil, err } - selected, state, err := zfs.GetZFSVolumeState(req.Name) - - if err == nil { - // ZFSVolume CR has been created, check if it is in Ready state - if state == zfs.ZFSStatusReady { - goto CreateVolumeResponse - } - return nil, status.Errorf(codes.Internal, "volume %s creation is Pending", volName) - } - if contentSource != nil && contentSource.GetSnapshot() != nil { snapshotID := contentSource.GetSnapshot().GetSnapshotId() @@ -231,18 +221,6 @@ func (cs *controller) CreateVolume( return nil, status.Error(codes.Internal, err.Error()) } - _, state, err = zfs.GetZFSVolumeState(req.Name) - - if err != nil { - return nil, status.Errorf(codes.Internal, "createvolume: failed to fetch the volume %v", err.Error()) - } - - if state == zfs.ZFSStatusPending { - return nil, status.Errorf(codes.Internal, "volume %s is being created", volName) - } - -CreateVolumeResponse: - sendEventOrIgnore(volName, strconv.FormatInt(int64(size), 10), "zfs-localpv", analytics.VolumeProvision) topology := map[string]string{zfs.ZFSTopologyKey: selected} diff --git a/pkg/zfs/mount.go b/pkg/zfs/mount.go index fea4357..eab8609 100644 --- a/pkg/zfs/mount.go +++ b/pkg/zfs/mount.go @@ -194,12 +194,12 @@ func MountDataset(vol *apis.ZFSVolume, mount *apis.MountInfo) error { volume := vol.Spec.PoolName + "/" + vol.Name err := verifyMountRequest(vol, mount.MountPath) if err != nil { - return status.Error(codes.Internal, "dataset can not be mounted") + return status.Error(codes.Internal, "invalid mount request") } err = MountZFSDataset(vol, mount.MountPath) if err != nil { - return status.Error(codes.Internal, "not able to mount the dataset") + return status.Errorf(codes.Internal, "zfs: mount failed err : %v", err.Error()) } logrus.Infof("dataset %v mounted %v", volume, mount.MountPath) diff --git a/pkg/zfs/zfs_util.go b/pkg/zfs/zfs_util.go index 0c9c657..9e2bf4a 100644 --- a/pkg/zfs/zfs_util.go +++ b/pkg/zfs/zfs_util.go @@ -20,6 +20,7 @@ import ( "os/exec" "path/filepath" + "fmt" "github.com/Sirupsen/logrus" apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/zfs/v1" ) @@ -379,8 +380,9 @@ func SetDatasetMountProp(volume string, mountpath string) error { if err != nil { logrus.Errorf("zfs: could not set mountpoint on dataset %v cmd %v error: %s", volume, ZFSVolArg, string(out)) + return fmt.Errorf("could not set the mountpoint, %s", string(out)) } - return err + return nil } // MountZFSDataset mounts the dataset to the given mountpoint @@ -412,7 +414,7 @@ func MountZFSDataset(vol *apis.ZFSVolume, mountpath string) error { if err != nil { logrus.Errorf("zfs: could not mount the dataset %v cmd %v error: %s", volume, MountVolArg, string(out)) - return err + return fmt.Errorf("not able to mount, %s", string(out)) } } @@ -452,7 +454,7 @@ func GetVolumeProperty(vol *apis.ZFSVolume, prop string) (string, error) { if err != nil { logrus.Errorf("zfs: could not get %s on dataset %v cmd %v error: %s", prop, volume, ZFSVolArg, string(out)) - return "", err + return "", fmt.Errorf("get %s failed, %s", prop, string(out)) } val := out[:len(out)-1] return string(val), nil