From e6abbbdde323e634e2dbd715b00ec74be1c47624 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 13 May 2019 10:17:17 +0530 Subject: [PATCH 1/2] Fix error string as per golang standard Error string should not be capatalized https://github.com/golang/go/wiki/CodeReviewComments#error-strings Signed-off-by: Madhu Rajanna --- pkg/cephfs/util.go | 4 ++-- pkg/rbd/controllerserver.go | 28 ++++++++++++++-------------- pkg/rbd/nodeserver.go | 14 +++++++------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pkg/cephfs/util.go b/pkg/cephfs/util.go index 25e0e2db5188..193089cb5e5f 100644 --- a/pkg/cephfs/util.go +++ b/pkg/cephfs/util.go @@ -106,12 +106,12 @@ func (cs *ControllerServer) validateCreateVolumeRequest(req *csi.CreateVolumeReq } if req.GetName() == "" { - return status.Error(codes.InvalidArgument, "Volume Name cannot be empty") + return status.Error(codes.InvalidArgument, "volume Name cannot be empty") } reqCaps := req.GetVolumeCapabilities() if reqCaps == nil { - return status.Error(codes.InvalidArgument, "Volume Capabilities cannot be empty") + return status.Error(codes.InvalidArgument, "volume Capabilities cannot be empty") } for _, cap := range reqCaps { diff --git a/pkg/rbd/controllerserver.go b/pkg/rbd/controllerserver.go index 22b06a95783a..b00830e44626 100644 --- a/pkg/rbd/controllerserver.go +++ b/pkg/rbd/controllerserver.go @@ -47,17 +47,17 @@ func (cs *ControllerServer) validateVolumeReq(req *csi.CreateVolumeRequest) erro } // Check sanity of request Name, Volume Capabilities if len(req.Name) == 0 { - return status.Error(codes.InvalidArgument, "Volume Name cannot be empty") + return status.Error(codes.InvalidArgument, "volume Name cannot be empty") } if req.VolumeCapabilities == nil { - return status.Error(codes.InvalidArgument, "Volume Capabilities cannot be empty") + return status.Error(codes.InvalidArgument, "volume Capabilities cannot be empty") } options := req.GetParameters() if value, ok := options["clusterID"]; !ok || len(value) == 0 { - return status.Error(codes.InvalidArgument, "Missing or empty cluster ID to provision volume from") + return status.Error(codes.InvalidArgument, "missing or empty cluster ID to provision volume from") } if value, ok := options["pool"]; !ok || len(value) == 0 { - return status.Error(codes.InvalidArgument, "Missing or empty pool name to provision volume from") + return status.Error(codes.InvalidArgument, "missing or empty pool name to provision volume from") } return nil } @@ -190,12 +190,12 @@ func (cs *ControllerServer) createBackingImage(rbdVol *rbdVolume, req *csi.Creat func (cs *ControllerServer) checkSnapshot(req *csi.CreateVolumeRequest, rbdVol *rbdVolume) error { snapshot := req.VolumeContentSource.GetSnapshot() if snapshot == nil { - return status.Error(codes.InvalidArgument, "Volume Snapshot cannot be empty") + return status.Error(codes.InvalidArgument, "volume Snapshot cannot be empty") } snapshotID := snapshot.GetSnapshotId() if len(snapshotID) == 0 { - return status.Error(codes.InvalidArgument, "Volume Snapshot ID cannot be empty") + return status.Error(codes.InvalidArgument, "volume Snapshot ID cannot be empty") } rbdSnap := &rbdSnapshot{} @@ -203,7 +203,7 @@ func (cs *ControllerServer) checkSnapshot(req *csi.CreateVolumeRequest, rbdVol * if _, ok := err.(ErrSnapNotFound); !ok { return status.Error(codes.Internal, err.Error()) } - return status.Error(codes.InvalidArgument, "Missing requested Snapshot ID") + return status.Error(codes.InvalidArgument, "missing requested Snapshot ID") } err := restoreSnapshot(rbdVol, rbdSnap, rbdVol.AdminID, req.GetSecrets()) @@ -224,7 +224,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol // For now the image get unconditionally deleted, but here retention policy can be checked volumeID := req.GetVolumeId() if volumeID == "" { - return nil, status.Error(codes.InvalidArgument, "Empty volume ID in request") + return nil, status.Error(codes.InvalidArgument, "empty volume ID in request") } volumeIDMutex.LockKey(volumeID) defer func() { @@ -287,11 +287,11 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol // are supported. func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) { if req.GetVolumeId() == "" { - return nil, status.Error(codes.InvalidArgument, "Empty volume ID in request") + return nil, status.Error(codes.InvalidArgument, "empty volume ID in request") } if len(req.VolumeCapabilities) == 0 { - return nil, status.Error(codes.InvalidArgument, "Empty volume capabilities in request") + return nil, status.Error(codes.InvalidArgument, "empty volume capabilities in request") } for _, cap := range req.VolumeCapabilities { @@ -326,7 +326,7 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS err := genVolFromVolID(rbdVol, req.GetSourceVolumeId(), req.GetSecrets()) if err != nil { if _, ok := err.(ErrImageNotFound); ok { - return nil, status.Errorf(codes.NotFound, "Source Volume ID %s not found", req.GetSourceVolumeId()) + return nil, status.Errorf(codes.NotFound, "source Volume ID %s not found", req.GetSourceVolumeId()) } return nil, status.Errorf(codes.Internal, err.Error()) } @@ -402,10 +402,10 @@ func (cs *ControllerServer) validateSnapshotReq(req *csi.CreateSnapshotRequest) // Check sanity of request Snapshot Name, Source Volume Id if len(req.Name) == 0 { - return status.Error(codes.InvalidArgument, "Snapshot Name cannot be empty") + return status.Error(codes.InvalidArgument, "snapshot Name cannot be empty") } if len(req.SourceVolumeId) == 0 { - return status.Error(codes.InvalidArgument, "Source Volume ID cannot be empty") + return status.Error(codes.InvalidArgument, "source Volume ID cannot be empty") } return nil @@ -467,7 +467,7 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS snapshotID := req.GetSnapshotId() if len(snapshotID) == 0 { - return nil, status.Error(codes.InvalidArgument, "Snapshot ID cannot be empty") + return nil, status.Error(codes.InvalidArgument, "snapshot ID cannot be empty") } snapshotIDMutex.LockKey(snapshotID) diff --git a/pkg/rbd/nodeserver.go b/pkg/rbd/nodeserver.go index 20c7a8b0989b..4942feb6fde4 100644 --- a/pkg/rbd/nodeserver.go +++ b/pkg/rbd/nodeserver.go @@ -23,7 +23,7 @@ import ( "regexp" "strings" - "github.com/ceph/ceph-csi/pkg/csi-common" + csicommon "github.com/ceph/ceph-csi/pkg/csi-common" "github.com/ceph/ceph-csi/pkg/util" "github.com/container-storage-interface/spec/lib/go/csi" @@ -46,15 +46,15 @@ type NodeServer struct { func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) { targetPath := req.GetTargetPath() if targetPath == "" { - return nil, status.Error(codes.InvalidArgument, "Empty target path in request") + return nil, status.Error(codes.InvalidArgument, "empty target path in request") } if req.GetVolumeCapability() == nil { - return nil, status.Error(codes.InvalidArgument, "Empty volume capability in request") + return nil, status.Error(codes.InvalidArgument, "empty volume capability in request") } if req.GetVolumeId() == "" { - return nil, status.Error(codes.InvalidArgument, "Empty volume ID in request") + return nil, status.Error(codes.InvalidArgument, "empty volume ID in request") } targetPathMutex.LockKey(targetPath) @@ -190,11 +190,11 @@ func (ns *NodeServer) createTargetPath(targetPath string, isBlock bool) (bool, e func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) { targetPath := req.GetTargetPath() if targetPath == "" { - return nil, status.Error(codes.InvalidArgument, "Empty target path in request") + return nil, status.Error(codes.InvalidArgument, "empty target path in request") } if req.GetVolumeId() == "" { - return nil, status.Error(codes.InvalidArgument, "Empty volume ID in request") + return nil, status.Error(codes.InvalidArgument, "empty volume ID in request") } targetPathMutex.LockKey(targetPath) @@ -217,7 +217,7 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu if notMnt { // TODO should consider deleting path instead of returning error, // once all codes become ready for csi 1.0. - return nil, status.Error(codes.NotFound, "Volume not mounted") + return nil, status.Error(codes.NotFound, "volume not mounted") } devicePath, cnt, err := mount.GetDeviceNameFromMount(ns.mounter, targetPath) From 283814843f67f25c40a8f72eced4a04525b76ac2 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 10 Jun 2019 12:52:13 +0530 Subject: [PATCH 2/2] Fix misspell words Signed-off-by: Madhu Rajanna --- pkg/util/cephcmds.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/util/cephcmds.go b/pkg/util/cephcmds.go index 9dabdb9036b4..bfe997389021 100644 --- a/pkg/util/cephcmds.go +++ b/pkg/util/cephcmds.go @@ -21,13 +21,14 @@ import ( "encoding/json" "fmt" "io/ioutil" - "k8s.io/klog" "os" "os/exec" "strings" + + "k8s.io/klog" ) -// ExecCommand executes passed in program with args and returns seperate stdout and stderr streams +// ExecCommand executes passed in program with args and returns separate stdout and stderr streams func ExecCommand(program string, args ...string) (stdout, stderr []byte, err error) { var ( cmd = exec.Command(program, args...) // nolint: gosec @@ -191,7 +192,7 @@ func GetOMapValue(monitors, adminID, key, poolName, namespace, oMapName, oMapKey klog.Errorf("failed getting omap value for key (%s) from omap (%s) in pool (%s): (%v)", oMapKey, oMapName, poolName, err) - return "", fmt.Errorf("error (%v) occured, command output streams is (%s)", + return "", fmt.Errorf("error (%v) occurred, command output streams is (%s)", err.Error(), stdoutanderr) }