-
What should be the most efficient way to migrate the current reconciler to this one? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is a good question. First, as a library that sits on top of controller-runtime, you have full access to controller-runtime types and capabilities. This makes it possible to migrate incrementally. Adopt as much (or little) as makes sense for your needs. It's perfectly normal to leave a reconciler or webhook in pure controller-runtime types if r-r doesn't provide a paved path that matches where you want to go. The best place to start when migrating is with a good test suite for your controller, this way you can have confidence that the refactoring isn't introducing new unintended behavior. The test support in reconciler-runtime is my personal favorite feature. You can use Once you feel there is sufficient test coverage to have confidence in the next steps, we can start to migrate the reconciler. The Combining the // existing controller-runtime code in your main
ctx := ctrl.SetupSignalHandler()
mgr := ... // the controller-runtime Manager
resyncPeriod := 10 * time.Hour // duration interval that controller-runtime controller will reprocess each resource
config := reconcilers.NewConfig(mgr, &foov1.Bar{}, resyncPeriod)
// new reconciler-runtime behavior, typically loaded from your "controllers" package
r := &reconcilers.ResourceReconciler[*foov1.Bar]{
Reconciler: &reconcilers.SyncReconciler[*foov1.Bar]{
Sync: func(ctx context.Context, resource *foov1.Bar) error {
// TODO add business logic
return nil
},
},
Config: config,
}
// new reconciler-runtime code, typically in your main
if err := r.SetupWithManager(ctx, mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Bar")
os.Exit(1)
}
// existing controller-runtime code in your main
setupLog.Info("starting manager")
if err := mgr.Start(ctx); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
} This example is attempting to streamline existing code that will be scaffolded for you with by a tool like kubebuilder with the new reconciler-runtime bits. Keeping architectural separation into multiple packages is strongly encouraged, but skipped here. Once you have your controller logic working inside the As you decompose your reconciler into a set of Hope that helps. |
Beta Was this translation helpful? Give feedback.
This is a good question.
First, as a library that sits on top of controller-runtime, you have full access to controller-runtime types and capabilities. This makes it possible to migrate incrementally. Adopt as much (or little) as makes sense for your needs. It's perfectly normal to leave a reconciler or webhook in pure controller-runtime types if r-r doesn't provide a paved path that matches where you want to go.
The best place to start when migrating is with a good test suite for your controller, this way you can have confidence that the refactoring isn't introducing new unintended behavior. The test support in reconciler-runtime is my personal favorite feature. You can use
ReconcilerTests
…