From b222b773aacbe9af1e5bfd3dd7631a1480e032d3 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 29 Jul 2024 13:07:37 +0200 Subject: [PATCH] rbd: implement journalledObject for volumes implement journalledObject interface to return the journal objects of the volume. Signed-off-by: Madhu Rajanna --- internal/rbd/rbd_util.go | 41 +++++++++++++++++++++++++++++++----- internal/rbd/types/group.go | 8 +++---- internal/rbd/types/volume.go | 6 +----- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 28437a921..6f9120719 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -426,11 +426,6 @@ func (rs *rbdSnapshot) String() string { return fmt.Sprintf("%s/%s@%s", rs.Pool, rs.RbdImageName, rs.RbdSnapName) } -// GetID returns the CSI volume handle of the image. -func (ri *rbdImage) GetID(ctx context.Context) (string, error) { - return ri.VolID, nil -} - // createImage creates a new ceph image with provision and volume options. func createImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) error { volSzMiB := fmt.Sprintf("%dM", util.RoundOffVolSize(pOpts.VolSize)) @@ -2187,3 +2182,39 @@ func (rv *rbdVolume) unsetAllMetadata(keys []string) error { return nil } + +// GetID returns the ID of the volume. +func (ri *rbdImage) GetID(ctx context.Context) (string, error) { + if ri.VolID == "" { + return "", errors.New("BUG: VolID is not set") + } + + return ri.VolID, nil +} + +// GetName returns the name of the rbd image. +func (ri *rbdImage) GetName(ctx context.Context) (string, error) { + if ri.RbdImageName == "" { + return "", errors.New("BUG: name is not set") + } + + return ri.RbdImageName, nil +} + +// GetPool returns the name of the pool that holds the Volume. +func (ri *rbdImage) GetPool(ctx context.Context) (string, error) { + if ri.Pool == "" { + return "", errors.New("BUG: pool is not set") + } + + return ri.Pool, nil +} + +// GetClusterID returns the clusterID the volume belongs to. +func (ri *rbdImage) GetClusterID(ctx context.Context) (string, error) { + if ri.ClusterID == "" { + return "", errors.New("BUG: clusterID is not set") + } + + return ri.ClusterID, nil +} diff --git a/internal/rbd/types/group.go b/internal/rbd/types/group.go index 83d0adea3..36f89e807 100644 --- a/internal/rbd/types/group.go +++ b/internal/rbd/types/group.go @@ -24,16 +24,16 @@ import ( ) type journalledObject interface { - // GetID returns the CSI-Addons VolumeGroupId of the VolumeGroup. + // GetID returns the ID in the backend storage for the object. GetID(ctx context.Context) (string, error) - // GetName returns the name in the backend storage for the VolumeGroup. + // GetName returns the name of the object in the backend storage. GetName(ctx context.Context) (string, error) - // GetPool returns the name of the pool that holds the VolumeGroup. + // GetPool returns the name of the pool that holds the object. GetPool(ctx context.Context) (string, error) - // GetClusterID returns the ID of the cluster of the VolumeGroup. + // GetClusterID returns the ID of the cluster of the object. GetClusterID(ctx context.Context) (string, error) } diff --git a/internal/rbd/types/volume.go b/internal/rbd/types/volume.go index 7f534091f..388676cf5 100644 --- a/internal/rbd/types/volume.go +++ b/internal/rbd/types/volume.go @@ -25,15 +25,13 @@ import ( //nolint:interfacebloat // more than 10 methods are needed for the interface type Volume interface { + journalledObject // Destroy frees the resources used by the Volume. Destroy(ctx context.Context) // Delete removes the volume from the storage backend. Delete(ctx context.Context) error - // GetID returns the CSI VolumeID for the volume. - GetID(ctx context.Context) (string, error) - // ToCSI creates a CSI protocol formatted struct of the volume. ToCSI(ctx context.Context) (*csi.Volume, error) @@ -43,8 +41,6 @@ type Volume interface { // RemoveFromGroup removes the Volume from the VolumeGroup. RemoveFromGroup(ctx context.Context, vg VolumeGroup) error - // GetPoolName returns the name of the pool where the volume is stored. - GetPoolName() string // GetCreationTime returns the creation time of the volume. GetCreationTime() (*timestamppb.Timestamp, error) // GetMetadata returns the value of the metadata key from the volume.