@@ -12,6 +12,7 @@ import (
1212 "github.com/cobaltcore-dev/cortex/api/v1alpha1"
1313 "github.com/cobaltcore-dev/cortex/internal/knowledge/datasources"
1414 "github.com/cobaltcore-dev/cortex/internal/knowledge/db"
15+ "github.com/cobaltcore-dev/cortex/pkg/conf"
1516 "github.com/cobaltcore-dev/cortex/pkg/keystone"
1617 "github.com/cobaltcore-dev/cortex/pkg/multicluster"
1718 "github.com/cobaltcore-dev/cortex/pkg/sso"
@@ -24,20 +25,25 @@ import (
2425 "k8s.io/apimachinery/pkg/runtime"
2526 ctrl "sigs.k8s.io/controller-runtime"
2627 "sigs.k8s.io/controller-runtime/pkg/client"
28+ "sigs.k8s.io/controller-runtime/pkg/controller"
2729 "sigs.k8s.io/controller-runtime/pkg/event"
2830 "sigs.k8s.io/controller-runtime/pkg/handler"
2931 logf "sigs.k8s.io/controller-runtime/pkg/log"
3032 "sigs.k8s.io/controller-runtime/pkg/manager"
3133 "sigs.k8s.io/controller-runtime/pkg/predicate"
34+ "sigs.k8s.io/controller-runtime/pkg/reconcile"
3235)
3336
34- type OpenStackDatasourceReconcilerConfig struct {
37+ type config struct {
3538 // The controller will only touch resources with this scheduling domain.
3639 SchedulingDomain v1alpha1.SchedulingDomain `json:"schedulingDomain"`
3740 // Secret ref to keystone credentials stored in a k8s secret.
3841 KeystoneSecretRef corev1.SecretReference `json:"keystoneSecretRef"`
3942 // Secret ref to SSO credentials stored in a k8s secret, if applicable.
4043 SSOSecretRef * corev1.SecretReference `json:"ssoSecretRef"`
44+ // The number of parallel reconciles to allow for the controller.
45+ // By default, this will be set to 1.
46+ ParallelReconciles * int `json:"openstackDatasourceControllerParallelReconciles,omitempty"`
4147}
4248
4349type Syncer interface {
@@ -54,8 +60,9 @@ type OpenStackDatasourceReconciler struct {
5460 Scheme * runtime.Scheme
5561 // Datasources monitor.
5662 Monitor datasources.Monitor
63+
5764 // Config for the reconciler.
58- Conf OpenStackDatasourceReconcilerConfig
65+ conf config
5966}
6067
6168// Reconcile is part of the main kubernetes reconciliation loop which aims to
@@ -281,16 +288,21 @@ func predicateIgnoreStatusConditions() predicate.Predicate {
281288}
282289
283290func (r * OpenStackDatasourceReconciler ) SetupWithManager (mgr manager.Manager , mcl * multicluster.Client ) error {
291+ var err error
292+ r .conf , err = conf .GetConfig [config ]()
293+ if err != nil {
294+ return err
295+ }
284296 bldr := multicluster .BuildController (mcl , mgr )
285297 // Watch datasource changes across all clusters.
286- bldr , err : = bldr .WatchesMulticluster (
298+ bldr , err = bldr .WatchesMulticluster (
287299 & v1alpha1.Datasource {},
288300 & handler.EnqueueRequestForObject {},
289301 predicate .NewPredicateFuncs (func (obj client.Object ) bool {
290302 // Only react to datasources matching the operator.
291303 ds := obj .(* v1alpha1.Datasource )
292304 // Ignore all datasources outside our scheduling domain.
293- if ds .Spec .SchedulingDomain != r .Conf .SchedulingDomain {
305+ if ds .Spec .SchedulingDomain != r .conf .SchedulingDomain {
294306 return false
295307 }
296308 // Ignore all datasources that are not of type openstack.
@@ -305,5 +317,14 @@ func (r *OpenStackDatasourceReconciler) SetupWithManager(mgr manager.Manager, mc
305317 return err
306318 }
307319 return bldr .Named ("cortex-openstack-datasource" ).
320+ WithOptions (controller.TypedOptions [reconcile.Request ]{
321+ // Allow parallel reconciles if configured, otherwise default to 1.
322+ MaxConcurrentReconciles : func () int {
323+ if r .conf .ParallelReconciles != nil {
324+ return * r .conf .ParallelReconciles
325+ }
326+ return 1
327+ }(),
328+ }).
308329 Complete (r )
309330}
0 commit comments