From b33d9ee5833c7bc82d58ed239ab6360b1577cab7 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Thu, 27 Oct 2022 16:51:27 +0200 Subject: [PATCH] rbd: update namespace name in rados object If a PV is reattached to a new PVC in a different namespace we need to update the namespace name in the rados object. Signed-off-by: Madhu Rajanna (cherry picked from commit 07aa9dea5c2ebdb791c54179b451e54e9819c02e) --- internal/journal/voljournal.go | 6 ++++++ internal/rbd/rbd_journal.go | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/journal/voljournal.go b/internal/journal/voljournal.go index 6cbf2f519..7807d2da4 100644 --- a/internal/journal/voljournal.go +++ b/internal/journal/voljournal.go @@ -842,3 +842,9 @@ func (conn *Connection) ReserveNewUUIDMapping(ctx context.Context, return setOMapKeys(ctx, conn, journalPool, cj.namespace, cj.csiDirectory, setKeys) } + +// ResetVolumeOwner updates the owner in the rados object. +func (conn *Connection) ResetVolumeOwner(ctx context.Context, pool, reservedUUID, owner string) error { + return setOMapKeys(ctx, conn, pool, conn.config.namespace, conn.config.cephUUIDDirectoryPrefix+reservedUUID, + map[string]string{conn.config.ownerKey: owner}) +} diff --git a/internal/rbd/rbd_journal.go b/internal/rbd/rbd_journal.go index 98a66050b..e2fadd21f 100644 --- a/internal/rbd/rbd_journal.go +++ b/internal/rbd/rbd_journal.go @@ -535,7 +535,7 @@ func undoVolReservation(ctx context.Context, rbdVol *rbdVolume, cr *util.Credent // Generate new volume Handler // The volume handler won't remain same as its contains poolID,clusterID etc // which are not same across clusters. -// nolint:gocyclo,cyclop // TODO: reduce complexity +// nolint:gocyclo,cyclop,nestif // TODO: reduce complexity func RegenerateJournal( volumeAttributes map[string]string, claimName, @@ -621,6 +621,12 @@ func RegenerateJournal( return "", err } } + if rbdVol.Owner != owner { + err = j.ResetVolumeOwner(ctx, rbdVol.JournalPool, rbdVol.ReservedID, owner) + if err != nil { + return "", err + } + } // Update Metadata on reattach of the same old PV parameters := k8s.PrepareVolumeMetadata(claimName, owner, "") err = rbdVol.setAllMetadata(parameters)