Skip to content

Commit 6b9c051

Browse files
authored
feat: add support for MaxConcurrentReconciles for reconcilers (#152)
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`.
1 parent 70d5918 commit 6b9c051

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

controllers/ocicluster_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ func (r *OCIClusterReconciler) reconcile(ctx context.Context, logger logr.Logger
265265
func (r *OCIClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
266266
log := ctrl.LoggerFrom(ctx)
267267
c, err := ctrl.NewControllerManagedBy(mgr).
268+
WithOptions(options).
268269
For(&infrastructurev1beta1.OCICluster{}).
269270
WithEventFilter(predicates.ResourceNotPaused(log)). // don't queue reconcile if resource is paused
270271
WithEventFilter(predicates.ResourceIsNotExternallyManaged(log)). //the externally managed cluster won't be reconciled

controllers/ocimachine_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func (r *OCIMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request)
163163
// SetupWithManager sets up the controller with the Manager.
164164
func (r *OCIMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
165165
c, err := ctrl.NewControllerManagedBy(mgr).
166+
WithOptions(options).
166167
For(&infrastructurev1beta1.OCIMachine{}).
167168
Watches(
168169
&source.Kind{Type: &clusterv1.Machine{}},

exp/controllers/ocimanagedcluster_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ func (r *OCIManagedClusterReconciler) SetupWithManager(ctx context.Context, mgr
286286
log := ctrl.LoggerFrom(ctx)
287287
ociManagedControlPlaneMapper, err := OCIManagedControlPlaneToOCIManagedClusterMapper(ctx, r.Client, log)
288288
c, err := ctrl.NewControllerManagedBy(mgr).
289+
WithOptions(options).
289290
For(&infrav1exp.OCIManagedCluster{}).
290291
WithEventFilter(predicates.ResourceNotPaused(log)). // don't queue reconcile if resource is paused
291292
// watch OCIManagedControlPlane resources

exp/controllers/ocimanagedcluster_controlplane_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func (r *OCIManagedClusterControlPlaneReconciler) SetupWithManager(ctx context.C
252252
log := ctrl.LoggerFrom(ctx)
253253
ociManagedClusterMapper, err := OCIManagedClusterToOCIManagedControlPlaneMapper(ctx, r.Client, log)
254254
c, err := ctrl.NewControllerManagedBy(mgr).
255+
WithOptions(options).
255256
For(&infrav1exp.OCIManagedControlPlane{}).
256257
Watches(
257258
&source.Kind{Type: &infrav1exp.OCIManagedCluster{}},

main.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ var (
5151
logOptions = logs.NewOptions()
5252
webhookPort int
5353
webhookCertDir string
54+
55+
// Flags for reconciler concurrency
56+
ociClusterConcurrency int
57+
ociMachineConcurrency int
58+
ociMachinePoolConcurrency int
5459
)
5560

5661
const (
@@ -88,6 +93,24 @@ func main() {
8893
)
8994
flag.StringVar(&webhookCertDir, "webhook-cert-dir", "/tmp/k8s-webhook-server/serving-certs/",
9095
"Webhook cert dir, only used when webhook-port is specified.")
96+
flag.IntVar(
97+
&ociClusterConcurrency,
98+
"ocicluster-concurrency",
99+
5,
100+
"Number of OciClusters to process simultaneously",
101+
)
102+
flag.IntVar(
103+
&ociMachineConcurrency,
104+
"ocimachine-concurrency",
105+
10,
106+
"Number of OciMachines to process simultaneously",
107+
)
108+
flag.IntVar(
109+
&ociMachinePoolConcurrency,
110+
"ocimachinepool-concurrency",
111+
5,
112+
"Number of OciMachinePools to process simultaneously",
113+
)
91114

92115
opts := zap.Options{
93116
Development: true,
@@ -166,7 +189,7 @@ func main() {
166189
Region: region,
167190
ClientProvider: clientProvider,
168191
Recorder: mgr.GetEventRecorderFor("ocicluster-controller"),
169-
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
192+
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: ociClusterConcurrency}); err != nil {
170193
setupLog.Error(err, "unable to create controller", "controller", scope.OCIClusterKind)
171194
os.Exit(1)
172195
}
@@ -177,7 +200,7 @@ func main() {
177200
ClientProvider: clientProvider,
178201
Region: region,
179202
Recorder: mgr.GetEventRecorderFor("ocimachine-controller"),
180-
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
203+
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: ociMachineConcurrency}); err != nil {
181204
setupLog.Error(err, "unable to create controller", "controller", scope.OCIMachineKind)
182205
os.Exit(1)
183206
}
@@ -191,7 +214,7 @@ func main() {
191214
ClientProvider: clientProvider,
192215
Recorder: mgr.GetEventRecorderFor("ocimachinepool-controller"),
193216
Region: region,
194-
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
217+
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: ociMachinePoolConcurrency}); err != nil {
195218
setupLog.Error(err, "unable to create controller", "controller", scope.OCIMachinePoolKind)
196219
os.Exit(1)
197220
}
@@ -205,7 +228,7 @@ func main() {
205228
Region: region,
206229
ClientProvider: clientProvider,
207230
Recorder: mgr.GetEventRecorderFor("ocimanagedmachinepool-controller"),
208-
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
231+
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: ociMachinePoolConcurrency}); err != nil {
209232
setupLog.Error(err, "unable to create controller", "controller", scope.OCIManagedMachinePoolKind)
210233
os.Exit(1)
211234
}
@@ -216,7 +239,7 @@ func main() {
216239
Region: region,
217240
ClientProvider: clientProvider,
218241
Recorder: mgr.GetEventRecorderFor("ocimanagedcluster-controller"),
219-
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
242+
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: ociClusterConcurrency}); err != nil {
220243
setupLog.Error(err, "unable to create controller", "controller", scope.OCIManagedClusterKind)
221244
os.Exit(1)
222245
}
@@ -227,7 +250,7 @@ func main() {
227250
Region: region,
228251
ClientProvider: clientProvider,
229252
Recorder: mgr.GetEventRecorderFor("ocimanagedclustercontrolplane-controller"),
230-
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
253+
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: ociClusterConcurrency}); err != nil {
231254
setupLog.Error(err, "unable to create controller", "controller", scope.OCIManagedClusterControlPlaneKind)
232255
os.Exit(1)
233256
}

0 commit comments

Comments
 (0)