Skip to content

Commit

Permalink
Decorate reconcilers only when leader election is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Jan 11, 2024
1 parent de8687b commit d7fbfd1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/controller/core/leader_aware_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -42,6 +43,11 @@ 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
Expand Down

0 comments on commit d7fbfd1

Please sign in to comment.