Skip to content

Commit

Permalink
controller: handle resources in concurrent mode
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm committed Jan 6, 2025
1 parent 85a2be2 commit e38dd74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions internal/controller/atlasmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ import (
"fmt"
"io"
"net/url"
"runtime"
"strings"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/predicate"

"ariga.io/atlas-go-sdk/atlasexec"
Expand All @@ -55,7 +57,7 @@ type (
// AtlasMigrationReconciler reconciles a AtlasMigration object
AtlasMigrationReconciler struct {
client.Client
scheme *runtime.Scheme
scheme *k8sruntime.Scheme
atlasClient AtlasExecFn
configMapWatcher *watch.ResourceWatcher
secretWatcher *watch.ResourceWatcher
Expand Down Expand Up @@ -204,6 +206,9 @@ func (r *AtlasMigrationReconciler) storeDirState(ctx context.Context, obj client
// SetupWithManager sets up the controller with the Manager.
func (r *AtlasMigrationReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
WithOptions(controller.Options{
MaxConcurrentReconciles: runtime.NumCPU(),
}).
For(&dbv1alpha1.AtlasMigration{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Owns(&dbv1alpha1.AtlasMigration{}).
Watches(&corev1.Secret{}, r.secretWatcher).
Expand Down
9 changes: 7 additions & 2 deletions internal/controller/atlasschema_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ import (
"net/url"
"path"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"

Expand All @@ -60,7 +62,7 @@ type (
AtlasSchemaReconciler struct {
client.Client
atlasClient AtlasExecFn
scheme *runtime.Scheme
scheme *k8sruntime.Scheme
configMapWatcher *watch.ResourceWatcher
secretWatcher *watch.ResourceWatcher
recorder record.EventRecorder
Expand Down Expand Up @@ -485,6 +487,9 @@ func (r *AtlasSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// SetupWithManager sets up the controller with the Manager.
func (r *AtlasSchemaReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
WithOptions(controller.Options{
MaxConcurrentReconciles: runtime.NumCPU(),
}).
For(&dbv1alpha1.AtlasSchema{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Owns(&dbv1alpha1.AtlasSchema{}).
Watches(&corev1.ConfigMap{}, r.configMapWatcher).
Expand Down

0 comments on commit e38dd74

Please sign in to comment.