@@ -226,18 +226,19 @@ func DeleteDataExport(ctx context.Context, deName, namespace string, rtClient ct
226226 return nil
227227}
228228
229- func getExportStatus (ctx context.Context , log * slog.Logger , deName , namespace string , public bool , rtClient ctrlrtclient.Client ) (podURL , volumeMode , internalCAData string , err error ) {
229+ func getExportStatus (ctx context.Context , log * slog.Logger , deName , namespace string , public bool , rtClient ctrlrtclient.Client ) ( /*podURL*/ string /*volumeMode*/ , string /*internalCAData*/ , string , error ) {
230+ var podURL , volumeMode , internalCAData string
231+
230232 log .Info ("Waiting for DataExport to be ready" , slog .String ("name" , deName ), slog .String ("namespace" , namespace ))
231233 deObj , err := GetDataExportWithRestart (ctx , deName , namespace , rtClient )
232234 if err != nil {
233- return
235+ return "" , "" , "" , err
234236 }
235237
236238 switch {
237239 case public :
238240 if deObj .Status .PublicURL == "" {
239- err = fmt .Errorf ("empty PublicURL" )
240- return
241+ return "" , "" , "" , fmt .Errorf ("empty PublicURL" )
241242 }
242243 podURL = deObj .Status .PublicURL
243244 if ! strings .HasPrefix (podURL , "http" ) {
@@ -247,51 +248,48 @@ func getExportStatus(ctx context.Context, log *slog.Logger, deName, namespace st
247248 podURL = deObj .Status .URL
248249 internalCAData = deObj .Status .CA
249250 default :
250- err = fmt .Errorf ("invalid URL" )
251- return
251+ return "" , "" , "" , fmt .Errorf ("invalid URL" )
252252 }
253253
254254 volumeKind := deObj .Spec .TargetRef .Kind
255255 if ! slices .Contains ([]string {dataio .PersistentVolumeClaimKind , dataio .VolumeSnapshotKind , dataio .VirtualDiskKind , dataio .VirtualDiskSnapshotKind }, volumeKind ) {
256- err = fmt .Errorf ("invalid volume kind: %s" , volumeKind )
257- return
256+ return "" , "" , "" , fmt .Errorf ("invalid volume kind: %s" , volumeKind )
258257 }
259258
260259 volumeMode = deObj .Status .VolumeMode
261260 log .Info ("DataExport is ready" , slog .String ("name" , deName ), slog .String ("namespace" , namespace ), slog .String ("url" , podURL ), slog .String ("volumeMode" , volumeMode ))
262- return
261+
262+ return podURL , volumeMode , internalCAData , nil
263263}
264264
265- func PrepareDownload (ctx context.Context , log * slog.Logger , deName , namespace string , publish bool , sClient * safeClient.SafeClient ) (url , volumeMode string , subClient * safeClient.SafeClient , finErr error ) {
265+ func PrepareDownload (ctx context.Context , log * slog.Logger , deName , namespace string , publish bool , sClient * safeClient.SafeClient ) (string , string , * safeClient.SafeClient , error ) {
266+ var url , volumeMode string
267+ var subClient * safeClient.SafeClient
268+
266269 rtClient , err := sClient .NewRTClient (v1alpha1 .AddToScheme )
267270 if err != nil {
268- finErr = err
269- return
271+ return "" , "" , nil , err
270272 }
271273
272274 podURL , volumeMode , intrenalCAData , err := getExportStatus (ctx , log , deName , namespace , publish , rtClient )
273275 if err != nil {
274- finErr = err
275- return
276+ return "" , "" , nil , err
276277 }
277278
278279 // Validate srcPath, dstPath params
279280 switch volumeMode {
280281 case "Filesystem" :
281282 url , err = neturl .JoinPath (podURL , "api/v1/files" )
282283 if err != nil {
283- finErr = err
284- return
284+ return "" , "" , nil , err
285285 }
286286 case "Block" :
287287 url , err = neturl .JoinPath (podURL , "api/v1/block" )
288288 if err != nil {
289- finErr = err
290- return
289+ return "" , "" , nil , err
291290 }
292291 default :
293- finErr = fmt .Errorf ("%w: '%s'" , dataio .ErrUnsupportedVolumeMode , volumeMode )
294- return
292+ return "" , "" , nil , fmt .Errorf ("%w: '%s'" , dataio .ErrUnsupportedVolumeMode , volumeMode )
295293 }
296294
297295 // Reuse the original SafeClient unless we need to inject additional CA.
@@ -302,11 +300,10 @@ func PrepareDownload(ctx context.Context, log *slog.Logger, deName, namespace st
302300 subClient = sClient .Copy ()
303301 decodedBytes , err := base64 .StdEncoding .DecodeString (intrenalCAData )
304302 if err != nil {
305- finErr = fmt .Errorf ("CA decoding error: %s" , err .Error ())
306- return
303+ return "" , "" , nil , fmt .Errorf ("CA decoding error: %s" , err .Error ())
307304 }
308305 subClient .SetTLSCAData (decodedBytes )
309306 }
310307
311- return
308+ return url , volumeMode , subClient , nil
312309}
0 commit comments