Skip to content

Commit e38dd74

Browse files
committed
controller: handle resources in concurrent mode
1 parent 85a2be2 commit e38dd74

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

internal/controller/atlasmigration_controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ import (
2424
"fmt"
2525
"io"
2626
"net/url"
27+
"runtime"
2728
"strings"
2829

2930
corev1 "k8s.io/api/core/v1"
3031
apierrors "k8s.io/apimachinery/pkg/api/errors"
3132
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32-
"k8s.io/apimachinery/pkg/runtime"
33+
k8sruntime "k8s.io/apimachinery/pkg/runtime"
3334
"k8s.io/apimachinery/pkg/types"
3435
"k8s.io/client-go/tools/record"
3536
ctrl "sigs.k8s.io/controller-runtime"
3637
"sigs.k8s.io/controller-runtime/pkg/builder"
3738
"sigs.k8s.io/controller-runtime/pkg/client"
39+
"sigs.k8s.io/controller-runtime/pkg/controller"
3840
"sigs.k8s.io/controller-runtime/pkg/predicate"
3941

4042
"ariga.io/atlas-go-sdk/atlasexec"
@@ -55,7 +57,7 @@ type (
5557
// AtlasMigrationReconciler reconciles a AtlasMigration object
5658
AtlasMigrationReconciler struct {
5759
client.Client
58-
scheme *runtime.Scheme
60+
scheme *k8sruntime.Scheme
5961
atlasClient AtlasExecFn
6062
configMapWatcher *watch.ResourceWatcher
6163
secretWatcher *watch.ResourceWatcher
@@ -204,6 +206,9 @@ func (r *AtlasMigrationReconciler) storeDirState(ctx context.Context, obj client
204206
// SetupWithManager sets up the controller with the Manager.
205207
func (r *AtlasMigrationReconciler) SetupWithManager(mgr ctrl.Manager) error {
206208
return ctrl.NewControllerManagedBy(mgr).
209+
WithOptions(controller.Options{
210+
MaxConcurrentReconciles: runtime.NumCPU(),
211+
}).
207212
For(&dbv1alpha1.AtlasMigration{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
208213
Owns(&dbv1alpha1.AtlasMigration{}).
209214
Watches(&corev1.Secret{}, r.secretWatcher).

internal/controller/atlasschema_controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ import (
2525
"net/url"
2626
"path"
2727
"path/filepath"
28+
"runtime"
2829
"strconv"
2930
"strings"
3031
"time"
3132

3233
corev1 "k8s.io/api/core/v1"
33-
"k8s.io/apimachinery/pkg/runtime"
34+
k8sruntime "k8s.io/apimachinery/pkg/runtime"
3435
"k8s.io/apimachinery/pkg/types"
3536
"k8s.io/client-go/tools/record"
3637
ctrl "sigs.k8s.io/controller-runtime"
3738
"sigs.k8s.io/controller-runtime/pkg/builder"
3839
"sigs.k8s.io/controller-runtime/pkg/client"
40+
"sigs.k8s.io/controller-runtime/pkg/controller"
3941
"sigs.k8s.io/controller-runtime/pkg/log"
4042
"sigs.k8s.io/controller-runtime/pkg/predicate"
4143

@@ -60,7 +62,7 @@ type (
6062
AtlasSchemaReconciler struct {
6163
client.Client
6264
atlasClient AtlasExecFn
63-
scheme *runtime.Scheme
65+
scheme *k8sruntime.Scheme
6466
configMapWatcher *watch.ResourceWatcher
6567
secretWatcher *watch.ResourceWatcher
6668
recorder record.EventRecorder
@@ -485,6 +487,9 @@ func (r *AtlasSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
485487
// SetupWithManager sets up the controller with the Manager.
486488
func (r *AtlasSchemaReconciler) SetupWithManager(mgr ctrl.Manager) error {
487489
return ctrl.NewControllerManagedBy(mgr).
490+
WithOptions(controller.Options{
491+
MaxConcurrentReconciles: runtime.NumCPU(),
492+
}).
488493
For(&dbv1alpha1.AtlasSchema{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
489494
Owns(&dbv1alpha1.AtlasSchema{}).
490495
Watches(&corev1.ConfigMap{}, r.configMapWatcher).

0 commit comments

Comments
 (0)