Skip to content

Commit

Permalink
feat(zfspv): wait for zfs volume to be created
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanpraka1 committed Jan 4, 2021
1 parent 2e5e61d commit ecc6c8d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
12 changes: 7 additions & 5 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func getRoundedCapacity(size int64) int64 {
return ((size + Mi - 1) / Mi) * Mi
}

func waitForReadyVolume(volname string) error {
func checkVolCreation(volname string) error {
for true {
vol, err := zfs.GetZFSVolume(volname)
if err != nil {
Expand All @@ -112,6 +112,10 @@ func waitForReadyVolume(volname string) error {
switch vol.Status.State {
case zfs.ZFSStatusReady:
return nil
case zfs.ZFSStatusFailed:
// delete the volume
zfs.DeleteVolume(volname)
return status.Errorf(codes.Internal, "zfs: not able to get create the volume")
}
time.Sleep(time.Second)
}
Expand Down Expand Up @@ -381,10 +385,8 @@ func (cs *controller) CreateVolume(
return nil, err
}

if _, ok := parameters["wait"]; ok {
if err := waitForReadyVolume(volName); err != nil {
return nil, err
}
if err := checkVolCreation(volName); err != nil {
return nil, err
}

sendEventOrIgnore(pvcName, volName, strconv.FormatInt(int64(size), 10), "zfs-localpv", analytics.VolumeProvision)
Expand Down
4 changes: 3 additions & 1 deletion pkg/mgmt/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ func (c *ZVController) syncZV(zv *apis.ZFSVolume) error {
err = zfs.CreateVolume(zv)
}
if err == nil {
err = zfs.UpdateZvolInfo(zv)
err = zfs.UpdateZvolInfo(zv, zfs.ZFSStatusReady)
} else {
err = zfs.UpdateZvolInfo(zv, zfs.ZFSStatusFailed)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/zfs/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func GetZFSVolumeState(volID string) (string, string, error) {
}

// UpdateZvolInfo updates ZFSVolume CR with node id and finalizer
func UpdateZvolInfo(vol *apis.ZFSVolume) error {
func UpdateZvolInfo(vol *apis.ZFSVolume, status string) error {
finalizers := []string{ZFSFinalizer}
labels := map[string]string{ZFSNodeKey: NodeID}

Expand All @@ -189,7 +189,7 @@ func UpdateZvolInfo(vol *apis.ZFSVolume) error {

newVol, err := volbuilder.BuildFrom(vol).
WithFinalizer(finalizers).
WithVolumeStatus(ZFSStatusReady).
WithVolumeStatus(status).
WithLabels(labels).Build()

if err != nil {
Expand Down

0 comments on commit ecc6c8d

Please sign in to comment.