Skip to content

Commit

Permalink
Merge pull request #144 from Madhu-1/bug-2138155
Browse files Browse the repository at this point in the history
BUG 2138155: fix namespace name update in metadata and rados object
  • Loading branch information
openshift-merge-robot authored Oct 31, 2022
2 parents dafd8b3 + 037dd3e commit 086ee47
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
21 changes: 21 additions & 0 deletions e2e/rbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ var _ = Describe("RBD", func() {
})

By("reattach the old PV to a new PVC and check if PVC metadata is updated on RBD image", func() {
reattachPVCNamespace := fmt.Sprintf("%s-2", f.Namespace.Name)
pvc, err := loadPVC(pvcPath)
if err != nil {
e2elog.Failf("failed to load PVC: %v", err)
Expand Down Expand Up @@ -573,8 +574,15 @@ var _ = Describe("RBD", func() {
// validate created backend rbd images
validateRBDImageCount(f, 1, defaultRBDPool)
validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType)
// create namespace for reattach PVC, deletion will be taken care by framework
ns, err := f.CreateNamespace(reattachPVCNamespace, nil)
if err != nil {
e2elog.Failf("failed to create namespace: %v", err)
}

pvcObj.Name = "rbd-pvc-new"
pvcObj.Namespace = ns.Name

// unset the resource version as should not be set on objects to be created
pvcObj.ResourceVersion = ""
err = createPVCAndvalidatePV(f.ClientSet, pvcObj, deployTimeout)
Expand All @@ -599,6 +607,19 @@ var _ = Describe("RBD", func() {
e2elog.Failf("expected pvcName %q got %q", pvcObj.Name, pvcName)
}

owner, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], pvcNamespaceKey),
rookNamespace)
if err != nil || stdErr != "" {
e2elog.Failf("failed to get owner name %s/%s %s: err=%v stdErr=%q",
rbdOptions(defaultRBDPool), imageList[0], pvcNamespaceKey, err, stdErr)
}
owner = strings.TrimSuffix(owner, "\n")
if owner != pvcObj.Namespace {
e2elog.Failf("expected pvcNamespace name %q got %q", pvcObj.Namespace, owner)
}

patchBytes = []byte(`{"spec":{"persistentVolumeReclaimPolicy": "Delete"}}`)
_, err = c.CoreV1().PersistentVolumes().Patch(
context.TODO(),
Expand Down
6 changes: 6 additions & 0 deletions internal/journal/voljournal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
10 changes: 8 additions & 2 deletions internal/rbd/rbd_journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -621,8 +621,14 @@ 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, rbdVol.Owner, "")
parameters := k8s.PrepareVolumeMetadata(claimName, owner, "")
err = rbdVol.setAllMetadata(parameters)
if err != nil {
return "", fmt.Errorf("failed to set volume metadata: %w", err)
Expand Down

0 comments on commit 086ee47

Please sign in to comment.