Skip to content

Commit

Permalink
[#700] Expose timeout options for leader election
Browse files Browse the repository at this point in the history
  • Loading branch information
brusdev committed Oct 6, 2023
1 parent 16f211f commit 0bb5c96
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"sort"
"strings"
"time"

"github.com/artemiscloud/activemq-artemis-operator/version"

Expand Down Expand Up @@ -99,13 +100,19 @@ func init() {
func main() {
var metricsAddr string
var enableLeaderElection bool
var leaseDurationSeconds int64
var renewDeadlineSeconds int64
var retryPeriodSeconds int64
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(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.Int64Var(&leaseDurationSeconds, "lease-duration", 15, "LeaseDuration is the duration that non-leader candidates will wait to force acquire leadership. This is measured against time of last observed ack. Default is 15 seconds.")
flag.Int64Var(&renewDeadlineSeconds, "renew-deadline", 10, "RenewDeadline is the duration that the acting controlplane will retry refreshing leadership before giving up. Default is 10 seconds.")
flag.Int64Var(&retryPeriodSeconds, "retry-period", 2, "RetryPeriod is the duration the LeaderElector clients should wait between tries of actions. Default is 2 seconds.")
opts := zap.Options{
Development: true,
}
Expand Down Expand Up @@ -148,6 +155,10 @@ func main() {
setupLog.Error(err, "failed to set operator's watch namespace to env")
}

leaseDuration := time.Duration(leaseDurationSeconds) * time.Second
renewDeadline := time.Duration(renewDeadlineSeconds) * time.Second
retryPeriod := time.Duration(retryPeriodSeconds) * time.Second

mgrOptions := ctrl.Options{
Scheme: scheme,
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
Expand All @@ -156,6 +167,9 @@ func main() {
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "d864aab0.amq.io",
LeaseDuration: &leaseDuration,
RenewDeadline: &renewDeadline,
RetryPeriod: &retryPeriod,
}

isLocal, watchList := common.ResolveWatchNamespaceForManager(oprNamespace, watchNamespace)
Expand All @@ -172,6 +186,17 @@ func main() {
}
}

setupLog.Info("Manager options",
"Namespace", mgrOptions.Namespace,
"MetricsBindAddress", mgrOptions.MetricsBindAddress,
"Port", mgrOptions.Port,
"HealthProbeBindAddress", mgrOptions.HealthProbeBindAddress,
"LeaderElection", mgrOptions.LeaderElection,
"LeaderElectionID", mgrOptions.LeaderElectionID,
"LeaseDuration", mgrOptions.LeaseDuration,
"RenewDeadline", mgrOptions.RenewDeadline,
"RetryPeriod", mgrOptions.RetryPeriod)

mgr, err := ctrl.NewManager(cfg, mgrOptions)
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down

0 comments on commit 0bb5c96

Please sign in to comment.