Skip to content

Commit

Permalink
Merge pull request #65 from cybozu-go/restore-on-secondary
Browse files Browse the repository at this point in the history
Restore on secondary mantle-controller
  • Loading branch information
satoru-takeuchi authored Nov 21, 2024
2 parents 4610f04 + 936a6e3 commit b795740
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
4 changes: 0 additions & 4 deletions internal/controller/mantlerestore_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions test/e2e/multik8s/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
})
})
}
13 changes: 13 additions & 0 deletions test/e2e/multik8s/testdata/mantlerestore-template.yaml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions test/e2e/multik8s/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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", "-")
Expand Down Expand Up @@ -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)
}

0 comments on commit b795740

Please sign in to comment.