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
Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 committed Jan 7, 2021
1 parent bd6df9b commit 9003572
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 91 deletions.
8 changes: 8 additions & 0 deletions deploy/yamls/zfssnapshot-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ spec:
successfully
properties:
state:
description: State specifies the current state of the snapshot provisioning
request. The state "Pending" means that the snapshot creation request
has not processed yet. The state "Ready" means that the snapshot
has been created and it is ready for the use.
enum:
- Pending
- Ready
- Failed
type: string
type: object
required:
Expand Down
1 change: 1 addition & 0 deletions deploy/yamls/zfsvolume-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ spec:
enum:
- Pending
- Ready
- Failed
type: string
type: object
required:
Expand Down
9 changes: 9 additions & 0 deletions deploy/zfs-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ spec:
enum:
- Pending
- Ready
- Failed
type: string
type: object
required:
Expand Down Expand Up @@ -645,6 +646,14 @@ spec:
successfully
properties:
state:
description: State specifies the current state of the snapshot provisioning
request. The state "Pending" means that the snapshot creation request
has not processed yet. The state "Ready" means that the snapshot
has been created and it is ready for the use.
enum:
- Pending
- Ready
- Failed
type: string
type: object
required:
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/openebs.io/zfs/v1/zfssnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ type ZFSSnapshotList struct {

// SnapStatus string that reflects if the snapshot was cretaed successfully
type SnapStatus struct {
// State specifies the current state of the snapshot provisioning request.
// The state "Pending" means that the snapshot creation request has not
// processed yet. The state "Ready" means that the snapshot has been created
// and it is ready for the use.
// +kubebuilder:validation:Enum=Pending;Ready;Failed
State string `json:"state,omitempty"`
}
2 changes: 1 addition & 1 deletion pkg/apis/openebs.io/zfs/v1/zfsvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,6 @@ type VolStatus struct {
// The state "Pending" means that the volume creation request has not
// processed yet. The state "Ready" means that the volume has been created
// and it is ready for the use.
// +kubebuilder:validation:Enum=Pending;Ready
// +kubebuilder:validation:Enum=Pending;Ready;Failed
State string `json:"state,omitempty"`
}
86 changes: 7 additions & 79 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,55 +101,6 @@ func getRoundedCapacity(size int64) int64 {
return ((size + Mi - 1) / Mi) * Mi
}

func waitForReadyVolume(volname string) error {
for true {
vol, err := zfs.GetZFSVolume(volname)
if err != nil {
return status.Errorf(codes.Internal,
"zfs: wait failed, not able to get the volume %s %s", volname, err.Error())
}

switch vol.Status.State {
case zfs.ZFSStatusReady:
return nil
}
time.Sleep(time.Second)
}
return nil
}

func waitForVolDestroy(volname string) error {
for true {
_, err := zfs.GetZFSVolume(volname)
if err != nil {
if k8serror.IsNotFound(err) {
return nil
}
return status.Errorf(codes.Internal,
"zfs: destroy wait failed, not able to get the volume %s %s", volname, err.Error())
}
time.Sleep(time.Second)
}
return nil
}

func waitForReadySnapshot(snapname string) error {
for true {
snap, err := zfs.GetZFSSnapshot(snapname)
if err != nil {
return status.Errorf(codes.Internal,
"zfs: wait failed, not able to get the snapshot %s %s", snapname, err.Error())
}

switch snap.Status.State {
case zfs.ZFSStatusReady:
return nil
}
time.Sleep(time.Second)
}
return nil
}

// CreateZFSVolume create new zfs volume from csi volume request
func CreateZFSVolume(req *csi.CreateVolumeRequest) (string, error) {
volName := strings.ToLower(req.GetName())
Expand Down Expand Up @@ -180,19 +131,11 @@ func CreateZFSVolume(req *csi.CreateVolumeRequest) (string, error) {
capacity := strconv.FormatInt(int64(size), 10)

if vol, err := zfs.GetZFSVolume(volName); err == nil {
if vol.DeletionTimestamp != nil {
if _, ok := parameters["wait"]; ok {
if err := waitForVolDestroy(volName); err != nil {
return "", err
}
}
} else {
if vol.Spec.Capacity != capacity {
return "", status.Errorf(codes.AlreadyExists,
"volume %s already present", volName)
}
return vol.Spec.OwnerNodeID, nil
if vol.Spec.Capacity != capacity {
return "", status.Errorf(codes.AlreadyExists,
"volume %s already present", volName)
}
return vol.Spec.OwnerNodeID, nil
}

nmap, err := getNodeMap(schld, pool)
Expand Down Expand Up @@ -238,7 +181,7 @@ func CreateZFSVolume(req *csi.CreateVolumeRequest) (string, error) {
err = zfs.ProvisionVolume(volObj)
if err != nil {
return "", status.Errorf(codes.Internal,
"not able to provision the volume %s", err.Error())
"not able to provision the volume err : %s", err.Error())
}

return selected, nil
Expand Down Expand Up @@ -286,7 +229,7 @@ func CreateVolClone(req *csi.CreateVolumeRequest, srcVol string) (string, error)
err = zfs.ProvisionVolume(volObj)
if err != nil {
return "", status.Errorf(codes.Internal,
"clone: not able to provision the volume %s", err.Error())
"clone: not able to provision the volume err : %s", err.Error())
}

return selected, nil
Expand Down Expand Up @@ -339,7 +282,7 @@ func CreateSnapClone(req *csi.CreateVolumeRequest, snapshot string) (string, err
err = zfs.ProvisionVolume(volObj)
if err != nil {
return "", status.Errorf(codes.Internal,
"not able to provision the clone volume %s", err.Error())
"not able to provision the clone volume err : %s", err.Error())
}

return selected, nil
Expand Down Expand Up @@ -381,12 +324,6 @@ func (cs *controller) CreateVolume(
return nil, err
}

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

sendEventOrIgnore(pvcName, volName, strconv.FormatInt(int64(size), 10), "zfs-localpv", analytics.VolumeProvision)

topology := map[string]string{zfs.ZFSTopologyKey: selected}
Expand Down Expand Up @@ -678,15 +615,6 @@ func (cs *controller) CreateSnapshot(
)
}

originalParams := req.GetParameters()
parameters := helpers.GetCaseInsensitiveMap(&originalParams)

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

state, _ = zfs.GetZFSSnapshotStatus(snapName)

return csipayload.NewCreateSnapshotResponseBuilder().
Expand Down
8 changes: 5 additions & 3 deletions pkg/mgmt/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ func (c *SnapController) syncSnap(snap *apis.ZFSSnapshot) error {
zfs.RemoveSnapFinalizer(snap)
}
} else {
// if finalizer is not set then it means we are creating
// status pendnig means we are creating
// the zfs snapshot.
if snap.Finalizers == nil {
if snap.Status.State == zfs.ZFSStatusPending {
err = zfs.CreateSnapshot(snap)
if err == nil {
err = zfs.UpdateSnapInfo(snap)
err = zfs.UpdateSnapInfo(snap, zfs.ZFSStatusReady)
} else {
err = zfs.UpdateSnapInfo(snap, zfs.ZFSStatusFailed)
}
}
}
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
Loading

0 comments on commit 9003572

Please sign in to comment.