@@ -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
@@ -509,7 +515,7 @@ func (gceCS *GCEControllerServer) createMultiZoneDisk(ctx context.Context, req *
509
515
// Use the first response as a template
510
516
volumeId := fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , gceCS .CloudProvider .GetDefaultProject (), common .MultiZoneValue , req .GetName ())
511
517
klog .V (4 ).Infof ("CreateVolume succeeded for multi-zone disks in zones %s: %v" , zones , multiZoneVolKey )
512
- return generateCreateVolumeResponseWithVolumeId (createdDisks [0 ], zones , params , dataCacheParams , enableDataCache , volumeId ), nil
518
+ return gceCS . generateCreateVolumeResponseWithVolumeId (createdDisks [0 ], zones , params , dataCacheParams , enableDataCache , volumeId ), nil
513
519
}
514
520
515
521
func (gceCS * GCEControllerServer ) getZonesWithDiskNameAndType (ctx context.Context , name string , diskType string ) ([]string , error ) {
@@ -603,7 +609,7 @@ func (gceCS *GCEControllerServer) createSingleDeviceDisk(ctx context.Context, re
603
609
return nil , common .LoggedError ("CreateVolume failed: %v" , err )
604
610
}
605
611
606
- return generateCreateVolumeResponseWithVolumeId (disk , zones , params , dataCacheParams , enableDataCache , volumeID ), err
612
+ return gceCS . generateCreateVolumeResponseWithVolumeId (disk , zones , params , dataCacheParams , enableDataCache , volumeID ), err
607
613
}
608
614
609
615
func (gceCS * GCEControllerServer ) createSingleDisk (ctx context.Context , req * csi.CreateVolumeRequest , params common.DiskParameters , volKey * meta.Key , zones []string ) (* gce.CloudDisk , error ) {
@@ -2278,9 +2284,11 @@ func getZonesFromTopology(topList []*csi.Topology) ([]string, error) {
2278
2284
func getZoneFromSegment (seg map [string ]string ) (string , error ) {
2279
2285
var zone string
2280
2286
for k , v := range seg {
2281
- switch k {
2282
- case common .TopologyKeyZone :
2287
+ switch {
2288
+ case k == common .TopologyKeyZone :
2283
2289
zone = v
2290
+ case common .IsGKETopologyLabel (k ):
2291
+ continue
2284
2292
default :
2285
2293
return "" , fmt .Errorf ("topology segment has unknown key %v" , k )
2286
2294
}
@@ -2370,21 +2378,30 @@ func extractVolumeContext(context map[string]string) (*PDCSIContext, error) {
2370
2378
case contextForceAttach :
2371
2379
b , err := common .ConvertStringToBool (val )
2372
2380
if err != nil {
2373
- return nil , fmt .Errorf ("Bad volume context force attach: %v " , err )
2381
+ return nil , fmt .Errorf ("bad volume context force attach: %w " , err )
2374
2382
}
2375
2383
info .ForceAttach = b
2376
2384
}
2377
2385
}
2378
2386
return info , nil
2379
2387
}
2380
2388
2381
- func generateCreateVolumeResponseWithVolumeId (disk * gce.CloudDisk , zones []string , params common.DiskParameters , dataCacheParams common.DataCacheParameters , enableDataCache bool , volumeId string ) * csi.CreateVolumeResponse {
2389
+ func ( gceCS * GCEControllerServer ) generateCreateVolumeResponseWithVolumeId (disk * gce.CloudDisk , zones []string , params common.DiskParameters , dataCacheParams common.DataCacheParameters , enableDataCache bool , volumeId string ) * csi.CreateVolumeResponse {
2382
2390
tops := []* csi.Topology {}
2383
2391
for _ , zone := range zones {
2384
- tops = append (tops , & csi.Topology {
2385
- Segments : map [string ]string {common .TopologyKeyZone : zone },
2386
- })
2392
+ top := & csi.Topology {
2393
+ Segments : map [string ]string {
2394
+ common .TopologyKeyZone : zone ,
2395
+ },
2396
+ }
2397
+
2398
+ if gceCS .EnableDiskTopology {
2399
+ top .Segments [common .TopologyLabelKey (params .DiskType )] = "true"
2400
+ }
2401
+
2402
+ tops = append (tops , top )
2387
2403
}
2404
+
2388
2405
realDiskSizeBytes := common .GbToBytes (disk .GetSizeGb ())
2389
2406
createResp := & csi.CreateVolumeResponse {
2390
2407
Volume : & csi.Volume {
0 commit comments