@@ -355,23 +355,24 @@ func (r *Reconciler) reconcileInstanceWithoutDeletionTimestamp(ctx context.Conte
355
355
vm * cnsvsphere.VirtualMachine ) error {
356
356
log := logger .GetLogger (ctx )
357
357
358
- // Call batch attach for volumes.
359
- err := r .processBatchAttach (ctx , vm , instance )
360
- if err != nil {
361
- log .Errorf ("failed to attach all volumes. Err: %+v" , err )
362
- return err
363
- }
364
-
358
+ var detachErr error
365
359
// Call detach if there are some volumes which need to be detached.
366
360
if len (volumesToDetach ) != 0 {
367
- err := r .processDetach (ctx , vm , instance , volumesToDetach )
368
- if err != nil {
369
- log .Errorf ("failed to detach all volumes. Err: +v" , err )
370
- return err
361
+ detachErr = r .processDetach (ctx , vm , instance , volumesToDetach )
362
+ if detachErr != nil {
363
+ log .Errorf ("failed to detach all volumes. Err: %s" , detachErr )
364
+ } else {
365
+ log .Infof ("Successfully detached all volumes %+v" , volumesToDetach )
371
366
}
372
- log .Infof ("Successfully detached all volumes %+v" , volumesToDetach )
373
367
}
374
- return nil
368
+
369
+ // Call batch attach for volumes.
370
+ attachErr := r .processBatchAttach (ctx , vm , instance )
371
+ if attachErr != nil {
372
+ log .Errorf ("failed to attach all volumes. Err: %+v" , attachErr )
373
+ }
374
+
375
+ return errors .Join (attachErr , detachErr )
375
376
}
376
377
377
378
// processDetach detaches each of the volumes in volumesToDetach by calling CNS DetachVolume API.
0 commit comments