From b9b4b1e34ef4eb72e48e408dd6e40495cfe0ae24 Mon Sep 17 00:00:00 2001 From: Rakshith R Date: Fri, 16 Jul 2021 15:10:09 +0530 Subject: [PATCH] rbd: refractor RegenerateJournal() to take in volumeAttributes This commit refractors RegenerateJournal() to take in volumeAttributes map[string]string as argument so it can extract required attributes internally. Signed-off-by: Rakshith R --- .../controller/persistentvolume/persistentvolume.go | 5 +---- internal/rbd/rbd_journal.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/controller/persistentvolume/persistentvolume.go b/internal/controller/persistentvolume/persistentvolume.go index 5d7b3470d..7e884e3cd 100644 --- a/internal/controller/persistentvolume/persistentvolume.go +++ b/internal/controller/persistentvolume/persistentvolume.go @@ -172,10 +172,7 @@ func (r ReconcilePersistentVolume) reconcilePV(ctx context.Context, obj runtime. if pv.Spec.CSI == nil || pv.Spec.CSI.Driver != r.config.DriverName { return nil } - pool := pv.Spec.CSI.VolumeAttributes["pool"] - journalPool := pv.Spec.CSI.VolumeAttributes["journalPool"] requestName := pv.Name - imageName := pv.Spec.CSI.VolumeAttributes["imageName"] volumeHandler := pv.Spec.CSI.VolumeHandle secretName := "" secretNamespace := "" @@ -210,7 +207,7 @@ func (r ReconcilePersistentVolume) reconcilePV(ctx context.Context, obj runtime. } defer cr.DeleteCredentials() - rbdVolID, err := rbd.RegenerateJournal(imageName, volumeHandler, pool, journalPool, requestName, cr) + rbdVolID, err := rbd.RegenerateJournal(pv.Spec.CSI.VolumeAttributes, volumeHandler, requestName, cr) if err != nil { util.ErrorLogMsg("failed to regenerate journal %s", err) diff --git a/internal/rbd/rbd_journal.go b/internal/rbd/rbd_journal.go index 0dbe80d5c..2a425d048 100644 --- a/internal/rbd/rbd_journal.go +++ b/internal/rbd/rbd_journal.go @@ -522,6 +522,7 @@ func undoVolReservation(ctx context.Context, rbdVol *rbdVolume, cr *util.Credent // complete omap mapping between imageName and volumeID. // RegenerateJournal performs below operations +// Extract parameters journalPool, pool from volumeAttributes // Extract information from volumeID // Get pool ID from pool name // Extract uuid from volumeID @@ -530,13 +531,15 @@ func undoVolReservation(ctx context.Context, rbdVol *rbdVolume, cr *util.Credent // The volume handler won't remain same as its contains poolID,clusterID etc // which are not same across clusters. func RegenerateJournal( - imageName, volumeID, pool, journalPool, requestName string, + volumeAttributes map[string]string, + volumeID, requestName string, cr *util.Credentials) (string, error) { ctx := context.Background() var ( options map[string]string vi util.CSIIdentifier rbdVol *rbdVolume + ok bool ) options = make(map[string]string) @@ -560,12 +563,14 @@ func RegenerateJournal( return "", err } - rbdVol.Pool = pool + if rbdVol.Pool, ok = volumeAttributes["pool"]; !ok { + return "", errors.New("required 'pool' parameter missing in volume attributes") + } err = rbdVol.Connect(cr) if err != nil { return "", err } - rbdVol.JournalPool = journalPool + rbdVol.JournalPool = volumeAttributes["journalPool"] if rbdVol.JournalPool == "" { rbdVol.JournalPool = rbdVol.Pool }