Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#700] Expose timeout options for leader election #701

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading