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

@ -147,6 +147,13 @@ func (rbdSnap *rbdSnapshot) toVolume() *rbdVolume {
}
func (rbdSnap *rbdSnapshot) ToCSI(ctx context.Context) (*csi.Snapshot, error) {
switch {
case rbdSnap.VolID == "":
return nil, fmt.Errorf("%q does not have a volume-id set", rbdSnap)
case rbdSnap.SourceVolumeID == "":
return nil, fmt.Errorf("%q does not have a source-volume-id set", rbdSnap)
}
created, err := rbdSnap.GetCreationTime(ctx)
if err != nil {
return nil, err