rbd: add validation to ToCSI() for rbdVolume and rbdSnapshot

After an unfortnate timed restart of the provisioner, a volume that got
cloned did not get a `rbdVolume.VolID` set. The `.VolID` is used as the
CSI Volume Handle, and is a required attribute.

The `rbdVolume` and `rbdSnapshot` structs have a `.ToCSI()` function
that can do the validation of required attributes. This is now added,
including unit-tests.

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos
2025-02-17 16:01:42 +01:00
committed by mergify[bot]
parent b3faa04504
commit ac8cda5e37
4 changed files with 186 additions and 1 deletions

View File

@ -250,6 +250,17 @@ func (cs *ControllerServer) parseVolCreateRequest(
}
func (rbdVol *rbdVolume) ToCSI(ctx context.Context) (*csi.Volume, error) {
switch {
case rbdVol.VolID == "":
return nil, fmt.Errorf("%q does not have a volume-id set", rbdVol)
case rbdVol.Pool == "":
return nil, fmt.Errorf("%q does not have a pool set", rbdVol)
case rbdVol.JournalPool == "":
return nil, fmt.Errorf("%q does not have a journal-pool set", rbdVol)
case rbdVol.RbdImageName == "":
return nil, fmt.Errorf("%q does not have an image-name set", rbdVol)
}
vol := &csi.Volume{
VolumeId: rbdVol.VolID,
CapacityBytes: rbdVol.VolSize,