From ad381c4ff015e63f0c9b2734bae16f812423d158 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Thu, 17 Oct 2024 17:31:45 +0200 Subject: [PATCH] rbd: implement Manager.GetVolumeGroupSnapshotByID The GetVolumeGroupSnapshotByID function makes it possible to get a VolumeGroupSnapshot object from the Manager by passing a request-id. This makes it simple for the Group Controller Server to check if a VolumeGroupSnapshot already exists, so it is not needed to try and re-create an existing one. Signed-off-by: Niels de Vos --- internal/rbd/manager.go | 17 +++++++++++++++++ internal/rbd/types/manager.go | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/internal/rbd/manager.go b/internal/rbd/manager.go index ebb20b6f5..d637c89a7 100644 --- a/internal/rbd/manager.go +++ b/internal/rbd/manager.go @@ -320,6 +320,23 @@ func (mgr *rbdManager) CreateVolumeGroup(ctx context.Context, name string) (type return vg, nil } +func (mgr *rbdManager) GetVolumeGroupSnapshotByID( + ctx context.Context, + id string, +) (types.VolumeGroupSnapshot, error) { + creds, err := mgr.getCredentials() + if err != nil { + return nil, err + } + + vgs, err := rbd_group.GetVolumeGroupSnapshot(ctx, id, mgr.csiID, creds, mgr) + if err != nil { + return nil, fmt.Errorf("failed to get volume group with id %q: %w", id, err) + } + + return vgs, nil +} + func (mgr *rbdManager) CreateVolumeGroupSnapshot( ctx context.Context, vg types.VolumeGroup, diff --git a/internal/rbd/types/manager.go b/internal/rbd/types/manager.go index c2541b493..105e28374 100644 --- a/internal/rbd/types/manager.go +++ b/internal/rbd/types/manager.go @@ -53,6 +53,10 @@ type Manager interface { // and records details about it in the journal. CreateVolumeGroup(ctx context.Context, name string) (VolumeGroup, error) + // GetVolumeGroupSnapshotByID resolves the VolumeGroupSnapshot from the + // CSI id/handle. + GetVolumeGroupSnapshotByID(ctx context.Context, id string) (VolumeGroupSnapshot, error) + // CreateVolumeGroupSnapshot instructs the Manager to create a // VolumeGroupSnapshot from the VolumeGroup. All snapshots in the // returned VolumeGroupSnapshot have been taken while I/O on the