Skip to content

Commit

Permalink
add r.primaryCleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
  • Loading branch information
ushitora-anqou committed Oct 3, 2024
1 parent b915bfc commit 7d2e4a7
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion internal/controller/mantlebackup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ func (r *MantleBackupReconciler) Reconcile(ctx context.Context, req ctrl.Request
if _, ok := backup.GetAnnotations()[annotDiffTo]; ok {
return ctrl.Result{Requeue: true}, nil
}
result, err := r.primaryCleanup(ctx, logger, &backup)
if err != nil || result != (ctrl.Result{}) {
return result, err
}
return r.removeFinalizer(ctx, logger, &backup, target, isErrTargetPVCNotFound(getSnapshotTargetErr))
}

Expand Down Expand Up @@ -356,7 +360,12 @@ func (r *MantleBackupReconciler) Reconcile(ctx context.Context, req ctrl.Request
if err != nil || result != (ctrl.Result{}) {
return result, err
}
if !prepare.isSecondaryMantleBackupReadyToUse {
if prepare.isSecondaryMantleBackupReadyToUse {
result, err := r.primaryCleanup(ctx, logger, &backup)
if err != nil || result != (ctrl.Result{}) {
return result, err
}
} else {
result, err := r.export(ctx, &backup, r.primarySettings.Client, prepare)
if err != nil || result != (ctrl.Result{}) {
return result, err
Expand Down Expand Up @@ -618,3 +627,24 @@ func (r *MantleBackupReconciler) export(
}
return ctrl.Result{}, nil
}

func (r *MantleBackupReconciler) primaryCleanup(
ctx context.Context,
logger *slog.Logger,
backup *mantlev1.MantleBackup,
) (ctrl.Result, error) { // nolint:unparam
if !backup.DeletionTimestamp.IsZero() {
return ctrl.Result{}, nil
}

// Update the status of the MantleBackup.
if err := r.updateStatusCondition(ctx, logger, backup, metav1.Condition{
Type: mantlev1.BackupConditionSyncedToRemote,
Status: metav1.ConditionTrue,
Reason: mantlev1.BackupReasonNone,
}); err != nil {
return ctrl.Result{}, err
}

return ctrl.Result{}, nil
}

0 comments on commit 7d2e4a7

Please sign in to comment.