@@ -54,7 +54,7 @@ type GCECompute interface {
54
54
GetDefaultZone () string
55
55
// Disk Methods
56
56
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 )
58
58
ValidateExistingDisk (ctx context.Context , disk * CloudDisk , params common.DiskParameters , reqBytes , limBytes int64 , multiWriter bool ) error
59
59
InsertDisk (ctx context.Context , project string , volKey * meta.Key , params common.DiskParameters , capBytes int64 , capacityRange * csi.CapacityRange , replicaZones []string , snapshotID string , multiWriter bool ) error
60
60
DeleteDisk (ctx context.Context , project string , volumeKey * meta.Key ) error
@@ -106,11 +106,14 @@ func (cloud *CloudProvider) ListDisks(ctx context.Context, maxEntries int64, pag
106
106
107
107
// RepairUnderspecifiedVolumeKey will query the cloud provider and check each zone for the disk specified
108
108
// 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 ) {
110
110
klog .V (5 ).Infof ("Repairing potentially underspecified volume key %v" , volumeKey )
111
+ if project == common .UnspecifiedValue {
112
+ project = cloud .project
113
+ }
111
114
region , err := common .GetRegionFromZones ([]string {cloud .zone })
112
115
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 )
114
117
}
115
118
switch volumeKey .Type () {
116
119
case meta .Zonal :
@@ -119,7 +122,7 @@ func (cloud *CloudProvider) RepairUnderspecifiedVolumeKey(ctx context.Context, p
119
122
// list all zones, try to get disk in each zone
120
123
zones , err := cloud .ListZones (ctx , region )
121
124
if err != nil {
122
- return nil , err
125
+ return "" , nil , err
123
126
}
124
127
for _ , zone := range zones {
125
128
_ , err := cloud .getZonalDiskOrError (ctx , project , zone , volumeKey .Name )
@@ -131,28 +134,28 @@ func (cloud *CloudProvider) RepairUnderspecifiedVolumeKey(ctx context.Context, p
131
134
}
132
135
// There is some miscellaneous error getting disk from zone
133
136
// so we return error immediately
134
- return nil , err
137
+ return "" , nil , err
135
138
}
136
139
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 )
138
141
}
139
142
foundZone = zone
140
143
}
141
144
142
145
if len (foundZone ) == 0 {
143
- return nil , notFoundError ()
146
+ return "" , nil , notFoundError ()
144
147
}
145
148
volumeKey .Zone = foundZone
146
- return volumeKey , nil
149
+ return project , volumeKey , nil
147
150
}
148
- return volumeKey , nil
151
+ return project , volumeKey , nil
149
152
case meta .Regional :
150
153
if volumeKey .Region == common .UnspecifiedValue {
151
154
volumeKey .Region = region
152
155
}
153
- return volumeKey , nil
156
+ return project , volumeKey , nil
154
157
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 ())
156
159
}
157
160
}
158
161
0 commit comments