rbd: prevent panic in CreateVolumeGroup if volumeID was not found

When an incorrect volumeID is passed while creating a VolumeGroup, the
`.Destroy()` function caused a panic. By appending each volume to the
volumes slice, the slice won't contain any `nil` volumes anymore.

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos 2025-03-20 10:31:39 +01:00 committed by mergify[bot]
parent d10c83eeae
commit 45c91ab0f1

View File

@ -89,7 +89,7 @@ func (vs *VolumeGroupServer) CreateVolumeGroup(
defer mgr.Destroy(ctx)
// resolve all volumes
volumes := make([]types.Volume, len(req.GetVolumeIds()))
volumes := make([]types.Volume, 0)
defer func() {
for _, vol := range volumes {
vol.Destroy(ctx)
@ -105,7 +105,7 @@ func (vs *VolumeGroupServer) CreateVolumeGroup(
req.GetName(),
err.Error())
}
volumes[i] = vol
volumes = append(volumes, vol)
}
log.DebugLog(ctx, "all %d Volumes for VolumeGroup %q have been found", len(volumes), req.GetName())