Skip to content

Commit

Permalink
max reconciles workerqueue (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdheipSingh authored Aug 23, 2022
1 parent 264bcfa commit 82753fe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions controllers/druid/druid_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}
11 changes: 11 additions & 0 deletions controllers/druid/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package druid
import (
"os"
"reflect"
"strconv"
"strings"
)

Expand Down Expand Up @@ -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
}

0 comments on commit 82753fe

Please sign in to comment.