Skip to content

Commit c432710

Browse files
committed
controller: handle resources in concurrent mode
1 parent 61ffeb9 commit c432710

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

internal/controller/atlasmigration_controller.go

+7-2
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"
@@ -53,7 +55,7 @@ type (
5355
// AtlasMigrationReconciler reconciles a AtlasMigration object
5456
AtlasMigrationReconciler struct {
5557
client.Client
56-
scheme *runtime.Scheme
58+
scheme *k8sruntime.Scheme
5759
atlasClient AtlasExecFn
5860
configMapWatcher *watch.ResourceWatcher
5961
secretWatcher *watch.ResourceWatcher
@@ -200,6 +202,9 @@ func (r *AtlasMigrationReconciler) storeDirState(ctx context.Context, obj client
200202
// SetupWithManager sets up the controller with the Manager.
201203
func (r *AtlasMigrationReconciler) SetupWithManager(mgr ctrl.Manager) error {
202204
return ctrl.NewControllerManagedBy(mgr).
205+
WithOptions(controller.Options{
206+
MaxConcurrentReconciles: runtime.NumCPU(),
207+
}).
203208
For(&dbv1alpha1.AtlasMigration{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
204209
Owns(&dbv1alpha1.AtlasMigration{}).
205210
Watches(&corev1.Secret{}, r.secretWatcher).

internal/controller/atlasschema_controller.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@ import (
2323
"io"
2424
"net/url"
2525
"path/filepath"
26+
"runtime"
2627
"strconv"
2728
"strings"
2829
"time"
2930

3031
corev1 "k8s.io/api/core/v1"
31-
"k8s.io/apimachinery/pkg/runtime"
32+
k8sruntime "k8s.io/apimachinery/pkg/runtime"
3233
"k8s.io/apimachinery/pkg/types"
3334
"k8s.io/client-go/tools/record"
3435
ctrl "sigs.k8s.io/controller-runtime"
3536
"sigs.k8s.io/controller-runtime/pkg/builder"
3637
"sigs.k8s.io/controller-runtime/pkg/client"
38+
"sigs.k8s.io/controller-runtime/pkg/controller"
3739
"sigs.k8s.io/controller-runtime/pkg/log"
3840
"sigs.k8s.io/controller-runtime/pkg/predicate"
3941

@@ -56,7 +58,7 @@ type (
5658
AtlasSchemaReconciler struct {
5759
client.Client
5860
atlasClient AtlasExecFn
59-
scheme *runtime.Scheme
61+
scheme *k8sruntime.Scheme
6062
configMapWatcher *watch.ResourceWatcher
6163
secretWatcher *watch.ResourceWatcher
6264
recorder record.EventRecorder
@@ -428,6 +430,9 @@ func (r *AtlasSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
428430
// SetupWithManager sets up the controller with the Manager.
429431
func (r *AtlasSchemaReconciler) SetupWithManager(mgr ctrl.Manager) error {
430432
return ctrl.NewControllerManagedBy(mgr).
433+
WithOptions(controller.Options{
434+
MaxConcurrentReconciles: runtime.NumCPU(),
435+
}).
431436
For(&dbv1alpha1.AtlasSchema{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
432437
Owns(&dbv1alpha1.AtlasSchema{}).
433438
Watches(&corev1.ConfigMap{}, r.configMapWatcher).

0 commit comments

Comments
 (0)