Skip to content
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

Add clone functionality. #106

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions pkg/glusterfs/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,8 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
return nil, err
}

if req.VolumeContentSource.GetSnapshot().GetSnapshotId() != "" {
snapName := req.VolumeContentSource.GetSnapshot().GetSnapshotId()
glog.V(2).Infof("creating volume from snapshot %s", snapName)
err = cs.checkExistingSnapshot(snapName, req.GetName())
if req.VolumeContentSource.GetType() != nil {
err = cs.cloneVolumeFromSource(volumeName, req.VolumeContentSource)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -184,6 +182,36 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
return resp, nil
}

func (cs *ControllerServer) cloneVolumeFromSource(volName string, volumeSource *csi.VolumeContentSource) error {
var err error
// type
switch volumeSource.Type.(type) {
case *csi.VolumeContentSource_Snapshot:
snapName := volumeSource.GetSnapshot().GetSnapshotId()
glog.V(2).Infof("creating volume from snapshot %s", snapName)
err = cs.checkExistingSnapshot(snapName, volName)
if err != nil {
return err
}
//create snapshot clone
err = cs.createSnapshotClone(snapName, volName)
case *csi.VolumeContentSource_Volume:
parentVol := volumeSource.GetVolume().GetVolumeId()
snapName := volName + parentVol
glog.V(2).Infof("creating volume from volume source %s", snapName)
_, err = cs.createSnapshot(snapName, volName)
if err != nil {
return err
}
err = cs.createSnapshotClone(snapName, volName)

default:
err = status.Errorf(codes.Internal, "Not a proper volume source")
glog.Error(err)
}
return err
}

func (cs *ControllerServer) getVolumeSize(req *csi.CreateVolumeRequest) int64 {
// If capacity mentioned, pick that or use default size 1 GB
volSizeBytes := defaultVolumeSize
Expand Down Expand Up @@ -214,8 +242,7 @@ func (cs *ControllerServer) checkExistingSnapshot(snapName, volName string) erro
return status.Errorf(codes.Internal, "failed to activate snapshot %s", err.Error())
}
}
//create snapshot clone
err = cs.createSnapshotClone(snapName, volName)

return err
}

Expand Down Expand Up @@ -488,6 +515,7 @@ func (cs *ControllerServer) ControllerGetCapabilities(ctx context.Context, req *
csi.ControllerServiceCapability_RPC_LIST_VOLUMES,
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS,
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
} {
caps = append(caps, newCap(cap))
}
Expand Down