Skip to content

Commit 0f0bcb7

Browse files
jphenowgargakshit
andauthored
Bump requeue timeout (#15)
Do not poll `pgbackrest` this fast Signed-off-by: Akshit Garg <[email protected]> Co-authored-by: Akshit Garg <[email protected]>
1 parent b539b61 commit 0f0bcb7

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

percona/controller/pgbackup/controller.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ func (r *PGBackupReconciler) SetupWithManager(mgr manager.Manager) error {
5454
Complete(r))
5555
}
5656

57+
const (
58+
requeueTimeout = time.Second * 15
59+
)
60+
5761
// +kubebuilder:rbac:groups=pgv2.percona.com,resources=perconapgbackups,verbs=create;get;list;watch;update;delete;patch
5862
// +kubebuilder:rbac:groups=pgv2.percona.com,resources=perconapgbackups/status,verbs=create;patch;update
5963
// +kubebuilder:rbac:groups=pgv2.percona.com,resources=perconapgclusters,verbs=get;list;create;update;patch;watch
@@ -82,7 +86,7 @@ func (r *PGBackupReconciler) Reconcile(ctx context.Context, request reconcile.Re
8286
if _, err := runFinalizers(ctx, r.Client, pgBackup); err != nil {
8387
return reconcile.Result{}, errors.Wrap(err, "failed to run finalizers")
8488
}
85-
return reconcile.Result{RequeueAfter: time.Second * 5}, nil
89+
return reconcile.Result{RequeueAfter: requeueTimeout}, nil
8690
}
8791

8892
if pgBackup.Status.State != v2.BackupFailed && pgBackup.Status.State != v2.BackupSucceeded {
@@ -101,7 +105,7 @@ func (r *PGBackupReconciler) Reconcile(ctx context.Context, request reconcile.Re
101105

102106
if pgCluster.Spec.Pause != nil && *pgCluster.Spec.Pause {
103107
log.Info("Can't start backup. PostgresCluster is paused", "pg-backup", pgBackup.Name, "cluster", pgCluster.Name)
104-
return reconcile.Result{RequeueAfter: time.Second * 5}, nil
108+
return reconcile.Result{RequeueAfter: requeueTimeout}, nil
105109
}
106110

107111
// start backup only if backup job doesn't exist
@@ -117,7 +121,7 @@ func (r *PGBackupReconciler) Reconcile(ctx context.Context, request reconcile.Re
117121
}
118122
if runningBackup != "" && runningBackup != pgBackup.Name {
119123
log.Info("Can't start backup. Previous backup is still in progress", "pg-backup", pgBackup.Name, "cluster", pgCluster.Name)
120-
return reconcile.Result{RequeueAfter: time.Second * 5}, nil
124+
return reconcile.Result{RequeueAfter: requeueTimeout}, nil
121125
}
122126
if err := startBackup(ctx, r.Client, pgBackup); err != nil {
123127
return reconcile.Result{}, errors.Wrap(err, "failed to start backup")
@@ -172,7 +176,7 @@ func (r *PGBackupReconciler) Reconcile(ctx context.Context, request reconcile.Re
172176
if errors.Is(err, ErrBackupJobNotFound) {
173177
log.Info("Waiting for backup to start")
174178

175-
return reconcile.Result{RequeueAfter: time.Second * 5}, nil
179+
return reconcile.Result{RequeueAfter: requeueTimeout}, nil
176180
}
177181
return reconcile.Result{}, errors.Wrap(err, "find backup job")
178182
}
@@ -228,7 +232,7 @@ func (r *PGBackupReconciler) Reconcile(ctx context.Context, request reconcile.Re
228232
log.Info("Backup succeeded")
229233
default:
230234
log.Info("Waiting for backup to complete")
231-
return reconcile.Result{RequeueAfter: time.Second * 5}, nil
235+
return reconcile.Result{RequeueAfter: requeueTimeout}, nil
232236
}
233237

234238
pgCluster := &v2.PerconaPGCluster{}
@@ -247,7 +251,7 @@ func (r *PGBackupReconciler) Reconcile(ctx context.Context, request reconcile.Re
247251
}
248252
if !done {
249253
log.Info("Waiting for crunchy reconciler to finish")
250-
return reconcile.Result{RequeueAfter: time.Second * 5}, nil
254+
return reconcile.Result{RequeueAfter: requeueTimeout}, nil
251255
}
252256

253257
if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
@@ -611,7 +615,7 @@ func finishBackup(ctx context.Context, c client.Client, pgBackup *v2.PerconaPGBa
611615
// If we delete the job labels without waiting for the reconcile to finish, the Crunchy reconciler will
612616
// receive the pgcluster with the "naming.PGBackRestBackup" annotation, but will not find the manual backup job.
613617
// It will attempt to create a new job with the same name, failing and resulting in a scary error in the logs.
614-
return &reconcile.Result{RequeueAfter: time.Second * 5}, nil
618+
return &reconcile.Result{RequeueAfter: requeueTimeout}, nil
615619
}
616620

617621
// Remove PGBackRest labels to prevent the job from being
@@ -650,7 +654,7 @@ func finishBackup(ctx context.Context, c client.Client, pgBackup *v2.PerconaPGBa
650654
return nil, errors.Wrapf(err, "delete %s annotation", pNaming.AnnotationBackupInProgress)
651655
}
652656
if !deleted {
653-
return &reconcile.Result{RequeueAfter: time.Second * 5}, nil
657+
return &reconcile.Result{RequeueAfter: requeueTimeout}, nil
654658
}
655659

656660
if checkBackupJob(job) != v2.BackupSucceeded {

0 commit comments

Comments
 (0)