-
Notifications
You must be signed in to change notification settings - Fork 167
K8SPSMDB-1075 use controller runtime builder #1692
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 18 commits
16146b9
7232b2e
48cab0b
86e1b54
42fa1a3
81487cc
5b1a14e
b5273d0
944bce6
25a6a8b
31692b1
af6bb73
e4a0c91
5246891
265f439
58ef4f7
1273100
a1c4006
45ff87f
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 |
|---|---|---|
|
|
@@ -14,20 +14,18 @@ import ( | |
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/client-go/util/retry" | ||
| "sigs.k8s.io/controller-runtime/pkg/builder" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/controller" | ||
| "sigs.k8s.io/controller-runtime/pkg/handler" | ||
| logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
| "sigs.k8s.io/controller-runtime/pkg/manager" | ||
| "sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
| "sigs.k8s.io/controller-runtime/pkg/source" | ||
|
|
||
| pbmBackup "github.com/percona/percona-backup-mongodb/pbm/backup" | ||
| pbmErrors "github.com/percona/percona-backup-mongodb/pbm/errors" | ||
| "github.com/percona/percona-backup-mongodb/pbm/storage" | ||
| "github.com/percona/percona-backup-mongodb/pbm/storage/azure" | ||
| "github.com/percona/percona-backup-mongodb/pbm/storage/s3" | ||
|
|
||
| "github.com/percona/percona-server-mongodb-operator/clientcmd" | ||
| psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1" | ||
| "github.com/percona/percona-server-mongodb-operator/pkg/naming" | ||
|
|
@@ -67,29 +65,20 @@ func newReconciler(mgr manager.Manager) (reconcile.Reconciler, error) { | |
| } | ||
|
|
||
| // add adds a new Controller to mgr with r as the reconcile.Reconciler | ||
| func add(mgr manager.Manager, r reconcile.Reconciler) error { | ||
| // Create a new controller | ||
| c, err := controller.New("psmdbbackup-controller", mgr, controller.Options{Reconciler: r}) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Watch for changes to primary resource PerconaServerMongoDBBackup | ||
| err = c.Watch(source.Kind(mgr.GetCache(), &psmdbv1.PerconaServerMongoDBBackup{}, &handler.TypedEnqueueRequestForObject[*psmdbv1.PerconaServerMongoDBBackup]{})) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // TODO(user): Modify this to be the types you create that are owned by the primary resource | ||
| // Watch for changes to secondary resource Pods and requeue the owner PerconaServerMongoDBBackup | ||
| err = c.Watch(source.Kind(mgr.GetCache(), &corev1.Pod{}, handler.TypedEnqueueRequestForOwner[*corev1.Pod]( | ||
| mgr.GetScheme(), mgr.GetRESTMapper(), &psmdbv1.PerconaServerMongoDBBackup{}, handler.OnlyControllerOwner(), | ||
| ))) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| func add(mgr manager.Manager, r reconcile.Reconciler) error { | ||
| return builder.ControllerManagedBy(mgr). | ||
| Named("psmdbbackup-controller"). | ||
| For(&psmdbv1.PerconaServerMongoDBBackup{}). | ||
| Watches( | ||
| &corev1.Pod{}, | ||
| handler.EnqueueRequestForOwner( | ||
| mgr.GetScheme(), mgr.GetRESTMapper(), | ||
| &psmdbv1.PerconaServerMongoDBBackup{}, | ||
| handler.OnlyControllerOwner(), | ||
| ), | ||
| ). | ||
| Complete(r) | ||
| } | ||
|
|
||
| var _ reconcile.Reconciler = &ReconcilePerconaServerMongoDBBackup{} | ||
|
|
@@ -177,15 +166,6 @@ func (r *ReconcilePerconaServerMongoDBBackup) Reconcile(ctx context.Context, req | |
| if err != nil { | ||
| return rr, errors.Wrapf(err, "set defaults for %s/%s", cluster.Namespace, cluster.Name) | ||
| } | ||
| // TODO: Remove after 1.15 | ||
| if cluster.CompareVersion("1.12.0") >= 0 && cr.Spec.ClusterName == "" { | ||
| cr.Spec.ClusterName = cr.Spec.PSMDBCluster | ||
| cr.Spec.PSMDBCluster = "" | ||
| err = r.client.Update(ctx, cr) | ||
| if err != nil { | ||
| return rr, errors.Wrap(err, "failed to update clusterName") | ||
| } | ||
| } | ||
|
Comment on lines
-180
to
-188
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 sync with @fiowro for release notes, we need to mention this field is deprecated
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. yep, sure
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. @fiowro we need to add to docs, that this field was deleted. |
||
| } | ||
|
|
||
| bcp, err := r.newBackup(ctx, cluster) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[goimports-reviser] reported by reviewdog 🐶