Skip to content

Commit

Permalink
feat: add support for MaxConcurrentReconciles for reconcilers (#152)
Browse files Browse the repository at this point in the history
This sets up default parameters and allows users to modify the number of
concurrent reconcilers for the `OCIClusterReconciler`,
`OCIMachineReconciler`, `OCIMachinePoolReconciler`,
`OCIManagedMachinePoolReconciler`, `OCIManagedClusterReconciler` and the
`OCIManagedClusterControlPlaneReconciler`.
  • Loading branch information
joekr committed Sep 14, 2022
1 parent 70d5918 commit 6b9c051
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions controllers/ocicluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ func (r *OCIClusterReconciler) reconcile(ctx context.Context, logger logr.Logger
func (r *OCIClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
log := ctrl.LoggerFrom(ctx)
c, err := ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&infrastructurev1beta1.OCICluster{}).
WithEventFilter(predicates.ResourceNotPaused(log)). // don't queue reconcile if resource is paused
WithEventFilter(predicates.ResourceIsNotExternallyManaged(log)). //the externally managed cluster won't be reconciled
Expand Down
1 change: 1 addition & 0 deletions controllers/ocimachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (r *OCIMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// SetupWithManager sets up the controller with the Manager.
func (r *OCIMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
c, err := ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&infrastructurev1beta1.OCIMachine{}).
Watches(
&source.Kind{Type: &clusterv1.Machine{}},
Expand Down
1 change: 1 addition & 0 deletions exp/controllers/ocimanagedcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ func (r *OCIManagedClusterReconciler) SetupWithManager(ctx context.Context, mgr
log := ctrl.LoggerFrom(ctx)
ociManagedControlPlaneMapper, err := OCIManagedControlPlaneToOCIManagedClusterMapper(ctx, r.Client, log)
c, err := ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&infrav1exp.OCIManagedCluster{}).
WithEventFilter(predicates.ResourceNotPaused(log)). // don't queue reconcile if resource is paused
// watch OCIManagedControlPlane resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ func (r *OCIManagedClusterControlPlaneReconciler) SetupWithManager(ctx context.C
log := ctrl.LoggerFrom(ctx)
ociManagedClusterMapper, err := OCIManagedClusterToOCIManagedControlPlaneMapper(ctx, r.Client, log)
c, err := ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&infrav1exp.OCIManagedControlPlane{}).
Watches(
&source.Kind{Type: &infrav1exp.OCIManagedCluster{}},
Expand Down
35 changes: 29 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ var (
logOptions = logs.NewOptions()
webhookPort int
webhookCertDir string

// Flags for reconciler concurrency
ociClusterConcurrency int
ociMachineConcurrency int
ociMachinePoolConcurrency int
)

const (
Expand Down Expand Up @@ -88,6 +93,24 @@ func main() {
)
flag.StringVar(&webhookCertDir, "webhook-cert-dir", "/tmp/k8s-webhook-server/serving-certs/",
"Webhook cert dir, only used when webhook-port is specified.")
flag.IntVar(
&ociClusterConcurrency,
"ocicluster-concurrency",
5,
"Number of OciClusters to process simultaneously",
)
flag.IntVar(
&ociMachineConcurrency,
"ocimachine-concurrency",
10,
"Number of OciMachines to process simultaneously",
)
flag.IntVar(
&ociMachinePoolConcurrency,
"ocimachinepool-concurrency",
5,
"Number of OciMachinePools to process simultaneously",
)

opts := zap.Options{
Development: true,
Expand Down Expand Up @@ -166,7 +189,7 @@ func main() {
Region: region,
ClientProvider: clientProvider,
Recorder: mgr.GetEventRecorderFor("ocicluster-controller"),
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: ociClusterConcurrency}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", scope.OCIClusterKind)
os.Exit(1)
}
Expand All @@ -177,7 +200,7 @@ func main() {
ClientProvider: clientProvider,
Region: region,
Recorder: mgr.GetEventRecorderFor("ocimachine-controller"),
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: ociMachineConcurrency}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", scope.OCIMachineKind)
os.Exit(1)
}
Expand All @@ -191,7 +214,7 @@ func main() {
ClientProvider: clientProvider,
Recorder: mgr.GetEventRecorderFor("ocimachinepool-controller"),
Region: region,
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: ociMachinePoolConcurrency}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", scope.OCIMachinePoolKind)
os.Exit(1)
}
Expand All @@ -205,7 +228,7 @@ func main() {
Region: region,
ClientProvider: clientProvider,
Recorder: mgr.GetEventRecorderFor("ocimanagedmachinepool-controller"),
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: ociMachinePoolConcurrency}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", scope.OCIManagedMachinePoolKind)
os.Exit(1)
}
Expand All @@ -216,7 +239,7 @@ func main() {
Region: region,
ClientProvider: clientProvider,
Recorder: mgr.GetEventRecorderFor("ocimanagedcluster-controller"),
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: ociClusterConcurrency}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", scope.OCIManagedClusterKind)
os.Exit(1)
}
Expand All @@ -227,7 +250,7 @@ func main() {
Region: region,
ClientProvider: clientProvider,
Recorder: mgr.GetEventRecorderFor("ocimanagedclustercontrolplane-controller"),
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: ociClusterConcurrency}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", scope.OCIManagedClusterControlPlaneKind)
os.Exit(1)
}
Expand Down

0 comments on commit 6b9c051

Please sign in to comment.