Skip to content

Commit

Permalink
don't disable backup before pausing cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
pooknull committed Aug 29, 2023
1 parent cb308c8 commit 6d70681
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
13 changes: 0 additions & 13 deletions pkg/apis/psmdb/v1/psmdb_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,19 +457,6 @@ func (cr *PerconaServerMongoDB) CheckNSetDefaults(platform version.Platform, log
if err := replset.NonVoting.SetDefaults(cr, replset); err != nil {
return errors.Wrap(err, "set nonvoting defaults")
}

if cr.Spec.Pause {
if cr.Status.State == AppStateStopping {
log.Info("Pausing cluster", "replset", replset.Name)
}
replset.Arbiter.Enabled = false
replset.NonVoting.Enabled = false
}
}

// there is shouldn't be any backups while pause
if cr.Spec.Pause {
cr.Spec.Backup.Enabled = false
}

if cr.Spec.Backup.Enabled {
Expand Down
34 changes: 29 additions & 5 deletions pkg/controller/perconaservermongodb/psmdb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,9 @@ func (r *ReconcilePerconaServerMongoDB) Reconcile(ctx context.Context, request r
}
}

if cr.Spec.Pause {
err = r.reconcilePause(ctx, cr)
if err != nil {
return reconcile.Result{}, err
}
err = r.reconcilePause(ctx, cr)
if err != nil {
return reconcile.Result{}, err
}

err = r.checkConfiguration(ctx, cr)
Expand Down Expand Up @@ -560,7 +558,33 @@ func (r *ReconcilePerconaServerMongoDB) Reconcile(ctx context.Context, request r
}

func (r *ReconcilePerconaServerMongoDB) reconcilePause(ctx context.Context, cr *api.PerconaServerMongoDB) error {
if !cr.Spec.Pause || cr.DeletionTimestamp != nil {
return nil
}

log := logf.FromContext(ctx)

backupRunning, err := r.isBackupRunning(ctx, cr)
if err != nil {
return errors.Wrap(err, "check if backup is running")
}
if backupRunning {
cr.Spec.Pause = false
if err := cr.CheckNSetDefaults(r.serverVersion.Platform, log); err != nil {
return errors.Wrap(err, "failed to set defaults")
}
log.Info("cluster will pause after all backups finished")
return nil
}

for _, rs := range cr.Spec.Replsets {
if cr.Status.State == api.AppStateStopping {
log.Info("Pausing cluster", "replset", rs.Name)
}
rs.Arbiter.Enabled = false
rs.NonVoting.Enabled = false
}

if err := r.deletePSMDBPods(ctx, cr); err != nil {
if err == errWaitingTermination {
log.Info("pausing cluster", "error", err.Error())
Expand Down

0 comments on commit 6d70681

Please sign in to comment.