Skip to content

Commit 9583911

Browse files
authored
Merge pull request #135 from Madhu-1/parse-cleanup
Remove redundant function parameters
2 parents b26c7a7 + df20225 commit 9583911

File tree

5 files changed

+56
-45
lines changed

5 files changed

+56
-45
lines changed

pkg/glusterfs/controllerserver.go

+38-33
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,22 @@ const (
2929

3030
var errVolumeNotFound = errors.New("volume not found")
3131

32-
// ControllerServer struct of GlusterFS CSI driver with supported methods of CSI controller server spec.
32+
// ControllerServer struct of GlusterFS CSI driver with supported methods of CSI
33+
// controller server spec.
3334
type ControllerServer struct {
3435
*GfDriver
3536
}
3637

3738
// CsiDrvParam stores csi driver specific request parameters.
3839
// This struct will be used to gather specific fields of CSI driver:
39-
// For eg. csiDrvName, csiDrvVersion..etc
40-
// and also gather parameters passed from SC which not part of gluster volcreate api.
40+
// For eg. csiDrvName, csiDrvVersion..etc and also gather
41+
// parameters passed from SC which not part of gluster volcreate api.
4142
// GlusterCluster - The resturl of gluster cluster
4243
// GlusterUser - The gluster username who got access to the APIs.
43-
// GlusterUserToken - The password/token of glusterUser to connect to glusterCluster
44-
// GlusterVersion - Says the version of the glustercluster running in glusterCluster endpoint.
44+
// GlusterUserToken - The password/token of glusterUser to connect to
45+
// glusterCluster.
46+
// GlusterVersion - Says the version of the glustercluster
47+
// running in glusterCluster endpoint.
4548
// All of these fields are optional and can be used if needed.
4649
type CsiDrvParam struct {
4750
GlusterCluster string
@@ -52,13 +55,15 @@ type CsiDrvParam struct {
5255
CsiDrvVersion string
5356
}
5457

55-
// ProvisionerConfig is the combined configuration of gluster cli vol create request and CSI driver specific input
58+
// ProvisionerConfig is the combined configuration of gluster cli vol create
59+
// request and CSI driver specific input
5660
type ProvisionerConfig struct {
5761
gdVolReq *api.VolCreateReq
58-
//csiConf *CsiDrvParam
62+
// csiConf *CsiDrvParam
5963
}
6064

61-
// ParseCreateVolRequest parse incoming volume create request and fill ProvisionerConfig.
65+
// ParseCreateVolRequest parse incoming volume create request and fill
66+
// ProvisionerConfig.
6267
func (cs *ControllerServer) ParseCreateVolRequest(req *csi.CreateVolumeRequest) (*ProvisionerConfig, error) {
6368

6469
var reqConf ProvisionerConfig
@@ -79,7 +84,7 @@ func (cs *ControllerServer) ParseCreateVolRequest(req *csi.CreateVolumeRequest)
7984

8085
case "replicas":
8186
replicas := v
82-
replicaCount, err = parseVolumeParamInt(replicas, minReplicaCount, maxReplicaCount)
87+
replicaCount, err = parseVolumeParamInt(replicas)
8388
if err != nil {
8489
return nil, fmt.Errorf("invalid value for parameter '%s', %v", k, err)
8590
}
@@ -94,18 +99,18 @@ func (cs *ControllerServer) ParseCreateVolRequest(req *csi.CreateVolumeRequest)
9499
return &reqConf, nil
95100
}
96101

97-
func parseVolumeParamInt(valueString string, min int, max int) (int, error) {
102+
func parseVolumeParamInt(valueString string) (int, error) {
98103

99104
count, err := strconv.Atoi(valueString)
100105
if err != nil {
101-
return 0, fmt.Errorf("value '%s' must be an integer between %d and %d", valueString, min, max)
106+
return 0, fmt.Errorf("value '%s' must be an integer between %d and %d", valueString, minReplicaCount, maxReplicaCount)
102107
}
103108

104-
if count < min {
105-
return 0, fmt.Errorf("value '%s' must be >= %v", valueString, min)
109+
if count < minReplicaCount {
110+
return 0, fmt.Errorf("value '%s' must be >= %v", valueString, minReplicaCount)
106111
}
107-
if count > max {
108-
return 0, fmt.Errorf("value '%s' must be <= %v", valueString, max)
112+
if count > maxReplicaCount {
113+
return 0, fmt.Errorf("value '%s' must be <= %v", valueString, maxReplicaCount)
109114
}
110115

111116
return count, nil
@@ -155,9 +160,9 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
155160
}
156161
err = cs.client.VolumeStart(volumeName, true)
157162
if err != nil {
158-
//we dont need to delete the volume if volume start fails
159-
//as we are listing the volumes and starting it again
160-
//before sending back the response
163+
// we dont need to delete the volume if volume start fails as we are
164+
// listing the volumes and starting it again before sending back the
165+
// response
161166
glog.Errorf("failed to start volume: %v", err)
162167
return nil, status.Errorf(codes.Internal, "failed to start volume: %v", err)
163168
}
@@ -197,7 +202,7 @@ func (cs *ControllerServer) checkExistingSnapshot(snapName, volName string) erro
197202
snapInfo, err := cs.client.SnapshotInfo(snapName)
198203
if err != nil {
199204
errResp := cs.client.LastErrorResponse()
200-
//errResp will be nil in case of No route to host error
205+
// errResp will be nil in case of No route to host error
201206
if errResp != nil && errResp.StatusCode == http.StatusNotFound {
202207
return status.Errorf(codes.NotFound, "failed to get snapshot info %s", err.Error())
203208
}
@@ -214,7 +219,7 @@ func (cs *ControllerServer) checkExistingSnapshot(snapName, volName string) erro
214219
return status.Errorf(codes.Internal, "failed to activate snapshot %s", err.Error())
215220
}
216221
}
217-
//create snapshot clone
222+
// create snapshot clone
218223
err = cs.createSnapshotClone(snapName, volName)
219224
return err
220225
}
@@ -269,7 +274,7 @@ func (cs *ControllerServer) doVolumeCreate(volumeName string, volSizeBytes int64
269274
if err != nil {
270275
glog.Errorf("failed to create volume: %v", err)
271276
errResp := cs.client.LastErrorResponse()
272-
//errResp will be nil in case of `No route to host` error
277+
// errResp will be nil in case of `No route to host` error
273278
if errResp != nil && errResp.StatusCode == http.StatusConflict {
274279
return status.Errorf(codes.Aborted, "volume create already in process: %v", err)
275280
}
@@ -285,7 +290,7 @@ func (cs *ControllerServer) checkExistingVolume(volumeName string, volSizeBytes
285290
vol, err := cs.client.Volumes(volumeName)
286291
if err != nil {
287292
errResp := cs.client.LastErrorResponse()
288-
//errResp will be nil in case of `No route to host` error
293+
// errResp will be nil in case of `No route to host` error
289294
if errResp != nil && errResp.StatusCode == http.StatusNotFound {
290295
return errVolumeNotFound
291296
}
@@ -304,7 +309,7 @@ func (cs *ControllerServer) checkExistingVolume(volumeName string, volSizeBytes
304309
return status.Errorf(codes.AlreadyExists, "volume %s already exits with different size: %d", volInfo.Name, volInfo.Capacity)
305310
}
306311

307-
//volume has not started, start the volume
312+
// volume has not started, start the volume
308313
if volInfo.State != api.VolStarted {
309314
err = cs.client.VolumeStart(volInfo.Name, true)
310315
if err != nil {
@@ -362,7 +367,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
362367

363368
if err != nil {
364369
errResp := cs.client.LastErrorResponse()
365-
//errResp will be nil in case of `No route to host` error
370+
// errResp will be nil in case of `No route to host` error
366371
if errResp != nil && errResp.StatusCode == http.StatusNotFound {
367372
return &csi.DeleteVolumeResponse{}, nil
368373
}
@@ -376,7 +381,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
376381
err = cs.client.VolumeDelete(req.VolumeId)
377382
if err != nil {
378383
errResp := cs.client.LastErrorResponse()
379-
//errResp will be nil in case of No route to host error
384+
// errResp will be nil in case of No route to host error
380385
if errResp != nil && errResp.StatusCode == http.StatusNotFound {
381386
return &csi.DeleteVolumeResponse{}, nil
382387
}
@@ -455,7 +460,7 @@ func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req
455460

456461
// ListVolumes returns a list of volumes
457462
func (cs *ControllerServer) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {
458-
//Fetch all the volumes in the TSP
463+
// Fetch all the volumes in the TSP
459464
volumes, err := cs.client.Volumes("")
460465
if err != nil {
461466
return nil, status.Error(codes.Internal, err.Error())
@@ -523,7 +528,7 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
523528
if err != nil {
524529
glog.Errorf("failed to get snapshot info for %v with Error %v", req.GetName(), err.Error())
525530
errResp := cs.client.LastErrorResponse()
526-
//errResp will be nil in case of No route to host error
531+
// errResp will be nil in case of No route to host error
527532
if errResp != nil && errResp.StatusCode != http.StatusNotFound {
528533

529534
return nil, status.Errorf(codes.Internal, "CreateSnapshot - failed to get snapshot info %s", err.Error())
@@ -583,7 +588,7 @@ func (cs *ControllerServer) doSnapshot(name, sourceVolID string) (*api.SnapCreat
583588
if err != nil {
584589
glog.Errorf("failed to create snapshot %v", err)
585590
errResp := cs.client.LastErrorResponse()
586-
//errResp will be nil in case of `No route to host` error
591+
// errResp will be nil in case of `No route to host` error
587592
if errResp != nil && errResp.StatusCode == http.StatusConflict {
588593
return nil, status.Errorf(codes.Aborted, "snapshot create already in process: %v", err)
589594
}
@@ -613,7 +618,7 @@ func (cs *ControllerServer) validateCreateSnapshotReq(req *csi.CreateSnapshotReq
613618
return status.Error(codes.InvalidArgument, "CreateSnapshot - sourceVolumeId is nil")
614619
}
615620
if req.GetName() == req.GetSourceVolumeId() {
616-
//In glusterd2 we cannot create a snapshot as same name as volume name
621+
// In glusterd2 we cannot create a snapshot as same name as volume name
617622
return status.Error(codes.InvalidArgument, "CreateSnapshot - sourceVolumeId and snapshot name cannot be same")
618623
}
619624
return nil
@@ -673,7 +678,7 @@ func (cs *ControllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
673678
return cs.listSnapshotFromID(req.GetSnapshotId())
674679
}
675680

676-
//If volume id is sent
681+
// If volume id is sent
677682
if len(req.GetSourceVolumeId()) != 0 {
678683
snaplist, err = cs.client.SnapshotList(req.SourceVolumeId)
679684
if err != nil {
@@ -686,7 +691,7 @@ func (cs *ControllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
686691
return nil, status.Errorf(codes.Internal, "ListSnapshot - failed to get snapshots %s", err.Error())
687692
}
688693
} else {
689-
//Get all snapshots
694+
// Get all snapshots
690695
snaplist, err = cs.client.SnapshotList("")
691696
if err != nil {
692697
glog.Errorf("failed to list snapshots %v", err)
@@ -755,8 +760,8 @@ func (cs *ControllerServer) doPagination(req *csi.ListSnapshotsRequest, snapList
755760

756761
}
757762

758-
//TODO need to remove paginating code once glusterd2 issue
759-
//https://github.com/gluster/glusterd2/issues/372 is merged
763+
// TODO need to remove paginating code once glusterd2 issue
764+
// https://github.com/gluster/glusterd2/issues/372 is merged
760765
var (
761766
maximumEntries = req.MaxEntries
762767
nextToken int32

pkg/glusterfs/driver.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const (
1313
glusterfsCSIDriverVersion = "0.0.9"
1414
)
1515

16-
// GfDriver is the struct embedding information about the connection to gluster cluster and configuration of CSI driver.
16+
// GfDriver is the struct embedding information about the connection to gluster
17+
// cluster and configuration of CSI driver.
1718
type GfDriver struct {
1819
client *restclient.Client
1920
*utils.Config
@@ -63,7 +64,8 @@ func NewIdentityServer(g *GfDriver) *IdentityServer {
6364
}
6465
}
6566

66-
// Run start a non-blocking grpc controller,node and identityserver for GlusterFS CSI driver which can serve multiple parallel requests
67+
// Run start a non-blocking grpc controller,node and identityserver for
68+
// GlusterFS CSI driver which can serve multiple parallel requests
6769
func (g *GfDriver) Run() {
6870
srv := csicommon.NewNonBlockingGRPCServer()
6971
srv.Start(g.Endpoint, NewIdentityServer(g), NewControllerServer(g), NewNodeServer(g))

pkg/glusterfs/identityserver.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77
"github.com/golang/glog"
88
)
99

10-
// IdentityServer struct of Glusterfs CSI driver with supported methods of CSI identity server spec.
10+
// IdentityServer struct of Glusterfs CSI driver with supported methods of CSI
11+
// identity server spec.
1112
type IdentityServer struct {
1213
*GfDriver
1314
}

pkg/glusterfs/nodeserver.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import (
1414
"k8s.io/kubernetes/pkg/volume/util"
1515
)
1616

17-
// NodeServer struct of Glusterfs CSI driver with supported methods of CSI node server spec.
17+
// NodeServer struct of Glusterfs CSI driver with supported methods of CSI node
18+
// server spec.
1819
type NodeServer struct {
1920
*GfDriver
2021
}
@@ -31,7 +32,8 @@ func (ns *NodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
3132
return nil, status.Error(codes.Unimplemented, "")
3233
}
3334

34-
// NodePublishVolume mounts the volume mounted to the staging path to the target path
35+
// NodePublishVolume mounts the volume mounted to the staging path to the target
36+
// path
3537
func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
3638
glog.V(2).Infof("received node publish volume request %+v", req)
3739

@@ -82,10 +84,11 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
8284
return &csi.NodePublishVolumeResponse{}, nil
8385
}
8486

85-
// NodeGetVolumeStats returns volume capacity statistics available for the volume
87+
// NodeGetVolumeStats returns volume capacity statistics available for the
88+
// volume
8689
func (ns *NodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) {
8790

88-
//TODO need to implement volume status call
91+
// TODO need to implement volume status call
8992
return nil, status.Error(codes.Unimplemented, "")
9093

9194
}

pkg/glusterfs/utils/config.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ const (
88
TB int64 = 1000 * GB
99
)
1010

11-
// RoundUpSize calculates how many allocation units are needed to accommodate
12-
// a volume of given size.
13-
// RoundUpSize(1500 * 1000*1000, 1000*1000*1000) returns '2'
14-
// (2 GB is the smallest allocatable volume that can hold 1500MiB)
11+
// RoundUpSize calculates how many allocation units are needed to accommodate a
12+
// volume of given size.
13+
// RoundUpSize(1500 * 1000*1000, 1000*1000*1000) returns
14+
// '2' (2 GB is the smallest allocatable volume that can hold 1500MiB)
1515
func RoundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 {
1616
return (volumeSizeBytes + allocationUnitBytes - 1) / allocationUnitBytes
1717
}
@@ -30,7 +30,7 @@ type Config struct {
3030
RestSecret string // GD2 user password
3131
}
3232

33-
//NewConfig returns config struct to initialize new driver
33+
// NewConfig returns config struct to initialize new driver
3434
func NewConfig() *Config {
3535
return &Config{}
3636
}

0 commit comments

Comments
 (0)