-
Notifications
You must be signed in to change notification settings - Fork 80
K8SPG-992: remove keep-job finalizer if cluster is deleted #1724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7ca5443
8ae2668
7d6ca81
50118ff
0b4b010
ec911b3
9924e38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -409,6 +409,33 @@ func ensureFinalizers(ctx context.Context, cl client.Client, pgBackup *v2.Percon | |
| func deleteBackupFinalizer(c client.Client, pg *v2.PerconaPGCluster) func(ctx context.Context, pgBackup *v2.PerconaPGBackup) error { | ||
| return func(ctx context.Context, pgBackup *v2.PerconaPGBackup) error { | ||
| if pg == nil { | ||
| // If the cluster was previously deleted, we cannot call finishBackup to remove | ||
| // annotations from the PGCluster. In that case, we no longer need the job to | ||
| // exist and we can remove the keep-job finalizer. | ||
|
Comment on lines
+412
to
+414
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why the removal of Shouldn't we instead set a watch on the Job and Cluster, requeue events for corresponding PGBackup and at the top of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The delete-backup finalizer is added before the backup job is created. So a backup job with keep-job cannot exist without the corresponding pgbackup having the delete-backup finalizer. The reason for tying keep-job removal to the delete-backup finalizer is the idea that delete-backup owns the backup cleanup sequence: it removes the backup labels and annotations from the cluster and then releases keep-job in the required order. If the cluster no longer exists, releasing keep-job is still the remaining part of the same cleanup operation, so it belongs in this finalizer. Moving this logic to the top of Reconcile would not change the behavior unless someone manually removed the delete-backup finalizer, which users should not touch. |
||
| job, err := findBackupJob(ctx, c, pgBackup) | ||
| if errors.Is(err, ErrBackupJobNotFound) || k8serrors.IsNotFound(err) { | ||
| return nil | ||
| } | ||
| if err != nil { | ||
| return errors.Wrap(err, "find backup job") | ||
| } | ||
|
|
||
| if !controllerutil.ContainsFinalizer(job, pNaming.FinalizerKeepJob) { | ||
| return nil | ||
| } | ||
|
|
||
| if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error { | ||
| j := new(batchv1.Job) | ||
| if err := c.Get(ctx, client.ObjectKeyFromObject(job), j); err != nil { | ||
| return client.IgnoreNotFound(err) | ||
| } | ||
|
|
||
| controllerutil.RemoveFinalizer(j, pNaming.FinalizerKeepJob) | ||
| return c.Update(ctx, j) | ||
|
pooknull marked this conversation as resolved.
|
||
| }); err != nil { | ||
| return errors.Wrap(err, "remove keep-job finalizer") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.