Skip to content

Commit 3f7ba81

Browse files
authored
Allow detach to happen even if batch attach fail (#3632)
1 parent 05108a3 commit 3f7ba81

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

pkg/syncer/cnsoperator/controller/cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -355,23 +355,24 @@ func (r *Reconciler) reconcileInstanceWithoutDeletionTimestamp(ctx context.Conte
355355
vm *cnsvsphere.VirtualMachine) error {
356356
log := logger.GetLogger(ctx)
357357

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
365359
// Call detach if there are some volumes which need to be detached.
366360
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)
371366
}
372-
log.Infof("Successfully detached all volumes %+v", volumesToDetach)
373367
}
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)
375376
}
376377

377378
// processDetach detaches each of the volumes in volumesToDetach by calling CNS DetachVolume API.

0 commit comments

Comments
 (0)