mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-21 13:50:20 +00:00
rbd: add manager GetSnapshotByID and SnapshotResolver interface
A (CSI) VolumeGroupSnapshot object contains references to Snapshot IDs (or CSI Snapshot handles). In order to work with a VolumeGroupSnapshot struct, the Snapshot IDs need to be resolved into rbdSnapshot structs. Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
parent
455a90e9f4
commit
9bea3feff1
@ -139,6 +139,31 @@ func (mgr *rbdManager) GetVolumeByID(ctx context.Context, id string) (types.Volu
|
||||
return volume, nil
|
||||
}
|
||||
|
||||
func (mgr *rbdManager) GetSnapshotByID(ctx context.Context, id string) (types.Snapshot, error) {
|
||||
creds, err := mgr.getCredentials()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
snapshot, err := genSnapFromSnapID(ctx, id, creds, mgr.secrets)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, ErrImageNotFound):
|
||||
err = fmt.Errorf("volume %s not found: %w", id, err)
|
||||
|
||||
return nil, err
|
||||
case errors.Is(err, util.ErrPoolNotFound):
|
||||
err = fmt.Errorf("pool %s not found for %s: %w", snapshot.Pool, id, err)
|
||||
|
||||
return nil, err
|
||||
default:
|
||||
return nil, fmt.Errorf("failed to get volume from id %q: %w", id, err)
|
||||
}
|
||||
}
|
||||
|
||||
return snapshot, nil
|
||||
}
|
||||
|
||||
func (mgr *rbdManager) GetVolumeGroupByID(ctx context.Context, id string) (types.VolumeGroup, error) {
|
||||
creds, err := mgr.getCredentials()
|
||||
if err != nil {
|
||||
|
@ -26,6 +26,12 @@ type VolumeResolver interface {
|
||||
GetVolumeByID(ctx context.Context, id string) (Volume, error)
|
||||
}
|
||||
|
||||
// SnapshotResolver can be used to construct a Snapshot from a CSI SnapshotId.
|
||||
type SnapshotResolver interface {
|
||||
// GetSnapshotByID uses the CSI SnapshotId to resolve the returned Snapshot.
|
||||
GetSnapshotByID(ctx context.Context, id string) (Snapshot, error)
|
||||
}
|
||||
|
||||
// Manager provides a way for other packages to get Volumes and VolumeGroups.
|
||||
// It handles the operations on the backend, and makes sure the journal
|
||||
// reflects the expected state.
|
||||
@ -33,6 +39,9 @@ type Manager interface {
|
||||
// VolumeResolver is fully implemented by the Manager.
|
||||
VolumeResolver
|
||||
|
||||
// SnapshotResolver is fully implemented by the Manager.
|
||||
SnapshotResolver
|
||||
|
||||
// Destroy frees all resources that the Manager allocated.
|
||||
Destroy(ctx context.Context)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user