diff --git a/pkg/controller/core/leader_aware_reconciler.go b/pkg/controller/core/leader_aware_reconciler.go index 9a3367f601..7da7766583 100644 --- a/pkg/controller/core/leader_aware_reconciler.go +++ b/pkg/controller/core/leader_aware_reconciler.go @@ -21,6 +21,7 @@ import ( "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -42,14 +43,17 @@ import ( // - Transition to actually reconciling requests in the replica that may acquire // the leader election lease, in case the previously leading replica failed to renew it. func WithLeadingManager(mgr ctrl.Manager, reconciler reconcile.Reconciler, cfg *config.Configuration) reconcile.Reconciler { + // Do not decorate the reconciler if leader election is disabled + if cfg.LeaderElection == nil || !ptr.Deref(cfg.LeaderElection.LeaderElect, false) { + return reconciler + } + // Default to the recommended lease duration, that's used for core components requeueDuration := 15 * time.Second // Otherwise used the configured lease duration for the manager - if le := cfg.LeaderElection; le != nil { - zero := metav1.Duration{} - if duration := le.LeaseDuration; duration != zero { - requeueDuration = duration.Duration - } + zero := metav1.Duration{} + if duration := cfg.LeaderElection.LeaseDuration; duration != zero { + requeueDuration = duration.Duration } return &leaderAwareReconciler{