Skip to content

Commit

Permalink
fixup! implement reconciler for MantleBackupConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
ushitora-anqou committed Jul 8, 2024
1 parent 5afee5d commit 8548600
Showing 1 changed file with 16 additions and 29 deletions.
45 changes: 16 additions & 29 deletions test/e2e/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,10 @@ func (test *backupTest) setupEnv() {
}

func (test *backupTest) teardownEnv() {
It("Delete the MantleBackupConfig and the MantleBackups associated with it.", func() {
mbc, err := getMBC(test.tenantNamespace1, test.mantleBackupConfigName[0])
if err == nil {
_, _, err := kubectl("delete", "-n", test.tenantNamespace1, "mantlebackupconfig", test.mantleBackupConfigName[0])
if err == nil {
mbs, err := listMantleBackupsByMBCUID(test.tenantNamespace1, string(mbc.UID))
if err == nil {
for _, mb := range mbs {
_, _, _ = kubectl("delete", "-n", test.tenantNamespace1, "mantlebackup", mb.Name)
}
}
}
}
})

It("delete resources in the namespace: "+test.tenantNamespace, func() {
err := deleteNamespacedResource(test.tenantNamespace, "mantlebackup")
err := deleteNamespacedResource(test.tenantNamespace, "mantlebackupconfig")
Expect(err).NotTo(HaveOccurred())
err = deleteNamespacedResource(test.tenantNamespace, "mantlebackup")
Expect(err).NotTo(HaveOccurred())
err = deleteNamespacedResource(test.tenantNamespace, "pvc")
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -246,11 +233,11 @@ func (test *backupTest) testCase1() {
func (test *backupTest) testCase2() {
It("should create and rotate MantleBackups from MantleBackupConfig", func() {
By("Creating MantleBackupConfig")
err := applyMantleBackupConfigTemplate(test.tenantNamespace1, test.pvcName1, test.mantleBackupConfigName[2])
err := applyMantleBackupConfigTemplate(test.tenantNamespace, test.pvcName1, test.mantleBackupConfigName[2])
Expect(err).NotTo(HaveOccurred())

By("Waiting for a CronJob to be created")
mbc, err := getMBC(test.tenantNamespace1, test.mantleBackupConfigName[2])
mbc, err := getMBC(test.tenantNamespace, test.mantleBackupConfigName[2])
Expect(err).NotTo(HaveOccurred())
cronJobName := "mbc-" + string(mbc.UID)
Eventually(func() error {
Expand All @@ -265,7 +252,7 @@ func (test *backupTest) testCase2() {
By("Waiting for a MantleBackup to be created")
var mb mantlev1.MantleBackup
Eventually(func() error {
mbs, err := listMantleBackupsByMBCUID(test.tenantNamespace1, string(mbc.UID))
mbs, err := listMantleBackupsByMBCUID(test.tenantNamespace, string(mbc.UID))
if err != nil {
return err
}
Expand All @@ -278,7 +265,7 @@ func (test *backupTest) testCase2() {

By("Waiting for MantleBackups to be rotated")
Eventually(func() error {
mbs, err := listMantleBackupsByMBCUID(test.tenantNamespace1, string(mbc.UID))
mbs, err := listMantleBackupsByMBCUID(test.tenantNamespace, string(mbc.UID))
if err != nil {
return err
}
Expand All @@ -291,15 +278,15 @@ func (test *backupTest) testCase2() {

It("should not delete the MantleBackups even when the MantleBackupConfig is deleted", func() {
By("Creating MantleBackupConfig")
err := applyMantleBackupConfigTemplate(test.tenantNamespace1, test.pvcName1, test.mantleBackupConfigName[4])
err := applyMantleBackupConfigTemplate(test.tenantNamespace, test.pvcName1, test.mantleBackupConfigName[4])
Expect(err).NotTo(HaveOccurred())
mbc, err := getMBC(test.tenantNamespace1, test.mantleBackupConfigName[4])
mbc, err := getMBC(test.tenantNamespace, test.mantleBackupConfigName[4])
Expect(err).NotTo(HaveOccurred())

By("Waiting for a MantleBackup to be created")
var mb mantlev1.MantleBackup
Eventually(func() error {
mbs, err := listMantleBackupsByMBCUID(test.tenantNamespace1, string(mbc.UID))
mbs, err := listMantleBackupsByMBCUID(test.tenantNamespace, string(mbc.UID))
if err != nil {
return err
}
Expand All @@ -324,11 +311,11 @@ func (test *backupTest) testCase2() {

It("should not delete a MantleBackup if it has an annotation of retainIfExpired", func() {
By("Creating MantleBackupConfig")
err := applyMantleBackupConfigTemplate(test.tenantNamespace1, test.pvcName1, test.mantleBackupConfigName[1])
err := applyMantleBackupConfigTemplate(test.tenantNamespace, test.pvcName1, test.mantleBackupConfigName[1])
Expect(err).NotTo(HaveOccurred())

By("Waiting for a CronJob to be created")
mbc, err := getMBC(test.tenantNamespace1, test.mantleBackupConfigName[1])
mbc, err := getMBC(test.tenantNamespace, test.mantleBackupConfigName[1])
Expect(err).NotTo(HaveOccurred())
cronJobName := "mbc-" + string(mbc.UID)
Eventually(func() error {
Expand All @@ -339,7 +326,7 @@ func (test *backupTest) testCase2() {
By("Attaching an annotation of retainIfExpired to a MantleBackup")
var mb mantlev1.MantleBackup
Eventually(func() error {
mbs, err := listMantleBackupsByMBCUID(test.tenantNamespace1, string(mbc.UID))
mbs, err := listMantleBackupsByMBCUID(test.tenantNamespace, string(mbc.UID))
if err != nil {
return err
}
Expand All @@ -362,7 +349,7 @@ func (test *backupTest) testCase2() {

By("Checking mbs not annotated with retainIfExpired are rotated")
Eventually(func() error {
mbs, err := listMantleBackupsByMBCUID(test.tenantNamespace1, string(mbc.UID))
mbs, err := listMantleBackupsByMBCUID(test.tenantNamespace, string(mbc.UID))
if err != nil {
return err
}
Expand Down Expand Up @@ -390,11 +377,11 @@ func (test *backupTest) testCase2() {

It("should re-create a CronJob associated with a MantleBackup when it's deleted by someone", func() {
By("Creating MantleBackupConfig")
err := applyMantleBackupConfigTemplate(test.tenantNamespace1, test.pvcName1, test.mantleBackupConfigName[3])
err := applyMantleBackupConfigTemplate(test.tenantNamespace, test.pvcName1, test.mantleBackupConfigName[3])
Expect(err).NotTo(HaveOccurred())

By("Waiting for a CronJob to be created")
mbc, err := getMBC(test.tenantNamespace1, test.mantleBackupConfigName[3])
mbc, err := getMBC(test.tenantNamespace, test.mantleBackupConfigName[3])
Expect(err).NotTo(HaveOccurred())
cronJobName := "mbc-" + string(mbc.UID)
Eventually(func() error {
Expand Down

0 comments on commit 8548600

Please sign in to comment.