rbd: add code to store/retrieve the image ID

cephcsi need to store and retrieve the rbd image ID
in the omap as we need the image ID to add a
task to remove the image from the Trash.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2020-06-24 12:31:06 +05:30 committed by mergify[bot]
parent 3dcef09676
commit 6ba0cd58b9
2 changed files with 26 additions and 0 deletions

View File

@ -127,6 +127,10 @@ type Config struct {
// Ceph volume was created
csiNameKey string
// CSI ImageID in per Ceph volume object map, containing image ID
// of this Ceph volume
csiImageIDKey string
// CSI image-name key in per Ceph volume object map, containing RBD image-name
// of this Ceph volume
csiImageKey string
@ -160,6 +164,7 @@ func NewCSIVolumeJournal(suffix string) *Config {
csiJournalPool: "csi.journalpool",
cephSnapSourceKey: "",
namespace: "",
csiImageIDKey: "csi.imageid",
encryptKMSKey: "csi.volume.encryptKMS",
commonPrefix: "csi.",
}
@ -176,6 +181,7 @@ func NewCSISnapshotJournal(suffix string) *Config {
csiJournalPool: "csi.journalpool",
cephSnapSourceKey: "csi.source",
namespace: "",
csiImageIDKey: "csi.imageid",
encryptKMSKey: "csi.volume.encryptKMS",
commonPrefix: "csi.",
}
@ -650,6 +656,24 @@ func (conn *Connection) GetImageAttributes(ctx context.Context, pool, objectUUID
return imageAttributes, nil
}
// StoreImageID stores the image ID in omap
func (conn *Connection) StoreImageID(ctx context.Context, pool, reservedUUID, imageID string, cr *util.Credentials) error {
err := util.SetOMapKeyValue(ctx, conn.monitors, cr, pool, conn.config.namespace, conn.config.cephUUIDDirectoryPrefix+reservedUUID, conn.config.csiImageIDKey, imageID)
if err != nil {
return err
}
return nil
}
// GetStoredImageID retrives the stored image ID from the omap
func (conn *Connection) GetStoredImageID(ctx context.Context, pool, reservedUUID string, cr *util.Credentials) (string, error) {
imageID, err := util.GetOMapValue(ctx, conn.monitors, cr, pool, conn.config.namespace, conn.config.cephUUIDDirectoryPrefix+reservedUUID, conn.config.csiImageIDKey)
if err != nil {
return "", err
}
return imageID, nil
}
// Destroy frees any resources and invalidates the journal connection.
func (conn *Connection) Destroy() {
// invalidate cluster connection metadata

View File

@ -96,6 +96,7 @@ type rbdVolume struct {
Mounter string `json:"mounter"`
ClusterID string `json:"clusterId"`
RequestName string
ReservedID string
VolName string `json:"volName"`
MonValueFromSecret string `json:"monValueFromSecret"`
VolSize int64 `json:"volSize"`
@ -121,6 +122,7 @@ type rbdSnapshot struct {
// Pool is where the image snapshot journal and snapshot is stored, and could be the same as `JournalPool`
SourceVolumeID string
RbdImageName string
ReservedID string
NamePrefix string
RbdSnapName string
SnapID string