rbd: make VolumeGroup Create/Delete/AddVolume/RemoveVolume idempotent

Add extra error checking to make sure trying to create an existing
volume group does not result in a failure. The same counts for deleting
a non-existing volume group, and adding/removing volumes to/from the
volume group.

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos
2024-07-22 16:59:07 +02:00
committed by mergify[bot]
parent 382d70893d
commit 4acffb5548
4 changed files with 25 additions and 22 deletions

View File

@ -237,16 +237,9 @@ func (mgr *rbdManager) CreateVolumeGroup(ctx context.Context, name string) (type
}
}()
// check if the volume group exists in the backend
existingName, err := vg.GetName(ctx)
err = vg.Create(ctx)
if err != nil {
// the volume group does not exist yet
err = vg.Create(ctx, vgName)
if err != nil {
return nil, fmt.Errorf("failed to create volume group %q: %w", name, err)
}
} else if existingName != vgName {
return nil, fmt.Errorf("volume group id %q has a name mismatch, expected %q, not %q", name, vgName, existingName)
return nil, fmt.Errorf("failed to create volume group %q: %w", name, err)
}
return vg, nil