Controller-runtime: How to specify worker count when using kubebuilder

Created on 24 May 2020  路  4Comments  路  Source: kubernetes-sigs/controller-runtime

Hi,

I noticed that the worker count is 1

2020-05-24T11:30:32.287+0800    INFO    controller-runtime.controllercontroller/controller.go:154   Starting workers    {"controller": "test", "worker count": 1}
2020-05-24T11:30:32.287+0800    INFO    controller-runtime.controllercontroller/controller.go:154   Starting workers    {"controller": "test2", "worker count": 1}

And I found there is no way to set MaxConcurrentReconciles. Could you help me to know how to set it. Thanks.

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
        Scheme:             scheme,
        MetricsBindAddress: metricsAddr,
        LeaderElection:     enableLeaderElection,
    })
    if err != nil {
        setupLog.Error(err, "unable to start manager")
        os.Exit(1)
    }

    const jobPollInterval = "5s"

    err = trainingjob.
        NewTrainingJobReconciler(
            mgr.GetClient(),
            ctrl.Log.WithName("controllers").WithName("TrainingJob"),
            parseDurationOrPanic(jobPollInterval)).
        SetupWithManager(mgr)
    if err != nil {
        setupLog.Error(err, "unable to create controller", "controller", "TrainingJob")
        os.Exit(1)
    }
kinsupport

Most helpful comment

@cheyang you can define MaxConcurrentReconciles using WithOptions(...) inside SetupWithManager call as

return ctrl.NewControllerManagedBy(mgr).
        For(&batch.CronJob{}).
        Owns(&kbatch.Job{}).
                WithOptions(...).
        Complete(r)

All 4 comments

@cheyang you can define MaxConcurrentReconciles using WithOptions(...) inside SetupWithManager call as

return ctrl.NewControllerManagedBy(mgr).
        For(&batch.CronJob{}).
        Owns(&kbatch.Job{}).
                WithOptions(...).
        Complete(r)

/milestone Next
/triage support

Closing given that the answer from @dmvolod is correct, feel free to reopen if necessary.
/close

@vincepri: Closing this issue.

In response to this:

/milestone Next
/triage support

Closing given that the answer from @dmvolod is correct, feel free to reopen if necessary.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

There is an example for setting MaxConcurrentReconciles here:
https://sdk.operatorframework.io/docs/building-operators/golang/tutorial/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

christopherhein picture christopherhein  路  8Comments

raffaelespazzoli picture raffaelespazzoli  路  11Comments

billcchung picture billcchung  路  7Comments

akutz picture akutz  路  5Comments

steven-zou picture steven-zou  路  5Comments