-
Notifications
You must be signed in to change notification settings - Fork 80
K8SPG-1010 Fix secrets cleanup #1685
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
Changes from all commits
b350481
d912b37
2db3ec2
c056e55
c2dc7e7
38a752b
4a9fbfc
72c46dd
add1675
c41c90d
78c453e
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 |
|---|---|---|
|
|
@@ -20,8 +20,6 @@ import ( | |
| v2 "github.com/percona/percona-postgresql-operator/v2/pkg/apis/pgv2.percona.com/v2" | ||
| ) | ||
|
|
||
| type finalizerFunc func(context.Context, *v2.PerconaPGCluster) error | ||
|
|
||
| func (r *PGClusterReconciler) deletePVC(ctx context.Context, cr *v2.PerconaPGCluster) error { | ||
| log := logging.FromContext(ctx) | ||
|
|
||
|
|
@@ -212,24 +210,42 @@ func (r *PGClusterReconciler) deleteBackups(ctx context.Context, cr *v2.PerconaP | |
| return nil | ||
| } | ||
|
|
||
| func (r *PGClusterReconciler) runFinalizers(ctx context.Context, cr *v2.PerconaPGCluster) error { | ||
| type finalizerEntry struct { | ||
| name string | ||
| fn controller.FinalizerFunc[*v2.PerconaPGCluster] | ||
| func (r *PGClusterReconciler) runFinalizers(ctx context.Context, cr *v2.PerconaPGCluster, finalizers []finalizerEntry) error { | ||
|
Contributor
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. after k8sClient.Delete(cr) + one Reconcile pass, but before the PostgresCluster is gone, maybe we can assert on a test that on the fetched CR that FinalizerStopWatchers and FinalizerDeleteBackups are already removed while FinalizerDeletePVC / FinalizerDeleteSSL are still present
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. good point, thanks for the suggestion, added the "pre-deletion finalizers removed before PostgresCluster is gone" unit test |
||
| for _, entry := range finalizers { | ||
| if _, err := controller.RunFinalizer(ctx, r.Client, cr, entry.name, entry.fn); err != nil { | ||
| return errors.Wrapf(err, "run finalizer %s", entry.name) | ||
| } | ||
| } | ||
|
|
||
| finalizers := []finalizerEntry{ | ||
| {pNaming.FinalizerDeletePVC, r.deletePVCAndSecrets}, | ||
| {pNaming.FinalizerDeleteSSL, r.deleteTLSSecrets}, | ||
| return nil | ||
| } | ||
|
|
||
| type finalizerEntry struct { | ||
| name string | ||
| fn controller.FinalizerFunc[*v2.PerconaPGCluster] | ||
| } | ||
|
|
||
| // prePostgresClusterDeletionFinalizers returns finalizers that must run while the | ||
| // PostgresCluster still exists (e.g. operations that require running pods or | ||
| // cluster resources such as stopping watchers and deleting backups from repos). | ||
| func (r *PGClusterReconciler) prePostgresClusterDeletionFinalizers() []finalizerEntry { | ||
|
Contributor
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. please add a comment describing what needs to go into pre finalizers list, i think it'll be confusing in the future
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. good point, done, thanks |
||
| return []finalizerEntry{ | ||
| {pNaming.FinalizerStopWatchers, r.stopExternalWatchers}, | ||
| {pNaming.FinalizerDeleteBackups, r.deleteBackups}, | ||
| } | ||
| } | ||
|
|
||
| for _, entry := range finalizers { | ||
| if _, err := controller.RunFinalizer(ctx, r.Client, cr, entry.name, entry.fn); err != nil { | ||
| return errors.Wrapf(err, "run finalizer %s", entry.name) | ||
| } | ||
| func (r *PGClusterReconciler) postPostgresClusterDeletionFinalizers() []finalizerEntry { | ||
| return []finalizerEntry{ | ||
| {pNaming.FinalizerDeletePVC, r.deletePVCAndSecrets}, | ||
| {pNaming.FinalizerDeleteSSL, r.deleteTLSSecrets}, | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| func (r *PGClusterReconciler) runPrePostgresClusterDeletionFinalizers(ctx context.Context, cr *v2.PerconaPGCluster) error { | ||
| return r.runFinalizers(ctx, cr, r.prePostgresClusterDeletionFinalizers()) | ||
| } | ||
|
|
||
| func (r *PGClusterReconciler) runPostPostgresClusterDeletionFinalizers(ctx context.Context, cr *v2.PerconaPGCluster) error { | ||
| return r.runFinalizers(ctx, cr, r.postPostgresClusterDeletionFinalizers()) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.