-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(clone): add support for creating the Clone from volume as datasource #234
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add support for creating the Clone from volume as datasource |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -401,6 +401,26 @@ func CreateVolume(vol *apis.ZFSVolume) error { | |
func CreateClone(vol *apis.ZFSVolume) error { | ||
volume := vol.Spec.PoolName + "/" + vol.Name | ||
|
||
if srcVol, ok := vol.Labels[ZFSVolKey]; ok { | ||
// datasource is volume, create the snapshot first | ||
snap := &apis.ZFSSnapshot{} | ||
snap.Name = vol.Name // use volname as snapname | ||
snap.Spec = vol.Spec | ||
// add src vol name | ||
snap.Labels = map[string]string{ZFSVolKey: srcVol} | ||
|
||
klog.Infof("creating snapshot %s@%s for the clone %s", srcVol, snap.Name, volume) | ||
|
||
err := CreateSnapshot(snap) | ||
|
||
if err != nil { | ||
klog.Errorf( | ||
"zfs: could not create snapshot for the clone vol %s snap %s err %v", volume, snap.Name, err, | ||
) | ||
return err | ||
} | ||
} | ||
|
||
if err := getVolume(volume); err != nil { | ||
var args []string | ||
args = buildCloneCreateArgs(vol) | ||
|
@@ -580,6 +600,27 @@ func DestroyVolume(vol *apis.ZFSVolume) error { | |
) | ||
return err | ||
} | ||
|
||
if srcVol, ok := vol.Labels[ZFSVolKey]; ok { | ||
// datasource is volume, delete the dependent snapshot | ||
snap := &apis.ZFSSnapshot{} | ||
snap.Name = vol.Name // snapname is same as volname | ||
snap.Spec = vol.Spec | ||
// add src vol name | ||
snap.Labels = map[string]string{ZFSVolKey: srcVol} | ||
|
||
klog.Infof("destroying snapshot %s@%s for the clone %s", srcVol, snap.Name, volume) | ||
|
||
err := DestroySnapshot(snap) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is where the source volume needs to be cleaned up, in case this was the last clone/snapshot being deleted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, not for the last clone/snapshot being deleted, every clone will have a corresponsing snapshot. So when we are deleting the clone volume, we should delete the corresponding snapshot here. |
||
|
||
if err != nil { | ||
// no need to reconcile as volume has already been deleted | ||
klog.Errorf( | ||
"zfs: could not destroy snapshot for the clone vol %s snap %s err %v", volume, snap.Name, err, | ||
) | ||
} | ||
} | ||
|
||
klog.Infof("destroyed volume %s", volume) | ||
|
||
return nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this a more explicit key - like "source-zfs-volume"?