@@ -54,7 +54,7 @@ type GCECompute interface {
5454 GetDefaultZone () string
5555 // Disk Methods
5656 GetDisk (ctx context.Context , project string , volumeKey * meta.Key , gceAPIVersion GCEAPIVersion ) (* CloudDisk , error )
57- RepairUnderspecifiedVolumeKey (ctx context.Context , project string , volumeKey * meta.Key ) (* meta.Key , error )
57+ RepairUnderspecifiedVolumeKey (ctx context.Context , project string , volumeKey * meta.Key ) (string , * meta.Key , error )
5858 ValidateExistingDisk (ctx context.Context , disk * CloudDisk , params common.DiskParameters , reqBytes , limBytes int64 , multiWriter bool ) error
5959 InsertDisk (ctx context.Context , project string , volKey * meta.Key , params common.DiskParameters , capBytes int64 , capacityRange * csi.CapacityRange , replicaZones []string , snapshotID string , multiWriter bool ) error
6060 DeleteDisk (ctx context.Context , project string , volumeKey * meta.Key ) error
@@ -106,11 +106,14 @@ func (cloud *CloudProvider) ListDisks(ctx context.Context, maxEntries int64, pag
106106
107107// RepairUnderspecifiedVolumeKey will query the cloud provider and check each zone for the disk specified
108108// by the volume key and return a volume key with a correct zone
109- func (cloud * CloudProvider ) RepairUnderspecifiedVolumeKey (ctx context.Context , project string , volumeKey * meta.Key ) (* meta.Key , error ) {
109+ func (cloud * CloudProvider ) RepairUnderspecifiedVolumeKey (ctx context.Context , project string , volumeKey * meta.Key ) (string , * meta.Key , error ) {
110110 klog .V (5 ).Infof ("Repairing potentially underspecified volume key %v" , volumeKey )
111+ if project == common .UnspecifiedValue {
112+ project = cloud .project
113+ }
111114 region , err := common .GetRegionFromZones ([]string {cloud .zone })
112115 if err != nil {
113- return nil , fmt .Errorf ("failed to get region from zones: %v" , err )
116+ return "" , nil , fmt .Errorf ("failed to get region from zones: %v" , err )
114117 }
115118 switch volumeKey .Type () {
116119 case meta .Zonal :
@@ -119,7 +122,7 @@ func (cloud *CloudProvider) RepairUnderspecifiedVolumeKey(ctx context.Context, p
119122 // list all zones, try to get disk in each zone
120123 zones , err := cloud .ListZones (ctx , region )
121124 if err != nil {
122- return nil , err
125+ return "" , nil , err
123126 }
124127 for _ , zone := range zones {
125128 _ , err := cloud .getZonalDiskOrError (ctx , project , zone , volumeKey .Name )
@@ -131,28 +134,28 @@ func (cloud *CloudProvider) RepairUnderspecifiedVolumeKey(ctx context.Context, p
131134 }
132135 // There is some miscellaneous error getting disk from zone
133136 // so we return error immediately
134- return nil , err
137+ return "" , nil , err
135138 }
136139 if len (foundZone ) > 0 {
137- return nil , fmt .Errorf ("found disk %s in more than one zone: %s and %s" , volumeKey .Name , foundZone , zone )
140+ return "" , nil , fmt .Errorf ("found disk %s in more than one zone: %s and %s" , volumeKey .Name , foundZone , zone )
138141 }
139142 foundZone = zone
140143 }
141144
142145 if len (foundZone ) == 0 {
143- return nil , notFoundError ()
146+ return "" , nil , notFoundError ()
144147 }
145148 volumeKey .Zone = foundZone
146- return volumeKey , nil
149+ return project , volumeKey , nil
147150 }
148- return volumeKey , nil
151+ return project , volumeKey , nil
149152 case meta .Regional :
150153 if volumeKey .Region == common .UnspecifiedValue {
151154 volumeKey .Region = region
152155 }
153- return volumeKey , nil
156+ return project , volumeKey , nil
154157 default :
155- return nil , fmt .Errorf ("key was neither zonal nor regional, got: %v" , volumeKey .String ())
158+ return "" , nil , fmt .Errorf ("key was neither zonal nor regional, got: %v" , volumeKey .String ())
156159 }
157160}
158161
0 commit comments