diff --git a/e2e/rbd.go b/e2e/rbd.go index c8b71817b367..042fc3f2fe24 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -463,6 +463,173 @@ var _ = Describe("RBD", func() { } }) + By( + "validate PVC mounting if snapshot and parent PVC are deleted chained with depth 2", + func() { + snapChainDepth := 2 + + err := deleteResource(rbdExamplePath + "storageclass.yaml") + if err != nil { + framework.Failf("failed to delete storageclass: %v", err) + } + + err = createRBDStorageClass( + f.ClientSet, + f, + defaultSCName, + nil, + map[string]string{ + "encrypted": "true", + "encryptionKMSID": "vault-test", + }, + deletePolicy) + if err != nil { + framework.Failf("failed to create storageclass: %v", err) + } + + err = createRBDSnapshotClass(f) + if err != nil { + framework.Failf("failed to create storageclass: %v", err) + } + + defer func() { + err = deleteRBDSnapshotClass() + if err != nil { + framework.Failf("failed to delete VolumeSnapshotClass: %v", err) + } + err = deleteResource(rbdExamplePath + "storageclass.yaml") + if err != nil { + framework.Failf("failed to delete storageclass: %v", err) + } + err = createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, nil, deletePolicy) + if err != nil { + framework.Failf("failed to create storageclass: %v", err) + } + }() + + // create PVC and bind it to an app + pvc, err := loadPVC(pvcPath) + if err != nil { + framework.Failf("failed to load PVC: %v", err) + } + + pvc.Namespace = f.UniqueName + app, err := loadApp(appPath) + if err != nil { + framework.Failf("failed to load application: %v", err) + } + app.Namespace = f.UniqueName + err = createPVCAndApp("", f, pvc, app, deployTimeout) + if err != nil { + framework.Failf("failed to create PVC and application: %v", err) + } + // validate created backend rbd images + validateRBDImageCount(f, 1, defaultRBDPool) + validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType) + for i := 0; i < snapChainDepth; i++ { + var pvcClone *v1.PersistentVolumeClaim + snap := getSnapshot(snapshotPath) + snap.Name = fmt.Sprintf("%s-%d", snap.Name, i) + snap.Namespace = f.UniqueName + snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name + + err = createSnapshot(&snap, deployTimeout) + if err != nil { + framework.Failf("failed to create snapshot: %v", err) + } + // validate created backend rbd images + // parent PVC + snapshot + totalImages := 2 + validateRBDImageCount(f, totalImages, defaultRBDPool) + validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType) + validateOmapCount(f, 1, rbdType, defaultRBDPool, snapsType) + pvcClone, err = loadPVC(pvcClonePath) + if err != nil { + framework.Failf("failed to load PVC: %v", err) + } + + // delete parent PVC + err = deletePVCAndApp("", f, pvc, app) + if err != nil { + framework.Failf("failed to delete PVC and application: %v", err) + } + // validate created backend rbd images + validateRBDImageCount(f, 1, defaultRBDPool) + validateOmapCount(f, 0, rbdType, defaultRBDPool, volumesType) + validateOmapCount(f, 1, rbdType, defaultRBDPool, snapsType) + + // create clone PVC + pvcClone.Name = fmt.Sprintf("%s-%d", pvcClone.Name, i) + pvcClone.Namespace = f.UniqueName + pvcClone.Spec.DataSource.Name = snap.Name + err = createPVCAndvalidatePV(f.ClientSet, pvcClone, deployTimeout) + if err != nil { + framework.Failf("failed to create PVC: %v", err) + } + // validate created backend rbd images = snapshot + clone + totalImages = 2 + validateRBDImageCount(f, totalImages, defaultRBDPool) + validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType) + validateOmapCount(f, 1, rbdType, defaultRBDPool, snapsType) + + // delete snapshot + err = deleteSnapshot(&snap, deployTimeout) + if err != nil { + framework.Failf("failed to delete snapshot: %v", err) + } + + // validate created backend rbd images = clone + totalImages = 1 + validateRBDImageCount(f, totalImages, defaultRBDPool) + validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType) + validateOmapCount(f, 0, rbdType, defaultRBDPool, snapsType) + + // create pvc-pvc clone + smartClonePVC, err := loadPVC(pvcSmartClonePath) + if err != nil { + framework.Failf("failed to load smart clone PVC: %v", err) + } + + smartClonePVC.Name = fmt.Sprintf("%s-%d", smartClonePVC.Name, i) + smartClonePVC.Namespace = f.UniqueName + smartClonePVC.Spec.DataSource.Name = pvcClone.Name + err = createPVCAndvalidatePV(f.ClientSet, smartClonePVC, deployTimeout) + if err != nil { + framework.Failf("failed to create smart clone PVC %q: %v", + smartClonePVC.Name, err) + } + + err = deletePVCAndValidatePV(f.ClientSet, smartClonePVC, deployTimeout) + if err != nil { + framework.Failf("failed to delete smart clone PVC %q: %v", + smartClonePVC.Name, err) + } + + app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvcClone.Name + // create application + err = createApp(f.ClientSet, app, deployTimeout) + if err != nil { + framework.Failf("failed to create application: %v", err) + } + + pvc = pvcClone + } + + err = deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout) + if err != nil { + framework.Failf("failed to delete application: %v", err) + } + // delete PVC clone + err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout) + if err != nil { + framework.Failf("failed to delete PVC: %v", err) + } + // validate created backend rbd images + validateRBDImageCount(f, 0, defaultRBDPool) + validateOmapCount(f, 0, rbdType, defaultRBDPool, volumesType) + validateOmapCount(f, 0, rbdType, defaultRBDPool, snapsType) + }) + By("create a PVC and check PVC/PV metadata on RBD image", func() { pvc, err := loadPVC(pvcPath) if err != nil { @@ -3488,152 +3655,6 @@ var _ = Describe("RBD", func() { validateOmapCount(f, 0, rbdType, defaultRBDPool, snapsType) }) - By( - "validate PVC mounting if snapshot and parent PVC are deleted chained with depth 2", - func() { - snapChainDepth := 2 - - err := deleteResource(rbdExamplePath + "storageclass.yaml") - if err != nil { - framework.Failf("failed to delete storageclass: %v", err) - } - - err = createRBDStorageClass( - f.ClientSet, - f, - defaultSCName, - nil, - map[string]string{ - "encrypted": "true", - "encryptionKMSID": "vault-test", - }, - deletePolicy) - if err != nil { - framework.Failf("failed to create storageclass: %v", err) - } - - err = createRBDSnapshotClass(f) - if err != nil { - framework.Failf("failed to create storageclass: %v", err) - } - - defer func() { - err = deleteRBDSnapshotClass() - if err != nil { - framework.Failf("failed to delete VolumeSnapshotClass: %v", err) - } - err = deleteResource(rbdExamplePath + "storageclass.yaml") - if err != nil { - framework.Failf("failed to delete storageclass: %v", err) - } - err = createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, nil, deletePolicy) - if err != nil { - framework.Failf("failed to create storageclass: %v", err) - } - }() - - // create PVC and bind it to an app - pvc, err := loadPVC(pvcPath) - if err != nil { - framework.Failf("failed to load PVC: %v", err) - } - - pvc.Namespace = f.UniqueName - app, err := loadApp(appPath) - if err != nil { - framework.Failf("failed to load application: %v", err) - } - app.Namespace = f.UniqueName - err = createPVCAndApp("", f, pvc, app, deployTimeout) - if err != nil { - framework.Failf("failed to create PVC and application: %v", err) - } - // validate created backend rbd images - validateRBDImageCount(f, 1, defaultRBDPool) - validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType) - for i := 0; i < snapChainDepth; i++ { - var pvcClone *v1.PersistentVolumeClaim - snap := getSnapshot(snapshotPath) - snap.Name = fmt.Sprintf("%s-%d", snap.Name, i) - snap.Namespace = f.UniqueName - snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name - - err = createSnapshot(&snap, deployTimeout) - if err != nil { - framework.Failf("failed to create snapshot: %v", err) - } - // validate created backend rbd images - // parent PVC + snapshot - totalImages := 2 - validateRBDImageCount(f, totalImages, defaultRBDPool) - validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType) - validateOmapCount(f, 1, rbdType, defaultRBDPool, snapsType) - pvcClone, err = loadPVC(pvcClonePath) - if err != nil { - framework.Failf("failed to load PVC: %v", err) - } - - // delete parent PVC - err = deletePVCAndApp("", f, pvc, app) - if err != nil { - framework.Failf("failed to delete PVC and application: %v", err) - } - // validate created backend rbd images - validateRBDImageCount(f, 1, defaultRBDPool) - validateOmapCount(f, 0, rbdType, defaultRBDPool, volumesType) - validateOmapCount(f, 1, rbdType, defaultRBDPool, snapsType) - - // create clone PVC - pvcClone.Name = fmt.Sprintf("%s-%d", pvcClone.Name, i) - pvcClone.Namespace = f.UniqueName - pvcClone.Spec.DataSource.Name = snap.Name - err = createPVCAndvalidatePV(f.ClientSet, pvcClone, deployTimeout) - if err != nil { - framework.Failf("failed to create PVC: %v", err) - } - // validate created backend rbd images = snapshot + clone - totalImages = 2 - validateRBDImageCount(f, totalImages, defaultRBDPool) - validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType) - validateOmapCount(f, 1, rbdType, defaultRBDPool, snapsType) - - // delete snapshot - err = deleteSnapshot(&snap, deployTimeout) - if err != nil { - framework.Failf("failed to delete snapshot: %v", err) - } - - // validate created backend rbd images = clone - totalImages = 1 - validateRBDImageCount(f, totalImages, defaultRBDPool) - validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType) - validateOmapCount(f, 0, rbdType, defaultRBDPool, snapsType) - - app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvcClone.Name - // create application - err = createApp(f.ClientSet, app, deployTimeout) - if err != nil { - framework.Failf("failed to create application: %v", err) - } - - pvc = pvcClone - } - - err = deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout) - if err != nil { - framework.Failf("failed to delete application: %v", err) - } - // delete PVC clone - err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout) - if err != nil { - framework.Failf("failed to delete PVC: %v", err) - } - // validate created backend rbd images - validateRBDImageCount(f, 0, defaultRBDPool) - validateOmapCount(f, 0, rbdType, defaultRBDPool, volumesType) - validateOmapCount(f, 0, rbdType, defaultRBDPool, snapsType) - }) - By("validate PVC Clone chained with depth 2", func() { cloneChainDepth := 2