Skip to content

Commit

Permalink
K8SPG-496: trigger reconcile on PerconaPGBackup update (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
pooknull authored Jan 16, 2024
1 parent 8f9eb42 commit c55ccc3
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion percona/controller/pgcluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (r *PGClusterReconciler) SetupWithManager(mgr manager.Manager) error {
Watches(&corev1.Service{}, r.watchServices()).
Watches(&corev1.Secret{}, r.watchSecrets()).
Watches(&batchv1.Job{}, r.watchBackupJobs()).
Watches(&v2.PerconaPGBackup{}, r.watchPGBackups()).
Complete(r)
}

Expand Down Expand Up @@ -109,6 +110,21 @@ func (r *PGClusterReconciler) watchBackupJobs() handler.Funcs {
}
}

func (r *PGClusterReconciler) watchPGBackups() handler.Funcs {
return handler.Funcs{
UpdateFunc: func(ctx context.Context, e event.UpdateEvent, q workqueue.RateLimitingInterface) {
pgBackup, ok := e.ObjectNew.(*v2.PerconaPGBackup)
if !ok {
return
}
q.Add(reconcile.Request{NamespacedName: client.ObjectKey{
Namespace: pgBackup.GetNamespace(),
Name: pgBackup.Spec.PGCluster,
}})
},
}
}

func (r *PGClusterReconciler) watchSecrets() handler.Funcs {
return handler.Funcs{
UpdateFunc: func(ctx context.Context, e event.UpdateEvent, q workqueue.RateLimitingInterface) {
Expand Down Expand Up @@ -374,7 +390,8 @@ func isBackupRunning(ctx context.Context, cl client.Reader, cr *v2.PerconaPGClus

backupList := &v2.PerconaPGBackupList{}
if err := cl.List(ctx, backupList, &client.ListOptions{
Namespace: cr.Namespace}); err != nil {
Namespace: cr.Namespace,
}); err != nil {
return false, errors.Wrap(err, "list backups")
}

Expand Down

0 comments on commit c55ccc3

Please sign in to comment.