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

Create a cloned OpenEBS (jiva) Volume from a snapshot #283

Merged
merged 3 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Enahance volume API to support volume clone
This PR will extend the maya-apiserver volume create
API's to create volume clone feature.

Signed-off-by: prateekpandey14 <prateekpandey14@gmail.com>
  • Loading branch information
prateekpandey14 committed Mar 27, 2018
commit c71528da32a2db43b71d095a565b054c66388bfa
13 changes: 0 additions & 13 deletions cmd/maya-apiserver/app/server/snapshot_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ func (s *HTTPServer) snapshotSpecificRequest(resp http.ResponseWriter, req *http
return s.snapshotCreate(resp, req)
case strings.Contains(path, "/revert/"):
return s.snapshotRevert(resp, req)
case strings.Contains(path, "/clone/"):
return s.snapshotClone(resp, req)
case strings.Contains(path, "/list"):
volName := strings.TrimPrefix(path, "/list/")
return s.snapshotList(resp, req, volName)
Expand Down Expand Up @@ -169,17 +167,6 @@ func (s *HTTPServer) snapshotList(resp http.ResponseWriter, req *http.Request, v

}

// SnapshotClone is http handler for restore a snapshot to a persistent volume
func (s *HTTPServer) snapshotClone(resp http.ResponseWriter, req *http.Request) (interface{}, error) {

clone, err := s.volumeAdd(resp, req)
if err != nil {
return nil, err
}

return clone, nil
}

/*func (s *HTTPServer) getControllerIP(resp http.ResponseWriter, req *http.Request, snap.Spec.Volname string) (string, err) {
voldetails, err := s.vsmRead(resp, req, snap.Spec.VolumeName)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion orchprovider/k8s/v1/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ func (k *k8sOrchestrator) createReplicaDeployment(volProProfile volProfile.Volum
return nil, err
}

glog.Infof("Successfully added replica(s) 'count: %d' for Volume '%s'", rCount, d.Name)
glog.Infof("Successfully added replica(s) 'count: %d' for Volume '%s'", *rCount, d.Name)

//glog.Infof("Successfully added replica #%d for VSM '%s'", rcIndex, d.Name)
//} -- end of for loop -- if manual replica addition
Expand Down
6 changes: 4 additions & 2 deletions types/v1/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ const (
// This is replaced at runtime
JivaCloneIPHolder JivaAnnotations = "__CLONE_IP__"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we calling these as annotations? I guess this is an old type that we are re-using. But lets make it a point to avoid once we feel that this design/code is not good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, these are coming from the Volume struct, just using this to pass as replica args .


JivaReplicaTypeHolder JivaAnnotations = "clone"
//JivaReplicaTypeHolder JivaAnnotations = "clone"
JivaSnapNameHolder JivaAnnotations = "__SNAPNAME__"

// JivaStorageSizeHolder is used as a placeholder for persistent volume's
// storage capacity
//
Expand Down Expand Up @@ -621,7 +623,7 @@ var (
JivaReplicaArgs = []string{"replica", "--frontendIP", string(JivaClusterIPHolder), "--size", string(JivaStorageSizeHolder), string(JivaPersistentMountPathDef)}

// JivaCloneReplicaArgs is the set of arguments provided to JivaReplicaCmd
JivaCloneReplicaArgs = []string{"replica", "--frontendIP", string(JivaClusterIPHolder), "--cloneIP", string(JivaCloneIPHolder), "--type", string(JivaReplicaTypeHolder), "--size", string(JivaStorageSizeHolder), string(JivaPersistentMountPathDef)}
JivaCloneReplicaArgs = []string{"replica", "--frontendIP", string(JivaClusterIPHolder), "--cloneIP", string(JivaCloneIPHolder), "--type", string("clone"), "--snapName", string(JivaSnapNameHolder), "--size", string(JivaStorageSizeHolder), string(JivaPersistentMountPathDef)}
)

// TODO
Expand Down
8 changes: 6 additions & 2 deletions types/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ type Volume struct {
// - `true` indicates monitoring is required & should use the defaults
Monitor string `json:"monitor,omitempty" protobuf:"bytes,1,opt,name=monitor"`

// CloneIP is the sync controller IP which will be used to sync and rebuild
// the clone replica
// CloneIP is the source controller IP which will be used to make a sync and rebuild
// request from the new clone replica.
CloneIP string `json:"cloneIP,omitempty" protobuf:"bytes,1,opt,name=cloneIP"`

// SnapshotName name of snapshot which is getting promoted as persistent
// volume(this snapshot will be cloned to new volume).
SnapshotName string `json:"snapshotName,omitempty" protobuf:"bytes,1,opt,name=snapshotName"`
// Specs contains the desired specifications the volume should have.
// +optional
Specs []VolumeSpec `json:"specs,omitempty" protobuf:"bytes,2,rep,name=specs"`
Expand Down
8 changes: 6 additions & 2 deletions types/v1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,25 +925,29 @@ func MakeOrDefJivaReplicaArgs(vol *Volume, clusterIP string) []string {
//storSize := GetPVPStorageSize(profileMap)
storSize := vol.Capacity
cloneIP := vol.CloneIP
snapshotName := vol.SnapshotName

repArgs := make([]string, len(JivaReplicaArgs))
//repArgs := make([]string, len(JivaReplicaArgs))
if cloneIP == "" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe its best to avoid this if else by structuring the code better.
Probably a new struct that deals with clone would have been great.
When the complexity arises with new business logic/features, a well defined struct will be able to handle this better.

repArgs := make([]string, len(JivaReplicaArgs))
for i, rArg := range JivaReplicaArgs {
rArg = strings.Replace(rArg, string(JivaClusterIPHolder), clusterIP, 1)
rArg = strings.Replace(rArg, string(JivaStorageSizeHolder), storSize, 1)
repArgs[i] = rArg
}
return repArgs
} else {
repArgs := make([]string, len(JivaCloneReplicaArgs))
for i, rArg := range JivaCloneReplicaArgs {
rArg = strings.Replace(rArg, string(JivaClusterIPHolder), clusterIP, 1)
rArg = strings.Replace(rArg, string(JivaStorageSizeHolder), storSize, 1)
rArg = strings.Replace(rArg, string(JivaCloneIPHolder), cloneIP, 1)
rArg = strings.Replace(rArg, string(JivaSnapNameHolder), snapshotName, 1)
repArgs[i] = rArg

}
return repArgs
}
return repArgs
}

// DefaultJivaISCSIPort will provide the port required to make ISCSI based
Expand Down