@@ -29,19 +29,22 @@ const (
29
29
30
30
var errVolumeNotFound = errors .New ("volume not found" )
31
31
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.
33
34
type ControllerServer struct {
34
35
* GfDriver
35
36
}
36
37
37
38
// CsiDrvParam stores csi driver specific request parameters.
38
39
// 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.
41
42
// GlusterCluster - The resturl of gluster cluster
42
43
// 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.
45
48
// All of these fields are optional and can be used if needed.
46
49
type CsiDrvParam struct {
47
50
GlusterCluster string
@@ -52,13 +55,15 @@ type CsiDrvParam struct {
52
55
CsiDrvVersion string
53
56
}
54
57
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
56
60
type ProvisionerConfig struct {
57
61
gdVolReq * api.VolCreateReq
58
- //csiConf *CsiDrvParam
62
+ // csiConf *CsiDrvParam
59
63
}
60
64
61
- // ParseCreateVolRequest parse incoming volume create request and fill ProvisionerConfig.
65
+ // ParseCreateVolRequest parse incoming volume create request and fill
66
+ // ProvisionerConfig.
62
67
func (cs * ControllerServer ) ParseCreateVolRequest (req * csi.CreateVolumeRequest ) (* ProvisionerConfig , error ) {
63
68
64
69
var reqConf ProvisionerConfig
@@ -79,7 +84,7 @@ func (cs *ControllerServer) ParseCreateVolRequest(req *csi.CreateVolumeRequest)
79
84
80
85
case "replicas" :
81
86
replicas := v
82
- replicaCount , err = parseVolumeParamInt (replicas , minReplicaCount , maxReplicaCount )
87
+ replicaCount , err = parseVolumeParamInt (replicas )
83
88
if err != nil {
84
89
return nil , fmt .Errorf ("invalid value for parameter '%s', %v" , k , err )
85
90
}
@@ -94,18 +99,18 @@ func (cs *ControllerServer) ParseCreateVolRequest(req *csi.CreateVolumeRequest)
94
99
return & reqConf , nil
95
100
}
96
101
97
- func parseVolumeParamInt (valueString string , min int , max int ) (int , error ) {
102
+ func parseVolumeParamInt (valueString string ) (int , error ) {
98
103
99
104
count , err := strconv .Atoi (valueString )
100
105
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 )
102
107
}
103
108
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 )
106
111
}
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 )
109
114
}
110
115
111
116
return count , nil
@@ -155,9 +160,9 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
155
160
}
156
161
err = cs .client .VolumeStart (volumeName , true )
157
162
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
161
166
glog .Errorf ("failed to start volume: %v" , err )
162
167
return nil , status .Errorf (codes .Internal , "failed to start volume: %v" , err )
163
168
}
@@ -197,7 +202,7 @@ func (cs *ControllerServer) checkExistingSnapshot(snapName, volName string) erro
197
202
snapInfo , err := cs .client .SnapshotInfo (snapName )
198
203
if err != nil {
199
204
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
201
206
if errResp != nil && errResp .StatusCode == http .StatusNotFound {
202
207
return status .Errorf (codes .NotFound , "failed to get snapshot info %s" , err .Error ())
203
208
}
@@ -214,7 +219,7 @@ func (cs *ControllerServer) checkExistingSnapshot(snapName, volName string) erro
214
219
return status .Errorf (codes .Internal , "failed to activate snapshot %s" , err .Error ())
215
220
}
216
221
}
217
- //create snapshot clone
222
+ // create snapshot clone
218
223
err = cs .createSnapshotClone (snapName , volName )
219
224
return err
220
225
}
@@ -269,7 +274,7 @@ func (cs *ControllerServer) doVolumeCreate(volumeName string, volSizeBytes int64
269
274
if err != nil {
270
275
glog .Errorf ("failed to create volume: %v" , err )
271
276
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
273
278
if errResp != nil && errResp .StatusCode == http .StatusConflict {
274
279
return status .Errorf (codes .Aborted , "volume create already in process: %v" , err )
275
280
}
@@ -285,7 +290,7 @@ func (cs *ControllerServer) checkExistingVolume(volumeName string, volSizeBytes
285
290
vol , err := cs .client .Volumes (volumeName )
286
291
if err != nil {
287
292
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
289
294
if errResp != nil && errResp .StatusCode == http .StatusNotFound {
290
295
return errVolumeNotFound
291
296
}
@@ -304,7 +309,7 @@ func (cs *ControllerServer) checkExistingVolume(volumeName string, volSizeBytes
304
309
return status .Errorf (codes .AlreadyExists , "volume %s already exits with different size: %d" , volInfo .Name , volInfo .Capacity )
305
310
}
306
311
307
- //volume has not started, start the volume
312
+ // volume has not started, start the volume
308
313
if volInfo .State != api .VolStarted {
309
314
err = cs .client .VolumeStart (volInfo .Name , true )
310
315
if err != nil {
@@ -362,7 +367,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
362
367
363
368
if err != nil {
364
369
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
366
371
if errResp != nil && errResp .StatusCode == http .StatusNotFound {
367
372
return & csi.DeleteVolumeResponse {}, nil
368
373
}
@@ -376,7 +381,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
376
381
err = cs .client .VolumeDelete (req .VolumeId )
377
382
if err != nil {
378
383
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
380
385
if errResp != nil && errResp .StatusCode == http .StatusNotFound {
381
386
return & csi.DeleteVolumeResponse {}, nil
382
387
}
@@ -455,7 +460,7 @@ func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req
455
460
456
461
// ListVolumes returns a list of volumes
457
462
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
459
464
volumes , err := cs .client .Volumes ("" )
460
465
if err != nil {
461
466
return nil , status .Error (codes .Internal , err .Error ())
@@ -523,7 +528,7 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
523
528
if err != nil {
524
529
glog .Errorf ("failed to get snapshot info for %v with Error %v" , req .GetName (), err .Error ())
525
530
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
527
532
if errResp != nil && errResp .StatusCode != http .StatusNotFound {
528
533
529
534
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
583
588
if err != nil {
584
589
glog .Errorf ("failed to create snapshot %v" , err )
585
590
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
587
592
if errResp != nil && errResp .StatusCode == http .StatusConflict {
588
593
return nil , status .Errorf (codes .Aborted , "snapshot create already in process: %v" , err )
589
594
}
@@ -613,7 +618,7 @@ func (cs *ControllerServer) validateCreateSnapshotReq(req *csi.CreateSnapshotReq
613
618
return status .Error (codes .InvalidArgument , "CreateSnapshot - sourceVolumeId is nil" )
614
619
}
615
620
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
617
622
return status .Error (codes .InvalidArgument , "CreateSnapshot - sourceVolumeId and snapshot name cannot be same" )
618
623
}
619
624
return nil
@@ -673,7 +678,7 @@ func (cs *ControllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
673
678
return cs .listSnapshotFromID (req .GetSnapshotId ())
674
679
}
675
680
676
- //If volume id is sent
681
+ // If volume id is sent
677
682
if len (req .GetSourceVolumeId ()) != 0 {
678
683
snaplist , err = cs .client .SnapshotList (req .SourceVolumeId )
679
684
if err != nil {
@@ -686,7 +691,7 @@ func (cs *ControllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
686
691
return nil , status .Errorf (codes .Internal , "ListSnapshot - failed to get snapshots %s" , err .Error ())
687
692
}
688
693
} else {
689
- //Get all snapshots
694
+ // Get all snapshots
690
695
snaplist , err = cs .client .SnapshotList ("" )
691
696
if err != nil {
692
697
glog .Errorf ("failed to list snapshots %v" , err )
@@ -755,8 +760,8 @@ func (cs *ControllerServer) doPagination(req *csi.ListSnapshotsRequest, snapList
755
760
756
761
}
757
762
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
760
765
var (
761
766
maximumEntries = req .MaxEntries
762
767
nextToken int32
0 commit comments