From 936a6e3352ae0c4cd29f94627899a7c72e93e28f Mon Sep 17 00:00:00 2001 From: Ryotaro Banno Date: Wed, 20 Nov 2024 04:58:47 +0000 Subject: [PATCH] handle MantleRestore also in secondary mantle-controller Signed-off-by: Ryotaro Banno --- .../controller/mantlerestore_controller.go | 4 ---- test/e2e/multik8s/suite_test.go | 18 ++++++++++++++++++ .../testdata/mantlerestore-template.yaml | 13 +++++++++++++ test/e2e/multik8s/util.go | 15 +++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 test/e2e/multik8s/testdata/mantlerestore-template.yaml diff --git a/internal/controller/mantlerestore_controller.go b/internal/controller/mantlerestore_controller.go index 160479a7..53c05482 100644 --- a/internal/controller/mantlerestore_controller.go +++ b/internal/controller/mantlerestore_controller.go @@ -62,10 +62,6 @@ func NewMantleRestoreReconciler( func (r *MantleRestoreReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { logger := log.FromContext(ctx) - if r.role == RoleSecondary { - return ctrl.Result{}, nil - } - var restore mantlev1.MantleRestore err := r.client.Get(ctx, req.NamespacedName, &restore) if errors.IsNotFound(err) { diff --git a/test/e2e/multik8s/suite_test.go b/test/e2e/multik8s/suite_test.go index 3b1f5b3a..77974efe 100644 --- a/test/e2e/multik8s/suite_test.go +++ b/test/e2e/multik8s/suite_test.go @@ -55,6 +55,7 @@ func replicationTestSuite() { namespace := util.GetUniqueName("ns-") pvcName := util.GetUniqueName("pvc-") backupName := util.GetUniqueName("mb-") + restoreName := util.GetUniqueName("mr-") By("setting up the environment") Eventually(func() error { @@ -160,6 +161,23 @@ func replicationTestSuite() { return nil }).Should(Succeed()) + + By("creating MantleRestore on the secondary k8s cluster by using the MantleBackup replicated above") + Eventually(func() error { + return applyMantleRestoreTemplate(secondaryK8sCluster, namespace, restoreName, backupName) + }).Should(Succeed()) + + By("checking MantleRestore can be ready to use") + Eventually(func() error { + mr, err := getMR(secondaryK8sCluster, namespace, restoreName) + if err != nil { + return err + } + if !meta.IsStatusConditionTrue(mr.Status.Conditions, "ReadyToUse") { + return errors.New("ReadyToUse of .Status.Conditions is not True") + } + return nil + }).Should(Succeed()) }) }) } diff --git a/test/e2e/multik8s/testdata/mantlerestore-template.yaml b/test/e2e/multik8s/testdata/mantlerestore-template.yaml new file mode 100644 index 00000000..235ff467 --- /dev/null +++ b/test/e2e/multik8s/testdata/mantlerestore-template.yaml @@ -0,0 +1,13 @@ +apiVersion: mantle.cybozu.io/v1 +kind: MantleRestore +metadata: + labels: + app.kubernetes.io/name: mantlerestore + app.kubernetes.io/instance: %s + app.kubernetes.io/part-of: mantle + app.kubernetes.io/managed-by: kustomize + app.kubernetes.io/created-by: mantle + name: %s + namespace: %s +spec: + backup: %s diff --git a/test/e2e/multik8s/util.go b/test/e2e/multik8s/util.go index 4c77163e..ca08b530 100644 --- a/test/e2e/multik8s/util.go +++ b/test/e2e/multik8s/util.go @@ -26,6 +26,8 @@ var ( testRBDPoolSCTemplate string //go:embed testdata/mantlebackup-template.yaml testMantleBackupTemplate string + //go:embed testdata/mantlerestore-template.yaml + testMantleRestoreTemplate string kubectlPrefixPrimary = os.Getenv("KUBECTL_PRIMARY") kubectlPrefixSecondary = os.Getenv("KUBECTL_SECONDARY") @@ -84,6 +86,15 @@ func applyMantleBackupTemplate(clusterNo int, namespace, pvcName, backupName str return nil } +func applyMantleRestoreTemplate(clusterNo int, namespace, restoreName, backupName string) error { + manifest := fmt.Sprintf(testMantleRestoreTemplate, restoreName, restoreName, namespace, backupName) + _, _, err := kubectl(clusterNo, []byte(manifest), "apply", "-f", "-") + if err != nil { + return fmt.Errorf("kubectl apply mantlerestore failed. err: %w", err) + } + return nil +} + func applyPVCTemplate(clusterNo int, namespace, name string) error { manifest := fmt.Sprintf(testPVCTemplate, name) _, _, err := kubectl(clusterNo, []byte(manifest), "apply", "-n", namespace, "-f", "-") @@ -133,3 +144,7 @@ func getMB(clusterNo int, namespace, name string) (*mantlev1.MantleBackup, error func getPVC(clusterNo int, namespace, name string) (*corev1.PersistentVolumeClaim, error) { return getObject[corev1.PersistentVolumeClaim](clusterNo, "pvc", namespace, name) } + +func getMR(clusterNo int, namespace, name string) (*mantlev1.MantleRestore, error) { + return getObject[mantlev1.MantleRestore](clusterNo, "mantlerestore", namespace, name) +}