Skip to content

Control concurrent reconcile per namespace #3257

@a7i

Description

@a7i

controller-runtime provides the ability to control the MaxConcurrentReconciles

// MaxConcurrentReconciles is the maximum number of concurrent Reconciles which can be run. Defaults to 1.
MaxConcurrentReconciles int

This works great to control the concurrency limit at a global level, but I'm looking to limit it per namespace. In my use-case, I am reconciling pods in a particular order and the order only matters within a namespace and for a large cluster it's inefficient to have a global limit of 1.

	return ctrl.NewControllerManagedBy(mgr).
		Named(ControllerName).
		WithOptions(controller.Options{MaxConcurrentReconciles: 1}).
		For(&corev1.Pod{}, builder.WithPredicates(predicate.NewPredicateFuncs(func(object client.Object) bool {
			pod := object.(*corev1.Pod)

			if err := shouldReconcile(pod); err != nil {
				mgr.GetLogger().V(4).Info("skipping pod reconciliation: %s", err.Error())
				return false
			}

			return true
		}))).
		Complete(r)

I realize that not all resources are namespaced so we have to be aware of that in the api.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions