Skip to content

Commit 0a9a982

Browse files
committed
feat(controller): add parameter to fine-tune max concurrent reconciles
1 parent d1a998d commit 0a9a982

File tree

8 files changed

+27
-13
lines changed

8 files changed

+27
-13
lines changed

cmd/controllers/start.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func buildControllersStartCmd(app *burrito.App) *cobra.Command {
3535
cmd.Flags().DurationVar(&app.Config.Controller.Timers.WaitAction, "wait-action-period", defaultWaitActionTimer, "period between two runners when a layer is locked. Must end with s, m or h.")
3636
cmd.Flags().DurationVar(&app.Config.Controller.Timers.FailureGracePeriod, "failure-grace-period", defaultFailureGracePeriod, "initial time before retry, goes exponential function of number failure. Must end with s, m or h.")
3737
cmd.Flags().IntVar(&app.Config.Controller.TerraformMaxRetries, "terraform-max-retries", 5, "default number of retries for terraform actions (can be overriden in CRDs)")
38+
cmd.Flags().IntVar(&app.Config.Controller.MaxConcurrentReconciles, "max-concurrent-reconciles", 1, "maximum number of concurrent reconciles")
3839
cmd.Flags().BoolVar(&app.Config.Controller.LeaderElection.Enabled, "leader-election", true, "whether leader election is enabled or not, default to true")
3940
cmd.Flags().StringVar(&app.Config.Controller.LeaderElection.ID, "leader-election-id", "6d185457.terraform.padok.cloud", "lease id used for leader election")
4041
cmd.Flags().StringVar(&app.Config.Controller.HealthProbeBindAddress, "health-probe-bind-address", ":8081", "address to bind the metrics server embedded in the controllers")

deploy/charts/burrito/values.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ config:
1818
# -- By default, the controller will only watch the tenants namespaces
1919
namespaces: []
2020
timers: {}
21+
maxConcurrentReconciles: 1
2122
terraformMaxRetries: 3
2223
types: ["layer", "repository", "run", "pullrequest"]
2324
leaderElection:
@@ -45,7 +46,7 @@ config:
4546
storage:
4647
gcs: {}
4748
azure: {}
48-
aws: {}
49+
s3: {}
4950
addr: ":8080"
5051

5152
# Burrito server configuration

internal/burrito/config/config.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,19 @@ type WebhookGitlabConfig struct {
5858
}
5959

6060
type ControllerConfig struct {
61-
MainNamespace string `mapstructure:"mainNamespace"`
62-
Namespaces []string `mapstructure:"namespaces"`
63-
Timers ControllerTimers `mapstructure:"timers"`
64-
TerraformMaxRetries int `mapstructure:"terraformMaxRetries"`
65-
Types []string `mapstructure:"types"`
66-
LeaderElection LeaderElectionConfig `mapstructure:"leaderElection"`
67-
MetricsBindAddress string `mapstructure:"metricsBindAddress"`
68-
HealthProbeBindAddress string `mapstructure:"healthProbeBindAddress"`
69-
KubernetesWebhookPort int `mapstructure:"kubernetesWebhookPort"`
70-
GithubConfig GithubConfig `mapstructure:"githubConfig"`
71-
GitlabConfig GitlabConfig `mapstructure:"gitlabConfig"`
72-
RunParallelism int `mapstructure:"runParallelism"`
61+
MainNamespace string `mapstructure:"mainNamespace"`
62+
Namespaces []string `mapstructure:"namespaces"`
63+
Timers ControllerTimers `mapstructure:"timers"`
64+
TerraformMaxRetries int `mapstructure:"terraformMaxRetries"`
65+
Types []string `mapstructure:"types"`
66+
LeaderElection LeaderElectionConfig `mapstructure:"leaderElection"`
67+
MetricsBindAddress string `mapstructure:"metricsBindAddress"`
68+
HealthProbeBindAddress string `mapstructure:"healthProbeBindAddress"`
69+
KubernetesWebhookPort int `mapstructure:"kubernetesWebhookPort"`
70+
GithubConfig GithubConfig `mapstructure:"githubConfig"`
71+
GitlabConfig GitlabConfig `mapstructure:"gitlabConfig"`
72+
RunParallelism int `mapstructure:"runParallelism"`
73+
MaxConcurrentReconciles int `mapstructure:"maxConcurrentReconciles"`
7374
}
7475

7576
type GithubConfig struct {

internal/controllers/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (c *Controllers) Exec() {
120120
Client: mgr.GetClient(),
121121
Scheme: mgr.GetScheme(),
122122
Recorder: mgr.GetEventRecorderFor("Burrito"),
123+
Config: c.config,
123124
}).SetupWithManager(mgr); err != nil {
124125
log.Fatalf("unable to create repository controller: %s", err)
125126
}

internal/controllers/terraformlayer/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/client-go/tools/record"
3333
ctrl "sigs.k8s.io/controller-runtime"
3434
"sigs.k8s.io/controller-runtime/pkg/client"
35+
"sigs.k8s.io/controller-runtime/pkg/controller"
3536
"sigs.k8s.io/controller-runtime/pkg/event"
3637
"sigs.k8s.io/controller-runtime/pkg/predicate"
3738

@@ -202,6 +203,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
202203
r.Clock = RealClock{}
203204
return ctrl.NewControllerManagedBy(mgr).
204205
For(&configv1alpha1.TerraformLayer{}).
206+
WithOptions(controller.Options{MaxConcurrentReconciles: r.Config.Controller.MaxConcurrentReconciles}).
205207
WithEventFilter(ignorePredicate()).
206208
Complete(r)
207209
}

