From d9d18f2e8f93875532e7f175b012c720df885d49 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Thu, 25 Oct 2018 16:57:51 +0530 Subject: [PATCH] Call Volume info instead of volume status API 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 --- pkg/glusterfs/controllerserver.go | 19 ++++++++++--------- pkg/glusterfs/driver_test.go | 19 ++++++++----------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/pkg/glusterfs/controllerserver.go b/pkg/glusterfs/controllerserver.go index fa885c6a8..78b4a3e34 100644 --- a/pkg/glusterfs/controllerserver.go +++ b/pkg/glusterfs/controllerserver.go @@ -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() @@ -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) } } @@ -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) } diff --git a/pkg/glusterfs/driver_test.go b/pkg/glusterfs/driver_test.go index bcfd4f69b..9c8b93c5d 100644 --- a/pkg/glusterfs/driver_test.go +++ b/pkg/glusterfs/driver_test.go @@ -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) @@ -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