From 9cb19cb07c20c12fd8a06c362f38cf4aeae5b429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Golicz?= Date: Mon, 9 Dec 2024 15:22:30 +0100 Subject: [PATCH] Configurable number of workloads for both controllers with default value 25 --- cmd/main.go | 10 ++++++++-- .../kubeconfig/gardener_cluster_controller.go | 3 +-- internal/controller/kubeconfig/suite_test.go | 2 +- internal/controller/runtime/runtime_controller.go | 4 +--- internal/controller/runtime/suite_test.go | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 3806bdac..63b6ded8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -83,6 +83,8 @@ const ( defaultShootCreateRequeueDuration = 60 * time.Second defaultShootDeleteRequeueDuration = 90 * time.Second defaultShootReconcileRequeueDuration = 30 * time.Second + defaultRuntimeCtrlWorkersCnt = 25 + defaultGardenerClusterCtrlWorkersCnt = 25 ) func main() { @@ -97,6 +99,8 @@ func main() { var runtimeCtrlGardenerRequestTimeout time.Duration var runtimeCtrlGardenerRateLimiterQPS int var runtimeCtrlGardenerRateLimiterBurst int + var runtimeCtrlWorkersCnt int + var gardenerClusterCtrlWorkersCnt int var converterConfigFilepath string var shootSpecDumpEnabled bool var auditLogMandatory bool @@ -114,6 +118,8 @@ func main() { flag.DurationVar(&runtimeCtrlGardenerRequestTimeout, "gardener-request-timeout", defaultGardenerRequestTimeout, "Timeout duration for Gardener client for Runtime Controller") flag.IntVar(&runtimeCtrlGardenerRateLimiterQPS, "gardener-ratelimiter-qps", defaultGardenerRateLimiterQPS, "Gardener client rate limiter QPS for Runtime Controller") flag.IntVar(&runtimeCtrlGardenerRateLimiterBurst, "gardener-ratelimiter-burst", defaultGardenerRateLimiterBurst, "Gardener client rate limiter burst for Runtime Controller") + flag.IntVar(&runtimeCtrlWorkersCnt, "runtime-ctrl-workers-cnt", defaultRuntimeCtrlWorkersCnt, "A number of workers running in parallel for Runtime Controller") + flag.IntVar(&gardenerClusterCtrlWorkersCnt, "gardener-cluster-ctrl-workers-cnt", defaultGardenerClusterCtrlWorkersCnt, "A number of workers running in parallel for Gardener Cluster Controller") flag.StringVar(&converterConfigFilepath, "converter-config-filepath", "/converter-config/converter_config.json", "A file path to the gardener shoot converter configuration.") flag.BoolVar(&shootSpecDumpEnabled, "shoot-spec-dump-enabled", false, "Feature flag to allow persisting specs of created shoots") flag.BoolVar(&auditLogMandatory, "audit-log-mandatory", true, "Feature flag to enable strict mode for audit log configuration") @@ -178,7 +184,7 @@ func main() { minimalRotationTimeRatio, gardenerCtrlReconciliationTimeout, metrics, - ).SetupWithManager(mgr); err != nil { + ).SetupWithManager(mgr, gardenerClusterCtrlWorkersCnt); err != nil { setupLog.Error(err, "unable to create controller", "controller", "GardenerCluster") os.Exit(1) } @@ -229,7 +235,7 @@ func main() { cfg, ) - if err = runtimeReconciler.SetupWithManager(mgr); err != nil { + if err = runtimeReconciler.SetupWithManager(mgr, runtimeCtrlWorkersCnt); err != nil { setupLog.Error(err, "unable to setup controller with Manager", "controller", "Runtime") os.Exit(1) } diff --git a/internal/controller/kubeconfig/gardener_cluster_controller.go b/internal/controller/kubeconfig/gardener_cluster_controller.go index c3bf14d8..386007a6 100644 --- a/internal/controller/kubeconfig/gardener_cluster_controller.go +++ b/internal/controller/kubeconfig/gardener_cluster_controller.go @@ -44,7 +44,6 @@ const ( clusterCRNameLabel = "operator.kyma-project.io/cluster-name" rotationPeriodRatio = 0.95 - numberOfWorkers = 25 ) // GardenerClusterController reconciles a GardenerCluster object @@ -431,7 +430,7 @@ func (controller *GardenerClusterController) newSecret(cluster imv1.GardenerClus } // SetupWithManager sets up the controller with the Manager. -func (controller *GardenerClusterController) SetupWithManager(mgr ctrl.Manager) error { +func (controller *GardenerClusterController) SetupWithManager(mgr ctrl.Manager, numberOfWorkers int) error { return ctrl.NewControllerManagedBy(mgr). For(&imv1.GardenerCluster{}, builder.WithPredicates(predicate.Or( predicate.LabelChangedPredicate{}, diff --git a/internal/controller/kubeconfig/suite_test.go b/internal/controller/kubeconfig/suite_test.go index bff77022..cd776e67 100644 --- a/internal/controller/kubeconfig/suite_test.go +++ b/internal/controller/kubeconfig/suite_test.go @@ -92,7 +92,7 @@ var _ = BeforeSuite(func() { Expect(gardenerClusterController).NotTo(BeNil()) - err = gardenerClusterController.SetupWithManager(mgr) + err = gardenerClusterController.SetupWithManager(mgr, 1) Expect(err).To(BeNil()) Expect(gardenerClusterController).NotTo(BeNil()) diff --git a/internal/controller/runtime/runtime_controller.go b/internal/controller/runtime/runtime_controller.go index 6ec81603..7708421f 100644 --- a/internal/controller/runtime/runtime_controller.go +++ b/internal/controller/runtime/runtime_controller.go @@ -31,8 +31,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" ) -const numberOfWorkers = 25 - // RuntimeReconciler reconciles a Runtime object // nolint:revive type RuntimeReconciler struct { @@ -91,7 +89,7 @@ func NewRuntimeReconciler(mgr ctrl.Manager, shootClient client.Client, logger lo } // SetupWithManager sets up the controller with the Manager. -func (r *RuntimeReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *RuntimeReconciler) SetupWithManager(mgr ctrl.Manager, numberOfWorkers int) error { return ctrl.NewControllerManagedBy(mgr). For(&imv1.Runtime{}). WithOptions(controller.Options{MaxConcurrentReconciles: numberOfWorkers}). diff --git a/internal/controller/runtime/suite_test.go b/internal/controller/runtime/suite_test.go index 52fd1155..136be430 100644 --- a/internal/controller/runtime/suite_test.go +++ b/internal/controller/runtime/suite_test.go @@ -135,7 +135,7 @@ var _ = BeforeSuite(func() { runtimeReconciler = NewRuntimeReconciler(mgr, gardenerTestClient, logger, fsmCfg) Expect(runtimeReconciler).NotTo(BeNil()) - err = runtimeReconciler.SetupWithManager(mgr) + err = runtimeReconciler.SetupWithManager(mgr, 1) Expect(err).To(BeNil()) //+kubebuilder:scaffold:scheme