Skip to content

Commit

Permalink
Call Volume info instead of volume status API
Browse files Browse the repository at this point in the history
After volume creation, suppose glusterd2
or CSI driver fails, as the volume is
not in the started state we won't be able to
get the volume status. as part of checking
the existing volume we don't need to call
volume status API, we can call volume info
and check volume is present or not.

Signed-off-by: Madhu Rajanna <mrajanna@redhat.com>
  • Loading branch information
Madhu-1 committed Oct 25, 2018
1 parent e5df356 commit d9d18f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
19 changes: 10 additions & 9 deletions pkg/glusterfs/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (cs *ControllerServer) doVolumeCreate(volumeName string, volSizeMB int) err
}

func (cs *ControllerServer) checkExistingVolume(volumeName string, volSizeMB int) error {
vol, err := cs.client.VolumeStatus(volumeName)
vol, err := cs.client.Volumes(volumeName)
if err != nil {
glog.Errorf("failed to fetch volume : %v", err)
errResp := cs.client.LastErrorResponse()
Expand All @@ -191,21 +191,22 @@ func (cs *ControllerServer) checkExistingVolume(volumeName string, volSizeMB int
return status.Errorf(codes.Internal, "error in fetching volume details %v", err)
}

volInfo := vol[0]
// Do the owner validation
if glusterAnnVal, found := vol.Info.Metadata[volumeOwnerAnn]; !found || (found && glusterAnnVal != glusterfsCSIDriverName) {
if glusterAnnVal, found := volInfo.Metadata[volumeOwnerAnn]; !found || (found && glusterAnnVal != glusterfsCSIDriverName) {
return status.Errorf(codes.Internal, "volume %s (%s) is not owned by GlusterFS CSI driver",
vol.Info.Name, vol.Info.Metadata)
volInfo.Name, volInfo.Metadata)
}

if int(vol.Size.Capacity) != volSizeMB {
return status.Errorf(codes.AlreadyExists, "volume %s already exits with different size: %d", vol.Info.Name, vol.Size.Capacity)
if int(volInfo.Capacity) != volSizeMB {
return status.Errorf(codes.AlreadyExists, "volume %s already exits with different size: %d", volInfo.Name, volInfo.Capacity)
}

//volume has not started, start the volume
if !vol.Online {
err = cs.client.VolumeStart(vol.Info.Name, true)
if volInfo.State != api.VolStarted {
err = cs.client.VolumeStart(volInfo.Name, true)
if err != nil {
return status.Errorf(codes.Internal, "failed to start volume %s: %v", vol.Info.Name, err)
return status.Errorf(codes.Internal, "failed to start volume %s: %v", volInfo.Name, err)
}
}

Expand Down Expand Up @@ -310,7 +311,7 @@ func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req
return nil, status.Error(codes.InvalidArgument, "ValidateVolumeCapabilities() - VolumeCapabilities is nil")
}

_, err := cs.client.VolumeStatus(req.VolumeId)
_, err := cs.client.Volumes(volumeID)
if err != nil {
return nil, status.Errorf(codes.NotFound, "ValidateVolumeCapabilities() - %v", err)
}
Expand Down
19 changes: 8 additions & 11 deletions pkg/glusterfs/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ func handleGETRequest(w http.ResponseWriter, r *http.Request, t *testing.T) {
return
}

if strings.HasSuffix(r.URL.String(), "/v1/volumes") {
if r.URL.String() == "/v1/volumes" {
resp := make(api.VolumeListResp, 1)
resp[0] = api.VolumeGetResp{
ID: id,
Name: "test1",
Metadata: map[string]string{volumeOwnerAnn: glusterfsCSIDriverName},
State: api.VolStarted,
Capacity: 1000,
}
writeResp(w, http.StatusOK, resp, t)
Expand All @@ -132,16 +133,12 @@ func handleGETRequest(w http.ResponseWriter, r *http.Request, t *testing.T) {

vol := strings.Split(strings.Trim(r.URL.String(), "/"), "/")
if checkVolume(vol[2]) {
resp := api.VolumeStatusResp{
Info: api.VolumeInfo{
ID: id,
Name: vol[2],
Metadata: map[string]string{volumeOwnerAnn: glusterfsCSIDriverName},
},
Online: true,
Size: api.SizeInfo{
Capacity: volumeCache[vol[2]],
},
resp := api.VolumeGetResp{
ID: id,
Name: vol[2],
Metadata: map[string]string{volumeOwnerAnn: glusterfsCSIDriverName},
State: api.VolStarted,
Capacity: volumeCache[vol[2]],
}
writeResp(w, http.StatusOK, resp, t)
return
Expand Down

0 comments on commit d9d18f2

Please sign in to comment.