Skip to content

Commit b860d9f

Browse files
authored
Merge pull request #296 from chrisdoherty4/feature/concurrent-cluster-reconciliation
Concurrently reconcile CloudStackCluster resources
2 parents 41c2908 + 0220e48 commit b860d9f

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

config/manager/manager.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ spec:
2222
- /manager
2323
args:
2424
- --leader-elect
25+
- --cloudstackcluster-concurrency=${CAPC_CLOUDSTACKCLUSTER_CONCURRENCY:=10}
2526
- --cloudstackmachine-concurrency=${CAPC_CLOUDSTACKMACHINE_CONCURRENCY:=10}
2627
image: controller:latest
2728
name: manager

controllers/cloudstackcluster_controller.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"reflect"
2323

2424
ctrl "sigs.k8s.io/controller-runtime"
25+
"sigs.k8s.io/controller-runtime/pkg/controller"
2526
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2627
"sigs.k8s.io/controller-runtime/pkg/event"
2728
"sigs.k8s.io/controller-runtime/pkg/handler"
@@ -129,7 +130,8 @@ func (r *CloudStackClusterReconciliationRunner) SetFailureDomainsStatusMap() (ct
129130
for _, fdSpec := range r.ReconciliationSubject.Spec.FailureDomains {
130131
metaHashName := infrav1.FailureDomainHashedMetaName(fdSpec.Name, r.CAPICluster.Name)
131132
r.ReconciliationSubject.Status.FailureDomains[fdSpec.Name] = clusterv1.FailureDomainSpec{
132-
ControlPlane: true, Attributes: map[string]string{"MetaHashName": metaHashName}}
133+
ControlPlane: true, Attributes: map[string]string{"MetaHashName": metaHashName},
134+
}
133135
}
134136
return ctrl.Result{}, nil
135137
}
@@ -153,8 +155,9 @@ func (r *CloudStackClusterReconciliationRunner) ReconcileDelete() (ctrl.Result,
153155
}
154156

155157
// Called in main, this registers the cluster reconciler to the CAPI controller manager.
156-
func (reconciler *CloudStackClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {
158+
func (reconciler *CloudStackClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opts controller.Options) error {
157159
controller, err := ctrl.NewControllerManagedBy(mgr).
160+
WithOptions(opts).
158161
For(&infrav1.CloudStackCluster{}).
159162
WithEventFilter(
160163
predicate.Funcs{
@@ -194,6 +197,7 @@ func (reconciler *CloudStackClusterReconciler) SetupWithManager(ctx context.Cont
194197
return oldCluster.Spec.Paused && !newCluster.Spec.Paused
195198
},
196199
DeleteFunc: func(e event.DeleteEvent) bool { return false },
197-
CreateFunc: func(e event.CreateEvent) bool { return false }})
200+
CreateFunc: func(e event.CreateEvent) bool { return false },
201+
})
198202
return errors.Wrap(err, "building CloudStackCluster controller")
199203
}

controllers/cloudstackcluster_controller_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ import (
2424
"sigs.k8s.io/cluster-api-provider-cloudstack/controllers"
2525
dummies "sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies/v1beta3"
2626
"sigs.k8s.io/controller-runtime/pkg/client"
27+
"sigs.k8s.io/controller-runtime/pkg/controller"
2728
)
2829

2930
var _ = Describe("CloudStackClusterReconciler", func() {
3031
Context("With k8s like test environment.", func() {
3132
BeforeEach(func() {
32-
SetupTestEnvironment() // Must happen before setting up managers/reconcilers.
33-
Ω(ClusterReconciler.SetupWithManager(ctx, k8sManager)).Should(Succeed()) // Register CloudStack ClusterReconciler.
34-
Ω(FailureDomainReconciler.SetupWithManager(k8sManager)).Should(Succeed()) // Register CloudStack FailureDomainReconciler.
33+
SetupTestEnvironment() // Must happen before setting up managers/reconcilers.
34+
Ω(ClusterReconciler.SetupWithManager(ctx, k8sManager, controller.Options{})).Should(Succeed()) // Register CloudStack ClusterReconciler.
35+
Ω(FailureDomainReconciler.SetupWithManager(k8sManager)).Should(Succeed()) // Register CloudStack FailureDomainReconciler.
3536
})
3637

3738
It("Should create a CloudStackFailureDomain.", func() {

main.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type managerOpts struct {
7575
WatchFilterValue string
7676
CertDir string
7777

78+
CloudStackClusterConcurrency int
7879
CloudStackMachineConcurrency int
7980
}
8081

@@ -120,6 +121,12 @@ func setFlags() *managerOpts {
120121
"webhook-cert-dir",
121122
"/tmp/k8s-webhook-server/serving-certs/",
122123
"Specify the directory where webhooks will get tls certificates.")
124+
flag.IntVar(
125+
&opts.CloudStackClusterConcurrency,
126+
"cloudstackcluster-concurrency",
127+
10,
128+
"Maximum concurrent reconciles for CloudStackCluster resources",
129+
)
123130
flag.IntVar(
124131
&opts.CloudStackMachineConcurrency,
125132
"cloudstackmachine-concurrency",
@@ -203,7 +210,7 @@ func main() {
203210
}
204211

205212
func setupReconcilers(ctx context.Context, base utils.ReconcilerBase, opts managerOpts, mgr manager.Manager) {
206-
if err := (&controllers.CloudStackClusterReconciler{ReconcilerBase: base}).SetupWithManager(ctx, mgr); err != nil {
213+
if err := (&controllers.CloudStackClusterReconciler{ReconcilerBase: base}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: opts.CloudStackClusterConcurrency}); err != nil {
207214
setupLog.Error(err, "unable to create controller", "controller", "CloudStackCluster")
208215
os.Exit(1)
209216
}

0 commit comments

Comments
 (0)