From 2c47e47cae94bcb276e433a42d3856a0675b59bb Mon Sep 17 00:00:00 2001 From: Ryotaro Banno Date: Wed, 25 Dec 2024 07:44:54 +0000 Subject: [PATCH] test/e2e: multik8s: correct MB sync when primary -> standalone -> primary role change Signed-off-by: Ryotaro Banno --- test/e2e/multik8s/suite_test.go | 78 +++++++++++++++++++++++++++++++++ test/e2e/multik8s/util.go | 2 + 2 files changed, 80 insertions(+) diff --git a/test/e2e/multik8s/suite_test.go b/test/e2e/multik8s/suite_test.go index 6ac8c64..dad3904 100644 --- a/test/e2e/multik8s/suite_test.go +++ b/test/e2e/multik8s/suite_test.go @@ -42,6 +42,7 @@ var _ = Describe("Mantle", func() { Context("wait controller to be ready", waitControllerToBeReady) Context("replication test", replicationTestSuite) Context("change to standalone", changeToStandalone) + Context("change to primary", changeToPrimary) }) func waitControllerToBeReady() { @@ -551,5 +552,82 @@ func changeToStandalone() { g.Expect(found).To(BeTrue()) }, "10s", "1s").Should(Succeed()) }) + + It("should change their roles back to primary/secondary", func() { + By("changing the primary K8s cluster to standalone") + err := changeClusterRole(primaryK8sCluster, rolePrimary) + Expect(err).NotTo(HaveOccurred()) + By("changing the secondary K8s cluster to standalone") + err = changeClusterRole(secondaryK8sCluster, roleSecondary) + Expect(err).NotTo(HaveOccurred()) + }) + }) +} + +func changeToPrimary() { + Describe("change to primary", func() { + var ( + namespace string + pvcName0, backupName00, backupName01, writtenDataHash00, writtenDataHash01 string + pvcName1, backupName10, writtenDataHash10 string + ) + + It("should replicate a MantleBackup resource", func(ctx context.Context) { + namespace = util.GetUniqueName("ns-") + pvcName0 = util.GetUniqueName("pvc-") + backupName00 = util.GetUniqueName("mb-") + + setupEnvironment(namespace, pvcName0) + writtenDataHash00 = writeRandomDataToPV(ctx, namespace, pvcName0) + createMantleBackup(namespace, pvcName0, backupName00) + waitMantleBackupSynced(namespace, backupName00) + }) + + It("should change the role from primary to standalone", func() { + By("changing the primary K8s cluster to standalone") + err := changeClusterRole(primaryK8sCluster, roleStandalone) + Expect(err).NotTo(HaveOccurred()) + }) + + It("should create a MantleBackup resource", func(ctx SpecContext) { + backupName01 = util.GetUniqueName("mb-") + writtenDataHash01 = writeRandomDataToPV(ctx, namespace, pvcName0) + + createMantleBackup(namespace, pvcName0, backupName01) + + pvcName1 = util.GetUniqueName("pvc-") + backupName10 = util.GetUniqueName("mb-") + + Eventually(func() error { + return applyPVCTemplate(primaryK8sCluster, namespace, pvcName1) + }).Should(Succeed()) + writtenDataHash10 = writeRandomDataToPV(ctx, namespace, pvcName1) + createMantleBackup(namespace, pvcName1, backupName10) + }) + + It("should change the role from standalone to primary", func() { + By("changing the primary K8s cluster to primary") + err := changeClusterRole(primaryK8sCluster, rolePrimary) + Expect(err).NotTo(HaveOccurred()) + }) + + It("should synchronize MantleBackups correctly", func() { + waitMantleBackupSynced(namespace, backupName01) + waitMantleBackupSynced(namespace, backupName10) + }) + + It("should restore MantleBackups correctly", func(ctx SpecContext) { + restoreName00 := util.GetUniqueName("mr-") + ensureCorrectRestoration(primaryK8sCluster, ctx, namespace, backupName00, restoreName00, writtenDataHash00) + ensureCorrectRestoration(secondaryK8sCluster, ctx, namespace, backupName00, restoreName00, writtenDataHash00) + + restoreName01 := util.GetUniqueName("mr-") + ensureCorrectRestoration(primaryK8sCluster, ctx, namespace, backupName01, restoreName01, writtenDataHash01) + ensureCorrectRestoration(secondaryK8sCluster, ctx, namespace, backupName01, restoreName01, writtenDataHash01) + + restoreName10 := util.GetUniqueName("mr-") + ensureCorrectRestoration(primaryK8sCluster, ctx, namespace, backupName10, restoreName10, writtenDataHash10) + ensureCorrectRestoration(secondaryK8sCluster, ctx, namespace, backupName10, restoreName10, writtenDataHash10) + }) }) } diff --git a/test/e2e/multik8s/util.go b/test/e2e/multik8s/util.go index 5ff7dfa..d5d155c 100644 --- a/test/e2e/multik8s/util.go +++ b/test/e2e/multik8s/util.go @@ -27,6 +27,8 @@ const ( primaryK8sCluster = 1 secondaryK8sCluster = 2 roleStandalone = "standalone" + rolePrimary = "primary" + roleSecondary = "secondary" ) var (