From 3702214ce8a9afa25988e5b7e76f6bffaf866b98 Mon Sep 17 00:00:00 2001 From: mgianluc Date: Wed, 5 Jun 2024 12:43:19 +0200 Subject: [PATCH] Set concurrent reconcilers --- .golangci.yaml | 11 +++------- cmd/main.go | 26 ++++++++++++++--------- internal/controller/cleaner_controller.go | 7 +++++- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index f64e423..f2b3dc3 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -36,10 +36,7 @@ linters-settings: goimports: local-prefixes: github.com/projectsveltos gomnd: - settings: - mnd: - # don't include the "operation" and "assign" - checks: argument,case,condition,return + checks: argument,case,condition,return gomodguard: # Although this is almost empty, we will evolve the list below with the # modules we shouldn't use for technical and/or security reasons. @@ -51,7 +48,7 @@ linters-settings: # Don't merge replace directives using local path. local_replace_directives: true govet: - check-shadowing: true + shadow: true settings: printf: funcs: @@ -177,6 +174,4 @@ run: allow-parallel-runners: true # Timeout for analysis timeout: 5m - # files to skip: they will be analyzed, but issues from them won't be reported. - skip-dirs: - - cmd/example/gen + diff --git a/cmd/main.go b/cmd/main.go index 6b0b39e..62b1b4a 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -46,14 +46,15 @@ import ( ) var ( - setupLog = ctrl.Log.WithName("setup") - metricsAddr string - probeAddr string - workers int - restConfigQPS float32 - restConfigBurst int - webhookPort int - syncPeriod time.Duration + setupLog = ctrl.Log.WithName("setup") + metricsAddr string + probeAddr string + workers int + restConfigQPS float32 + restConfigBurst int + webhookPort int + concurrentReconciles int + syncPeriod time.Duration ) func main() { @@ -104,8 +105,9 @@ func main() { } if err = (&controller.CleanerReconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + ConcurrentReconciles: concurrentReconciles, }).SetupWithManager(ctx, mgr, workers, ctrl.Log.WithName("worker")); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Cleaner") os.Exit(1) @@ -139,6 +141,10 @@ func initFlags(fs *pflag.FlagSet) { fs.IntVar(&workers, "worker-number", defaultWorkers, "Number of worker. Workers are used to process cleaner instances in backgroun") + const defaultReconcilers = 10 + fs.IntVar(&concurrentReconciles, "concurrent-reconciles", defaultReconcilers, + "concurrent reconciles is the maximum number of concurrent Reconciles which can be run. Defaults to 10") + const defautlRestConfigQPS = 40 fs.Float32Var(&restConfigQPS, "kube-api-qps", defautlRestConfigQPS, fmt.Sprintf("Maximum queries per second from the controller client to the Kubernetes API server. Defaults to %d", diff --git a/internal/controller/cleaner_controller.go b/internal/controller/cleaner_controller.go index 0011e77..f1b9183 100644 --- a/internal/controller/cleaner_controller.go +++ b/internal/controller/cleaner_controller.go @@ -29,6 +29,7 @@ import ( "k8s.io/apimachinery/pkg/types" 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" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -42,7 +43,8 @@ import ( // CleanerReconciler reconciles a Cleaner object type CleanerReconciler struct { client.Client - Scheme *runtime.Scheme + Scheme *runtime.Scheme + ConcurrentReconciles int } //+kubebuilder:rbac:groups=apps.projectsveltos.io,resources=cleaners,verbs=get;list;watch @@ -164,6 +166,9 @@ func (r *CleanerReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manag return ctrl.NewControllerManagedBy(mgr). For(&appsv1alpha1.Cleaner{}). + WithOptions(controller.Options{ + MaxConcurrentReconciles: r.ConcurrentReconciles, + }). Complete(r) }