Skip to content

Commit

Permalink
Merge pull request #341 from vignesh-goutham/increase-workers
Browse files Browse the repository at this point in the history
Affinity group and failure domain controllers with multiple workers
  • Loading branch information
k8s-ci-robot authored Feb 17, 2024
2 parents a77afd3 + 9f30e7f commit d597e80
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
4 changes: 3 additions & 1 deletion controllers/cloudstackaffinitygroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
Expand Down Expand Up @@ -94,8 +95,9 @@ func (r *CloudStackAGReconciliationRunner) ReconcileDelete() (ctrl.Result, error
}

// SetupWithManager sets up the controller with the Manager.
func (reconciler *CloudStackAffinityGroupReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (reconciler *CloudStackAffinityGroupReconciler) SetupWithManager(mgr ctrl.Manager, opts controller.Options) error {
return ctrl.NewControllerManagedBy(mgr).
WithOptions(opts).
For(&infrav1.CloudStackAffinityGroup{}).
Complete(reconciler)
}
3 changes: 2 additions & 1 deletion controllers/cloudstackaffinitygroup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ import (
"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/cloud"
dummies "sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies/v1beta3"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
)

var _ = Describe("CloudStackAffinityGroupReconciler", func() {
BeforeEach(func() {
SetupTestEnvironment() // Must happen before setting up managers/reconcilers.
dummies.SetDummyVars()
Ω(AffinityGReconciler.SetupWithManager(k8sManager)).Should(Succeed()) // Register CloudStack AffinityGReconciler.
Ω(AffinityGReconciler.SetupWithManager(k8sManager, controller.Options{})).Should(Succeed()) // Register CloudStack AffinityGReconciler.
})

It("Should patch back the affinity group as ready after calling GetOrCreateAffinityGroup.", func() {
Expand Down
6 changes: 3 additions & 3 deletions controllers/cloudstackcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (
var _ = Describe("CloudStackClusterReconciler", func() {
Context("With k8s like test environment.", func() {
BeforeEach(func() {
SetupTestEnvironment() // Must happen before setting up managers/reconcilers.
Ω(ClusterReconciler.SetupWithManager(ctx, k8sManager, controller.Options{})).Should(Succeed()) // Register CloudStack ClusterReconciler.
Ω(FailureDomainReconciler.SetupWithManager(k8sManager)).Should(Succeed()) // Register CloudStack FailureDomainReconciler.
SetupTestEnvironment() // Must happen before setting up managers/reconcilers.
Ω(ClusterReconciler.SetupWithManager(ctx, k8sManager, controller.Options{})).Should(Succeed()) // Register CloudStack ClusterReconciler.
Ω(FailureDomainReconciler.SetupWithManager(k8sManager, controller.Options{})).Should(Succeed()) // Register CloudStack FailureDomainReconciler.
})

It("Should create a CloudStackFailureDomain.", func() {
Expand Down
9 changes: 6 additions & 3 deletions controllers/cloudstackfailuredomain_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
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/controller/controllerutil"
"sort"

Expand Down Expand Up @@ -263,7 +264,9 @@ func (r *CloudStackFailureDomainReconciliationRunner) RemoveFinalizer() (ctrl.Re
}

// SetupWithManager sets up the controller with the Manager.
func (reconciler *CloudStackFailureDomainReconciler) SetupWithManager(mgr ctrl.Manager) error {
_, err := ctrl.NewControllerManagedBy(mgr).For(&infrav1.CloudStackFailureDomain{}).Build(reconciler)
return err
func (reconciler *CloudStackFailureDomainReconciler) SetupWithManager(mgr ctrl.Manager, opts controller.Options) error {
return ctrl.NewControllerManagedBy(mgr).
WithOptions(opts).
For(&infrav1.CloudStackFailureDomain{}).
Complete(reconciler)
}
5 changes: 3 additions & 2 deletions controllers/cloudstackfailuredomain_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
)

var _ = Describe("CloudStackFailureDomainReconciler", func() {
Context("With k8s like test environment.", func() {
BeforeEach(func() {
dummies.SetDummyVars()
SetupTestEnvironment() // Must happen before setting up managers/reconcilers.
Ω(FailureDomainReconciler.SetupWithManager(k8sManager)).Should(Succeed()) // Register CloudStack FailureDomainReconciler.
SetupTestEnvironment() // Must happen before setting up managers/reconcilers.
Ω(FailureDomainReconciler.SetupWithManager(k8sManager, controller.Options{})).Should(Succeed()) // Register CloudStack FailureDomainReconciler.
// Modify failure domain name the same way the cluster controller would.
dummies.CSFailureDomain1.Name = dummies.CSFailureDomain1.Name + "-" + dummies.CSCluster.Name

Expand Down
22 changes: 18 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ type managerOpts struct {
WatchFilterValue string
CertDir string

CloudStackClusterConcurrency int
CloudStackMachineConcurrency int
CloudStackClusterConcurrency int
CloudStackMachineConcurrency int
CloudStackAffinityGroupConcurrency int
CloudStackFailureDomainConcurrency int
}

func setFlags() *managerOpts {
Expand Down Expand Up @@ -142,6 +144,18 @@ func setFlags() *managerOpts {
10,
"Maximum concurrent reconciles for CloudStackMachine resources",
)
flag.IntVar(
&opts.CloudStackAffinityGroupConcurrency,
"cloudstackaffinitygroup-concurrency",
5,
"Maximum concurrent reconciles for CloudStackAffinityGroup resources",
)
flag.IntVar(
&opts.CloudStackFailureDomainConcurrency,
"cloudstackfailuredomain-concurrency",
5,
"Maximum concurrent reconciles for CloudStackFailureDomain resources",
)

return opts
}
Expand Down Expand Up @@ -245,11 +259,11 @@ func setupReconcilers(ctx context.Context, base utils.ReconcilerBase, opts manag
setupLog.Error(err, "unable to create controller", "controller", "CloudStackIsoNetReconciler")
os.Exit(1)
}
if err := (&controllers.CloudStackAffinityGroupReconciler{ReconcilerBase: base}).SetupWithManager(mgr); err != nil {
if err := (&controllers.CloudStackAffinityGroupReconciler{ReconcilerBase: base}).SetupWithManager(mgr, controller.Options{MaxConcurrentReconciles: opts.CloudStackAffinityGroupConcurrency}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "CloudStackAffinityGroup")
os.Exit(1)
}
if err := (&controllers.CloudStackFailureDomainReconciler{ReconcilerBase: base}).SetupWithManager(mgr); err != nil {
if err := (&controllers.CloudStackFailureDomainReconciler{ReconcilerBase: base}).SetupWithManager(mgr, controller.Options{MaxConcurrentReconciles: opts.CloudStackFailureDomainConcurrency}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "CloudStackFailureDomain")
os.Exit(1)
}
Expand Down

0 comments on commit d597e80

Please sign in to comment.