Skip to content

Commit

Permalink
group controller: better cleanup when group snapshot fails
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpanic committed Aug 22, 2024
1 parent c001233 commit 823b1d3
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions internal/rbd/group_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,36 @@ func (cs *ControllerServer) CreateVolumeGroupSnapshot(ctx context.Context, req *
// 4. create a GroupSnapshot
// 5. remove all rbd-images from the VolumeGroup
// 6. return the VolumeGroupSnapshot-name and list of snapshots
var (
vg types.VolumeGroup
groupSnapshot types.VolumeGroupSnapshot
)

mgr := NewManager(cs.Driver.GetInstanceID(), req.GetParameters(), req.GetSecrets())
defer mgr.Destroy(ctx)

// resolve all volumes, free them later on
volumes := make([]types.Volume, len(req.GetSourceVolumeIds()))
defer func() {
for _, vol := range volumes {
vol.Destroy(ctx)
for _, volume := range volumes {
if vg != nil {
// 'normal' cleanup, remove all images from the group
err := vg.RemoveVolume(ctx, volume)
if err != nil {
log.ErrorLog(ctx, "failed to remove volume %q from volume group %q: %v", volume, vg, err)
}
}

// free all allocated volumes
volume.Destroy(ctx)
}

if groupSnapshot == nil && vg != nil {
// group snapshot creation failed, delete the volume group
err := vg.Delete(ctx)
if err != nil {
log.ErrorLog(ctx, "failed to delete volume group %q: %v", vg, err)
}
}
}()
for i, id := range req.GetSourceVolumeIds() {
Expand Down Expand Up @@ -93,20 +114,12 @@ func (cs *ControllerServer) CreateVolumeGroupSnapshot(ctx context.Context, req *
}
}

groupSnapshot, err := vg.CreateSnapshot(ctx, req.GetName())
groupSnapshot, err = vg.CreateSnapshot(ctx, req.GetName())
if err != nil {
return nil, status.Error(codes.Aborted, err.Error())
}
defer groupSnapshot.Destroy(ctx)

// TODO: remove images from the group
for _, volume := range volumes {
err = vg.RemoveVolume(ctx, volume)
if err != nil {
return nil, status.Error(codes.Aborted, err.Error())
}
}

csiVGS, err := groupSnapshot.ToCSI(ctx)
if err != nil {
return nil, status.Error(codes.Aborted, err.Error())
Expand Down

0 comments on commit 823b1d3

Please sign in to comment.