rbd: implement journalledObject for volumes

implement journalledObject interface to
return the journal objects of the volume.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2024-07-29 13:07:37 +02:00 committed by mergify[bot]
parent a243cf52d4
commit b222b773aa
3 changed files with 41 additions and 14 deletions

View File

@ -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
}

View File

@ -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)
}

View File

@ -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.