rbd: set SnapshotGroupID on each Snapshot of a VolumeGroupSnapshot

Without the SnapshotGroupID in the Snapshot object, Kubernetes CSI does
not know that the Snapshot belongs to a group. In that case, it allows
the deletion of the Snapshot, which should be denied.

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos
2024-10-25 17:24:50 +02:00
committed by mergify[bot]
parent ec1e7a4ee0
commit cea8bf8110
5 changed files with 52 additions and 10 deletions

View File

@ -191,6 +191,9 @@ type rbdSnapshot struct {
// RbdSnapName is the name of the RBD snapshot backing this rbdSnapshot
SourceVolumeID string
RbdSnapName string
// groupID is the CSI volume group ID where this snapshot belongs to
groupID string
}
// imageFeature represents required image features and value.
@ -1054,6 +1057,15 @@ func genSnapFromSnapID(
}
}
if imageAttributes.GroupID != "" {
rbdSnap.groupID = imageAttributes.GroupID
// FIXME: The snapshot will have RbdImageName set to the image
// that was used as source. This is not correct for group
// snapshots images, and need to be fixed. See
// rbdVolume.NewSnapshotByID() for more details.
rbdSnap.RbdImageName = rbdSnap.RbdSnapName
}
err = rbdSnap.Connect(cr)
if err != nil {
return rbdSnap, fmt.Errorf("failed to connect to %q: %w",