Skip to content

Commit

Permalink
Merge pull request #296 from chrisdoherty4/feature/concurrent-cluster…
Browse files Browse the repository at this point in the history
…-reconciliation

Concurrently reconcile CloudStackCluster resources
  • Loading branch information
k8s-ci-robot authored Jul 20, 2023
2 parents 41c2908 + 0220e48 commit b860d9f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ spec:
- /manager
args:
- --leader-elect
- --cloudstackcluster-concurrency=${CAPC_CLOUDSTACKCLUSTER_CONCURRENCY:=10}
- --cloudstackmachine-concurrency=${CAPC_CLOUDSTACKMACHINE_CONCURRENCY:=10}
image: controller:latest
name: manager
Expand Down
10 changes: 7 additions & 3 deletions controllers/cloudstackcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"reflect"

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand Down Expand Up @@ -129,7 +130,8 @@ func (r *CloudStackClusterReconciliationRunner) SetFailureDomainsStatusMap() (ct
for _, fdSpec := range r.ReconciliationSubject.Spec.FailureDomains {
metaHashName := infrav1.FailureDomainHashedMetaName(fdSpec.Name, r.CAPICluster.Name)
r.ReconciliationSubject.Status.FailureDomains[fdSpec.Name] = clusterv1.FailureDomainSpec{
ControlPlane: true, Attributes: map[string]string{"MetaHashName": metaHashName}}
ControlPlane: true, Attributes: map[string]string{"MetaHashName": metaHashName},
}
}
return ctrl.Result{}, nil
}
Expand All @@ -153,8 +155,9 @@ func (r *CloudStackClusterReconciliationRunner) ReconcileDelete() (ctrl.Result,
}

// Called in main, this registers the cluster reconciler to the CAPI controller manager.
func (reconciler *CloudStackClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {
func (reconciler *CloudStackClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opts controller.Options) error {
controller, err := ctrl.NewControllerManagedBy(mgr).
WithOptions(opts).
For(&infrav1.CloudStackCluster{}).
WithEventFilter(
predicate.Funcs{
Expand Down Expand Up @@ -194,6 +197,7 @@ func (reconciler *CloudStackClusterReconciler) SetupWithManager(ctx context.Cont
return oldCluster.Spec.Paused && !newCluster.Spec.Paused
},
DeleteFunc: func(e event.DeleteEvent) bool { return false },
CreateFunc: func(e event.CreateEvent) bool { return false }})
CreateFunc: func(e event.CreateEvent) bool { return false },
})
return errors.Wrap(err, "building CloudStackCluster controller")
}
7 changes: 4 additions & 3 deletions controllers/cloudstackcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ import (
"sigs.k8s.io/cluster-api-provider-cloudstack/controllers"
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("CloudStackClusterReconciler", func() {
Context("With k8s like test environment.", func() {
BeforeEach(func() {
SetupTestEnvironment() // Must happen before setting up managers/reconcilers.
Ω(ClusterReconciler.SetupWithManager(ctx, k8sManager)).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)).Should(Succeed()) // Register CloudStack FailureDomainReconciler.
})

It("Should create a CloudStackFailureDomain.", func() {
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type managerOpts struct {
WatchFilterValue string
CertDir string

CloudStackClusterConcurrency int
CloudStackMachineConcurrency int
}

Expand Down Expand Up @@ -120,6 +121,12 @@ func setFlags() *managerOpts {
"webhook-cert-dir",
"/tmp/k8s-webhook-server/serving-certs/",
"Specify the directory where webhooks will get tls certificates.")
flag.IntVar(
&opts.CloudStackClusterConcurrency,
"cloudstackcluster-concurrency",
10,
"Maximum concurrent reconciles for CloudStackCluster resources",
)
flag.IntVar(
&opts.CloudStackMachineConcurrency,
"cloudstackmachine-concurrency",
Expand Down Expand Up @@ -203,7 +210,7 @@ func main() {
}

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

0 comments on commit b860d9f

Please sign in to comment.