Skip to content

Commit

Permalink
Merge pull request #1302 from ncdc/0.1/concurrency
Browse files Browse the repository at this point in the history
⚠️ [0.1] Cluster, machine controller: support concurrency
  • Loading branch information
k8s-ci-robot committed Aug 21, 2019
2 parents 961efcc + 28cc750 commit c80f6e5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
11 changes: 9 additions & 2 deletions cmd/example-provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ import (
)

func main() {
var (
clusterConcurrency int
machineConcurrency int
)

klog.InitFlags(nil)
flag.Set("logtostderr", "true")
flag.IntVar(&clusterConcurrency, "cluster-concurrency", 1, "Number of clusters to process simultaneously")
flag.IntVar(&machineConcurrency, "machine-concurrency", 1, "Number of machines to process simultaneously")
flag.Parse()

cfg := config.GetConfigOrDie()
Expand Down Expand Up @@ -65,8 +72,8 @@ func main() {
klog.Fatal(err)
}

capimachine.AddWithActuator(mgr, machineActuator)
capicluster.AddWithActuator(mgr, clusterActuator)
capimachine.AddWithActuator(mgr, machineActuator, machineConcurrency)
capicluster.AddWithActuator(mgr, clusterActuator, clusterConcurrency)

if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
klog.Fatalf("Failed to run manager: %v", err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ const deleteRequeueAfter = 5 * time.Second

var DefaultActuator Actuator

func AddWithActuator(mgr manager.Manager, actuator Actuator) error {
func AddWithActuator(mgr manager.Manager, actuator Actuator, concurrency int) error {
reconciler, err := newReconciler(mgr, actuator)
if err != nil {
return err
}

return add(mgr, reconciler)
return add(mgr, reconciler, concurrency)
}

// newReconciler returns a new reconcile.Reconciler
Expand All @@ -70,9 +70,9 @@ func newReconciler(mgr manager.Manager, actuator Actuator) (reconcile.Reconciler
}

// add adds a new Controller to mgr with r as the reconcile.Reconciler
func add(mgr manager.Manager, r reconcile.Reconciler) error {
func add(mgr manager.Manager, r reconcile.Reconciler, concurrency int) error {
// Create a new controller
c, err := controller.New("cluster-controller", mgr, controller.Options{Reconciler: r})
c, err := controller.New("cluster-controller", mgr, controller.Options{Reconciler: r, MaxConcurrentReconciles: concurrency})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/cluster/cluster_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestReconcile(t *testing.T) {
t.Fatalf("Couldn't create controller: %v", err)
}
recFn, requests := SetupTestReconcile(r)
if err := add(mgr, recFn); err != nil {
if err := add(mgr, recFn, 1); err != nil {
t.Fatalf("error adding controller to manager: %v", err)
}
defer close(StartTestManager(mgr, t))
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/machine/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const (

var DefaultActuator Actuator

func AddWithActuator(mgr manager.Manager, actuator Actuator) error {
return add(mgr, newReconciler(mgr, actuator))
func AddWithActuator(mgr manager.Manager, actuator Actuator, concurrency int) error {
return add(mgr, newReconciler(mgr, actuator), concurrency)
}

// newReconciler returns a new reconcile.Reconciler
Expand All @@ -66,9 +66,9 @@ func newReconciler(mgr manager.Manager, actuator Actuator) reconcile.Reconciler
}

// add adds a new Controller to mgr with r as the reconcile.Reconciler
func add(mgr manager.Manager, r reconcile.Reconciler) error {
func add(mgr manager.Manager, r reconcile.Reconciler, concurrency int) error {
// Create a new controller
c, err := controller.New("machine-controller", mgr, controller.Options{Reconciler: r})
c, err := controller.New("machine-controller", mgr, controller.Options{Reconciler: r, MaxConcurrentReconciles: concurrency})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/machine/machine_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestReconcile(t *testing.T) {

a := newTestActuator()
recFn, requests := SetupTestReconcile(newReconciler(mgr, a))
if err := add(mgr, recFn); err != nil {
if err := add(mgr, recFn, 1); err != nil {
t.Fatalf("error adding controller to manager: %v", err)
}
defer close(StartTestManager(mgr, t))
Expand Down

0 comments on commit c80f6e5

Please sign in to comment.