diff --git a/test/e2e/backup_test.go b/test/e2e/backup_test.go index 21f7ff2e..b1e3b0af 100644 --- a/test/e2e/backup_test.go +++ b/test/e2e/backup_test.go @@ -9,9 +9,6 @@ import ( "github.com/cybozu-go/mantle/test/util" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "k8s.io/apimachinery/pkg/api/meta" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/yaml" ) const ( @@ -154,6 +151,18 @@ func (test *backupTest) testCase1() { return checkSnapshotExist(cephCluster1Namespace, test.poolName, imageName, test.mantleBackupName3) }).Should(Succeed()) + + By("Checking that the status.conditions of the MantleBackup resource becomes \"ReadyToUse\"") + Eventually(func() error { + ready, err := isMantleBackupReady(test.tenantNamespace, test.mantleBackupName3) + if err != nil { + return err + } + if !ready { + return fmt.Errorf("not ready") + } + return nil + }).Should(Succeed()) }) It("should not delete MantleBackup resource when delete backup target PVC", func() { @@ -173,14 +182,10 @@ func (test *backupTest) testCase1() { return fmt.Errorf("PVC %s still exists. stdout: %s", test.pvcName2, stdout) }).Should(Succeed()) - By("Checking that the status.conditions of the MantleBackup resource remain \"Bound\"") - stdout, _, err := kubectl("-n", test.tenantNamespace, "get", "mantlebackup", test.mantleBackupName3, "-o", "json") - Expect(err).NotTo(HaveOccurred()) - var backup mantlev1.MantleBackup - err = yaml.Unmarshal(stdout, &backup) + By("Checking that the status.conditions of the MantleBackup resource remain \"ReadyToUse\"") + ready, err := isMantleBackupReady(test.tenantNamespace, test.mantleBackupName3) Expect(err).NotTo(HaveOccurred()) - Expect(meta.FindStatusCondition(backup.Status.Conditions, mantlev1.BackupConditionReadyToUse).Status). - To(Equal(metav1.ConditionTrue)) + Expect(ready).To(Equal(true)) }) It("should delete MantleBackup resource", func() { diff --git a/test/e2e/util.go b/test/e2e/util.go index c10d5de5..6a451d92 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -13,6 +13,7 @@ import ( mantlev1 "github.com/cybozu-go/mantle/api/v1" "github.com/cybozu-go/mantle/internal/controller" testutil "github.com/cybozu-go/mantle/test/util" + "gopkg.in/yaml.v2" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" @@ -401,6 +402,20 @@ func getRBDInfo(clusterNS, pool, image string) (*rbdInfo, error) { return &info, nil } +func isMantleBackupReady(namespace, name string) (bool, error) { + stdout, _, err := kubectl("-n", namespace, "get", "mantlebackup", name, "-o", "json") + if err != nil { + return false, err + } + var backup mantlev1.MantleBackup + err = yaml.Unmarshal(stdout, &backup) + if err != nil { + return false, err + } + cond := meta.FindStatusCondition(backup.Status.Conditions, mantlev1.BackupConditionReadyToUse).Status + return cond == metav1.ConditionTrue, nil +} + func isMantleRestoreReady(namespace, name string) bool { stdout, stderr, err := kubectl("get", "mantlerestore", "-n", namespace, name, "-o", "json") if err != nil {