diff --git a/chart/values.yaml b/chart/values.yaml index b458685d..e42f2b33 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -6,7 +6,8 @@ env: DENY_LIST: "default,kube-system" # Comma-separated list of namespaces to ignore RECONCILE_WAIT: "10s" # Reconciliation delay WATCH_NAMESPACE: "" # Namespace to watch or empty string to watch all namespaces, To watch multiple namespaces add , into string. Ex: WATCH_NAMESPACE: "ns1,ns2,ns3" - + #MAX_CONCURRENT_RECONCILES:: "" # MaxConcurrentReconciles is the maximum number of concurrent Reconciles which can be run. + replicaCount: 1 image: diff --git a/controllers/druid/druid_controller.go b/controllers/druid/druid_controller.go index fe85c165..d0b4ae1d 100644 --- a/controllers/druid/druid_controller.go +++ b/controllers/druid/druid_controller.go @@ -12,6 +12,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/reconcile" druidv1alpha1 "github.com/druid-io/druid-operator/apis/druid/v1alpha1" @@ -74,6 +75,9 @@ func (r *DruidReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&druidv1alpha1.Druid{}). WithEventFilter(GenericPredicates{}). + WithOptions(controller.Options{ + MaxConcurrentReconciles: getMaxConcurrentReconciles(), + }). Complete(r) } @@ -91,3 +95,13 @@ func LookupReconcileTime() time.Duration { return v } } + +func getMaxConcurrentReconciles() int { + var MaxConcurrentReconciles = "MAX_CONCURRENT_RECONCILES" + + nu, found := os.LookupEnv(MaxConcurrentReconciles) + if !found { + return 1 + } + return Str2Int(nu) +} diff --git a/controllers/druid/util.go b/controllers/druid/util.go index 41697946..b30c2e48 100644 --- a/controllers/druid/util.go +++ b/controllers/druid/util.go @@ -3,6 +3,7 @@ package druid import ( "os" "reflect" + "strconv" "strings" ) @@ -66,3 +67,13 @@ func boolFalse() *bool { bool := false return &bool } + +// to be used in max concurrent reconciles only +// defaulting to return 1 +func Str2Int(s string) int { + i, err := strconv.Atoi(s) + if err != nil { + return 1 + } + return i +}