@@ -85,6 +85,16 @@ const (
85
85
VolumeEncryption = Name + "/encrypted"
86
86
)
87
87
88
+ // Struct to return volume parameters when prepareVolumeParams is called
89
+
90
+ type VolumeParams struct {
91
+ VolumeName string
92
+ TargetSizeGB int
93
+ Size int64
94
+ EncryptionStatus string
95
+ Region string
96
+ }
97
+
88
98
// canAttach indicates whether or not another volume can be attached to the
89
99
// Linode with the given ID.
90
100
//
@@ -189,7 +199,7 @@ func (cs *ControllerServer) getContentSourceVolume(ctx context.Context, contentS
189
199
// attemptCreateLinodeVolume creates a Linode volume while ensuring idempotency.
190
200
// It checks for existing volumes with the same label and either returns the existing
191
201
// volume or creates a new one, optionally cloning from a source volume.
192
- func (cs * ControllerServer ) attemptCreateLinodeVolume (ctx context.Context , label , tags , volumeEncryption string , sizeGB int , sourceVolume * linodevolumes.LinodeVolumeKey , accessibilityRequirements * csi. TopologyRequirement ) (* linodego.Volume , error ) {
202
+ func (cs * ControllerServer ) attemptCreateLinodeVolume (ctx context.Context , label , tags , volumeEncryption string , sizeGB int , sourceVolume * linodevolumes.LinodeVolumeKey , region string ) (* linodego.Volume , error ) {
193
203
log := logger .GetLogger (ctx )
194
204
log .V (4 ).Info ("Attempting to create Linode volume" , "label" , label , "sizeGB" , sizeGB , "tags" , tags )
195
205
@@ -219,7 +229,7 @@ func (cs *ControllerServer) attemptCreateLinodeVolume(ctx context.Context, label
219
229
return cs .cloneLinodeVolume (ctx , label , sourceVolume .VolumeID )
220
230
}
221
231
222
- return cs .createLinodeVolume (ctx , label , tags , volumeEncryption , sizeGB , accessibilityRequirements )
232
+ return cs .createLinodeVolume (ctx , label , tags , volumeEncryption , sizeGB , region )
223
233
}
224
234
225
235
// Helper function to extract region from topology
@@ -240,19 +250,10 @@ func getRegionFromTopology(requirements *csi.TopologyRequirement) string {
240
250
241
251
// createLinodeVolume creates a new Linode volume with the specified label, size, and tags.
242
252
// It returns the created volume or an error if the creation fails.
243
- func (cs * ControllerServer ) createLinodeVolume (ctx context.Context , label , tags , encryptionStatus string , sizeGB int , accessibilityRequirements * csi. TopologyRequirement ) (* linodego.Volume , error ) {
253
+ func (cs * ControllerServer ) createLinodeVolume (ctx context.Context , label , tags , encryptionStatus string , sizeGB int , region string ) (* linodego.Volume , error ) {
244
254
log := logger .GetLogger (ctx )
245
255
log .V (4 ).Info ("Creating Linode volume" , "label" , label , "sizeGB" , sizeGB , "tags" , tags )
246
256
247
- // Get the region from req.AccessibilityRequirements if it exists. Fall back to the controller's metadata region if not specified.
248
- region := cs .metadata .Region
249
- if accessibilityRequirements != nil {
250
- if topologyRegion := getRegionFromTopology (accessibilityRequirements ); topologyRegion != "" {
251
- log .V (4 ).Info ("Using region from topology" , "region" , topologyRegion )
252
- region = topologyRegion
253
- }
254
- }
255
-
256
257
// Prepare the volume creation request with region, label, and size.
257
258
volumeReq := linodego.VolumeCreateOptions {
258
259
Region : region ,
@@ -431,38 +432,54 @@ func (cs *ControllerServer) validateCreateVolumeRequest(ctx context.Context, req
431
432
// prepareVolumeParams prepares the volume parameters for creation.
432
433
// It extracts the capacity range from the request, calculates the size,
433
434
// and generates a normalized volume name. Returns the volume name and size in GB.
434
- func (cs * ControllerServer ) prepareVolumeParams (ctx context.Context , req * csi.CreateVolumeRequest ) (volumeName string , targetSizeGB int , size int64 , encryptionStatus string , err error ) {
435
+ func (cs * ControllerServer ) prepareVolumeParams (ctx context.Context , req * csi.CreateVolumeRequest ) (* VolumeParams , error ) {
435
436
log := logger .GetLogger (ctx )
436
437
log .V (4 ).Info ("Entering prepareVolumeParams()" , "req" , req )
437
438
defer log .V (4 ).Info ("Exiting prepareVolumeParams()" )
438
-
439
- // by default encryption is disabled
440
- encryptionStatus = "disabled"
439
+ // By default, encryption is disabled
440
+ encryptionStatus := "disabled"
441
441
// Retrieve the capacity range from the request to determine the size limits for the volume.
442
442
capRange := req .GetCapacityRange ()
443
443
// Get the requested size in bytes, handling any potential errors.
444
- size , err = getRequestCapacitySize (capRange )
444
+ size , err : = getRequestCapacitySize (capRange )
445
445
if err != nil {
446
- return "" , 0 , 0 , "" , err
446
+ return nil , err
447
+ }
448
+
449
+ // Get the region from req.AccessibilityRequirements if it exists. Fall back to the controller's metadata region if not specified.
450
+ accessibilityRequirements := req .GetAccessibilityRequirements ()
451
+ region := cs .metadata .Region
452
+ if accessibilityRequirements != nil {
453
+ if topologyRegion := getRegionFromTopology (accessibilityRequirements ); topologyRegion != "" {
454
+ log .V (4 ).Info ("Using region from topology" , "region" , topologyRegion )
455
+ region = topologyRegion
456
+ }
447
457
}
448
458
449
459
preKey := linodevolumes .CreateLinodeVolumeKey (0 , req .GetName ())
450
- volumeName = preKey .GetNormalizedLabelWithPrefix (cs .driver .volumeLabelPrefix )
451
- targetSizeGB = bytesToGB (size )
460
+ volumeName := preKey .GetNormalizedLabelWithPrefix (cs .driver .volumeLabelPrefix )
461
+ targetSizeGB := bytesToGB (size )
462
+
452
463
// Check if encryption should be enabled
453
464
if req .GetParameters ()[VolumeEncryption ] == True {
454
465
supported , err := cs .isEncryptionSupported (ctx , cs .metadata .Region )
455
466
if err != nil {
456
- return volumeName , targetSizeGB , size , encryptionStatus , err
467
+ return nil , err
457
468
}
458
469
if ! supported {
459
- return volumeName , targetSizeGB , size , encryptionStatus , errInternal ("Volume encryption is not supported in the %s region" , cs .metadata .Region )
470
+ return nil , errInternal ("Volume encryption is not supported in the %s region" , cs .metadata .Region )
460
471
}
461
472
encryptionStatus = "enabled"
462
473
}
463
474
464
475
log .V (4 ).Info ("Volume parameters prepared" , "volumeName" , volumeName , "targetSizeGB" , targetSizeGB )
465
- return volumeName , targetSizeGB , size , encryptionStatus , nil
476
+ return & VolumeParams {
477
+ VolumeName : volumeName ,
478
+ TargetSizeGB : targetSizeGB ,
479
+ Size : size ,
480
+ EncryptionStatus : encryptionStatus ,
481
+ Region : region ,
482
+ }, nil
466
483
}
467
484
468
485
// createVolumeContext creates a context map for the volume based on the request parameters.
@@ -489,12 +506,12 @@ func (cs *ControllerServer) createVolumeContext(ctx context.Context, req *csi.Cr
489
506
490
507
// createAndWaitForVolume attempts to create a new volume and waits for it to become active.
491
508
// It logs the process and handles any errors that occur during creation or waiting.
492
- func (cs * ControllerServer ) createAndWaitForVolume (ctx context.Context , name string , parameters map [string ]string , encryptionStatus string , sizeGB int , sourceInfo * linodevolumes.LinodeVolumeKey , accessibilityRequirements * csi. TopologyRequirement ) (* linodego.Volume , error ) {
509
+ func (cs * ControllerServer ) createAndWaitForVolume (ctx context.Context , name string , parameters map [string ]string , encryptionStatus string , sizeGB int , sourceInfo * linodevolumes.LinodeVolumeKey , region string ) (* linodego.Volume , error ) {
493
510
log := logger .GetLogger (ctx )
494
511
log .V (4 ).Info ("Entering createAndWaitForVolume()" , "name" , name , "sizeGB" , sizeGB , "tags" , parameters [VolumeTags ], "encryptionStatus" , encryptionStatus )
495
512
defer log .V (4 ).Info ("Exiting createAndWaitForVolume()" )
496
513
497
- vol , err := cs .attemptCreateLinodeVolume (ctx , name , parameters [VolumeTags ], encryptionStatus , sizeGB , sourceInfo , accessibilityRequirements )
514
+ vol , err := cs .attemptCreateLinodeVolume (ctx , name , parameters [VolumeTags ], encryptionStatus , sizeGB , sourceInfo , region )
498
515
if err != nil {
499
516
return nil , err
500
517
}
0 commit comments