@@ -120,6 +120,12 @@ type GCEControllerServer struct {
120
120
// Embed UnimplementedControllerServer to ensure the driver returns Unimplemented for any
121
121
// new RPC methods that might be introduced in future versions of the spec.
122
122
csi.UnimplementedControllerServer
123
+
124
+ EnableDiskTopology bool
125
+ }
126
+
127
+ type GCEControllerServerArgs struct {
128
+ EnableDiskTopology bool
123
129
}
124
130
125
131
type MultiZoneVolumeHandleConfig struct {
@@ -320,7 +326,7 @@ func (gceCS *GCEControllerServer) createVolumeInternal(ctx context.Context, req
320
326
if len (req .GetName ()) == 0 {
321
327
return nil , status .Error (codes .InvalidArgument , "CreateVolume Name must be provided" )
322
328
}
323
- if volumeCapabilities == nil || len (volumeCapabilities ) == 0 {
329
+ if len (volumeCapabilities ) == 0 {
324
330
return nil , status .Error (codes .InvalidArgument , "CreateVolume Volume capabilities must be provided" )
325
331
}
326
332
@@ -465,9 +471,7 @@ func (gceCS *GCEControllerServer) getMultiZoneProvisioningZones(ctx context.Cont
465
471
}
466
472
467
473
func (gceCS * GCEControllerServer ) createMultiZoneDisk (ctx context.Context , req * csi.CreateVolumeRequest , params common.DiskParameters , dataCacheParams common.DataCacheParameters , enableDataCache bool ) (* csi.CreateVolumeResponse , error ) {
468
- // Determine the zones that are needed.
469
474
var err error
470
-
471
475
// For multi-zone, we either select:
472
476
// 1) The zones specified in requisite topology requirements
473
477
// 2) All zones in the region that are compatible with the selected disk type
@@ -517,7 +521,8 @@ func (gceCS *GCEControllerServer) createMultiZoneDisk(ctx context.Context, req *
517
521
// Use the first response as a template
518
522
volumeId := fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , gceCS .CloudProvider .GetDefaultProject (), common .MultiZoneValue , req .GetName ())
519
523
klog .V (4 ).Infof ("CreateVolume succeeded for multi-zone disks in zones %s: %v" , zones , multiZoneVolKey )
520
- return generateCreateVolumeResponseWithVolumeId (createdDisks [0 ], zones , params , dataCacheParams , enableDataCache , volumeId ), nil
524
+
525
+ return gceCS .generateCreateVolumeResponseWithVolumeId (createdDisks [0 ], zones , params , dataCacheParams , enableDataCache , volumeId ), nil
521
526
}
522
527
523
528
func (gceCS * GCEControllerServer ) getZonesWithDiskNameAndType (ctx context.Context , name string , diskType string ) ([]string , error ) {
@@ -617,13 +622,13 @@ func (gceCS *GCEControllerServer) createSingleDeviceDisk(ctx context.Context, re
617
622
return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , volumeID )
618
623
}
619
624
defer gceCS .volumeLocks .Release (volumeID )
620
- disk , err := gceCS .createSingleDisk (ctx , req , params , volKey , zones , accessMode )
621
625
626
+ disk , err := gceCS .createSingleDisk (ctx , req , params , volKey , zones , accessMode )
622
627
if err != nil {
623
628
return nil , common .LoggedError ("CreateVolume failed: %v" , err )
624
629
}
625
630
626
- return generateCreateVolumeResponseWithVolumeId (disk , zones , params , dataCacheParams , enableDataCache , volumeID ), err
631
+ return gceCS . generateCreateVolumeResponseWithVolumeId (disk , zones , params , dataCacheParams , enableDataCache , volumeID ), nil
627
632
}
628
633
629
634
func getAccessMode (req * csi.CreateVolumeRequest , params common.DiskParameters ) (string , error ) {
@@ -2396,21 +2401,30 @@ func extractVolumeContext(context map[string]string) (*PDCSIContext, error) {
2396
2401
case contextForceAttach :
2397
2402
b , err := common .ConvertStringToBool (val )
2398
2403
if err != nil {
2399
- return nil , fmt .Errorf ("Bad volume context force attach: %v " , err )
2404
+ return nil , fmt .Errorf ("bad volume context force attach: %w " , err )
2400
2405
}
2401
2406
info .ForceAttach = b
2402
2407
}
2403
2408
}
2404
2409
return info , nil
2405
2410
}
2406
2411
2407
- func generateCreateVolumeResponseWithVolumeId (disk * gce.CloudDisk , zones []string , params common.DiskParameters , dataCacheParams common.DataCacheParameters , enableDataCache bool , volumeId string ) * csi.CreateVolumeResponse {
2412
+ func ( gceCS * GCEControllerServer ) generateCreateVolumeResponseWithVolumeId (disk * gce.CloudDisk , zones []string , params common.DiskParameters , dataCacheParams common.DataCacheParameters , enableDataCache bool , volumeId string ) * csi.CreateVolumeResponse {
2408
2413
tops := []* csi.Topology {}
2409
2414
for _ , zone := range zones {
2410
- tops = append (tops , & csi.Topology {
2411
- Segments : map [string ]string {common .TopologyKeyZone : zone },
2412
- })
2415
+ top := & csi.Topology {
2416
+ Segments : map [string ]string {
2417
+ common .TopologyKeyZone : zone ,
2418
+ },
2419
+ }
2420
+
2421
+ if gceCS .EnableDiskTopology {
2422
+ top .Segments [common .DiskTypeLabelKey (params .DiskType )] = "true"
2423
+ }
2424
+
2425
+ tops = append (tops , top )
2413
2426
}
2427
+
2414
2428
realDiskSizeBytes := common .GbToBytes (disk .GetSizeGb ())
2415
2429
createResp := & csi.CreateVolumeResponse {
2416
2430
Volume : & csi.Volume {
@@ -2468,10 +2482,10 @@ func generateCreateVolumeResponseWithVolumeId(disk *gce.CloudDisk, zones []strin
2468
2482
func getResourceId (resourceLink string ) (string , error ) {
2469
2483
url , err := neturl .Parse (resourceLink )
2470
2484
if err != nil {
2471
- return "" , fmt .Errorf ("Could not parse resource %s: %w" , resourceLink , err )
2485
+ return "" , fmt .Errorf ("could not parse resource %s: %w" , resourceLink , err )
2472
2486
}
2473
2487
if url .Scheme != resourceApiScheme {
2474
- return "" , fmt .Errorf ("Unexpected API scheme for resource %s" , resourceLink )
2488
+ return "" , fmt .Errorf ("unexpected API scheme for resource %s" , resourceLink )
2475
2489
}
2476
2490
2477
2491
// Note that the resource host can basically be anything, if we are running in
@@ -2480,16 +2494,16 @@ func getResourceId(resourceLink string) (string, error) {
2480
2494
// The path should be /compute/VERSION/project/....
2481
2495
elts := strings .Split (url .Path , "/" )
2482
2496
if len (elts ) < 4 {
2483
- return "" , fmt .Errorf ("Short resource path %s" , resourceLink )
2497
+ return "" , fmt .Errorf ("short resource path %s" , resourceLink )
2484
2498
}
2485
2499
if elts [1 ] != resourceApiService {
2486
- return "" , fmt .Errorf ("Bad resource service %s in %s" , elts [1 ], resourceLink )
2500
+ return "" , fmt .Errorf ("bad resource service %s in %s" , elts [1 ], resourceLink )
2487
2501
}
2488
2502
if _ , ok := validResourceApiVersions [elts [2 ]]; ! ok {
2489
- return "" , fmt .Errorf ("Bad version %s in %s" , elts [2 ], resourceLink )
2503
+ return "" , fmt .Errorf ("bad version %s in %s" , elts [2 ], resourceLink )
2490
2504
}
2491
2505
if elts [3 ] != resourceProject {
2492
- return "" , fmt .Errorf ("Expected %v to start with %s in resource %s" , elts [3 :], resourceProject , resourceLink )
2506
+ return "" , fmt .Errorf ("expected %v to start with %s in resource %s" , elts [3 :], resourceProject , resourceLink )
2493
2507
}
2494
2508
return strings .Join (elts [3 :], "/" ), nil
2495
2509
}
0 commit comments