Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set concurrent reconcilers #73

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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

26 changes: 16 additions & 10 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion internal/controller/cleaner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
Loading