Skip to content

Commit

Permalink
Merge pull request #26 from georgekuruvillak/worker_threads
Browse files Browse the repository at this point in the history
Added configurable worker count.
  • Loading branch information
Amshuman K R authored Mar 18, 2020
2 parents 460d91a + 0fb24f2 commit c552891
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions controllers/etcd_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/yaml"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"

druidv1alpha1 "github.com/gardener/etcd-druid/api/v1alpha1"
Expand Down Expand Up @@ -988,9 +989,10 @@ func convertConditionsToEtcd(condition *appsv1.StatefulSetCondition) druidv1alph
}

// SetupWithManager sets up manager with a new controller and r as the reconcile.Reconciler
func (r *EtcdReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&druidv1alpha1.Etcd{}).
func (r *EtcdReconciler) SetupWithManager(mgr ctrl.Manager, workers int) error {
return ctrl.NewControllerManagedBy(mgr).WithOptions(controller.Options{
MaxConcurrentReconciles: workers,
}).For(&druidv1alpha1.Etcd{}).
Owns(&appsv1.StatefulSet{}).
Complete(r)
}
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func init() {
func main() {
var metricsAddr string
var enableLeaderElection bool
var workers int
flag.IntVar(&workers, "workers", 3, "Number of worker threads.")
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
Expand All @@ -67,7 +69,7 @@ func main() {
setupLog.Error(err, "unable to initialize controller with image vector")
os.Exit(1)
}
err = ec.SetupWithManager(mgr)
err = ec.SetupWithManager(mgr, workers)
if err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Etcd")
os.Exit(1)
Expand Down

0 comments on commit c552891

Please sign in to comment.