Skip to content

Commit

Permalink
fix(pvc): fixing stale ZFSVolume CR issue when deleting pending PVC
Browse files Browse the repository at this point in the history
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 #121,
Now PVC will be bound but still ZFSVolume will be in Pending state until the volume is created.

Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 authored and kmova committed Jun 8, 2020
1 parent 0e22239 commit 45015bf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 27 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/145-pawanpraka1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixing stale ZFSVolume resource issue when deleting the pvc in pending state
22 changes: 0 additions & 22 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions pkg/zfs/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions pkg/zfs/zfs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 45015bf

Please sign in to comment.