Skip to content

Commit

Permalink
feat(RELEASE-1307): increases lease timeout
Browse files Browse the repository at this point in the history
this PR proposes a change in the default leader election
time controls to decrease the etcd load and allowing the
to wait time to renew the leadership, and also decreasing
the number of requests to etcd.

Signed-off-by: Leandro Mendes <[email protected]>
  • Loading branch information
theflockers committed Dec 3, 2024
1 parent f30a87d commit 70a0bb1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ spec:
- /manager
args:
- --leader-elect
- --lease-duration
- 60
- --leader-renew-deadline
- 30
- --leader-elector-retry-period
- 10
image: controller:latest
name: manager
securityContext:
Expand Down
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"crypto/tls"
"flag"
"os"
"time"

"sigs.k8s.io/controller-runtime/pkg/metrics/server"
crwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
Expand Down Expand Up @@ -70,13 +71,23 @@ func main() {
var metricsAddr string
var enableHttp2 bool
var enableLeaderElection bool
var leaderRenewDeadline time.Duration
var leaseDuration time.Duration
var leaderElectorRetryPeriod time.Duration

Check warning on line 76 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L74-L76

Added lines #L74 - L76 were not covered by tests
var probeAddr string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableHttp2, "enable-http2", false, "Enable HTTP/2 for the metrics and webhook servers.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.DurationVar(&leaderRenewDeadline, "leader-renew-deadline", 10*time.Second,
"Leader RenewDeadline is the duration that the acting controlplane "+
"will retry refreshing leadership before giving up.")
flag.DurationVar(&leaseDuration, "lease-duration", 15*time.Second,
"Lease Duration is the duration that non-leader candidates will wait to force acquire leadership.")
flag.DurationVar(&leaderElectorRetryPeriod, "leader-elector-retry-period", 2*time.Second, "RetryPeriod is the duration the "+
"LeaderElector clients should wait between tries of actions.")

Check warning on line 90 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L84-L90

Added lines #L84 - L90 were not covered by tests
opts := zap.Options{
Development: true,
TimeEncoder: zapcore.ISO8601TimeEncoder,
Expand All @@ -90,6 +101,9 @@ func main() {
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "f3d4c01a.redhat.com",
RenewDeadline: &leaderRenewDeadline,
LeaseDuration: &leaseDuration,
RetryPeriod: &leaderElectorRetryPeriod,

Check warning on line 106 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L104-L106

Added lines #L104 - L106 were not covered by tests
Metrics: server.Options{
BindAddress: metricsAddr,
},
Expand Down

0 comments on commit 70a0bb1

Please sign in to comment.