internal/controllers/terraformpullrequest/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"k8s.io/client-go/tools/record"
2020
ctrl "sigs.k8s.io/controller-runtime"
2121
"sigs.k8s.io/controller-runtime/pkg/client"
22+
"sigs.k8s.io/controller-runtime/pkg/controller"
2223
"sigs.k8s.io/controller-runtime/pkg/event"
2324
"sigs.k8s.io/controller-runtime/pkg/predicate"
2425

@@ -111,6 +112,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
111112
r.Providers = providers
112113
return ctrl.NewControllerManagedBy(mgr).
113114
For(&configv1alpha1.TerraformPullRequest{}).
115+
WithOptions(controller.Options{MaxConcurrentReconciles: r.Config.Controller.MaxConcurrentReconciles}).
114116
WithEventFilter(ignorePredicate()).
115117
Complete(r)
116118
}

internal/controllers/terraformrepository/controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@ import (
2424
"k8s.io/client-go/tools/record"
2525
ctrl "sigs.k8s.io/controller-runtime"
2626
"sigs.k8s.io/controller-runtime/pkg/client"
27+
"sigs.k8s.io/controller-runtime/pkg/controller"
2728

2829
configv1alpha1 "github.com/padok-team/burrito/api/v1alpha1"
30+
"github.com/padok-team/burrito/internal/burrito/config"
2931
)
3032

3133
// RepositoryReconciler reconciles a TerraformRepository object
3234
type Reconciler struct {
3335
client.Client
3436
Scheme *runtime.Scheme
3537
Recorder record.EventRecorder
38+
Config *config.Config
3639
}
3740

3841
//+kubebuilder:rbac:groups=config.terraform.padok.cloud,resources=terraformrepositories,verbs=get;list;watch;create;update;patch;delete
@@ -60,5 +63,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
6063
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
6164
return ctrl.NewControllerManagedBy(mgr).
6265
For(&configv1alpha1.TerraformRepository{}).
66+
WithOptions(controller.Options{MaxConcurrentReconciles: r.Config.Controller.MaxConcurrentReconciles}).
6367
Complete(r)
6468
}

internal/controllers/terraformrun/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"k8s.io/client-go/tools/record"
3737
ctrl "sigs.k8s.io/controller-runtime"
3838
"sigs.k8s.io/controller-runtime/pkg/client"
39+
"sigs.k8s.io/controller-runtime/pkg/controller"
3940
"sigs.k8s.io/controller-runtime/pkg/event"
4041
"sigs.k8s.io/controller-runtime/pkg/predicate"
4142

@@ -186,6 +187,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
186187
r.Clock = RealClock{}
187188
return ctrl.NewControllerManagedBy(mgr).
188189
For(&configv1alpha1.TerraformRun{}).
190+
WithOptions(controller.Options{MaxConcurrentReconciles: r.Config.Controller.MaxConcurrentReconciles}).
189191
WithEventFilter(ignorePredicate()).
190192
Complete(r)
191193
}

0 commit comments

Comments
 (0)