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

feat: add leader election envionment variables to make them configurable #3225

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions controllers/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"time"

"go.uber.org/zap"
appv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -41,6 +42,20 @@ type ArgoEventsControllerOpts struct {
HealthPort int32
}

func lookupEnvDurationOr(key string, o time.Duration) *time.Duration {
logger := logging.NewArgoEventsLogger().Named(eventbus.ControllerName)
v, found := os.LookupEnv(key)
if found && v != "" {
d, err := time.ParseDuration(v)
if err != nil {
logger.With(key, v).Fatalw("parsing %s duration", key, zap.Error(err))
} else {
return &d
}
}
return &o
}

func Start(eventsOpts ArgoEventsControllerOpts) {
logger := logging.NewArgoEventsLogger().Named(eventbus.ControllerName)
config, err := controllers.LoadConfig(func(err error) {
Expand Down Expand Up @@ -74,6 +89,9 @@ func Start(eventsOpts ArgoEventsControllerOpts) {
if eventsOpts.LeaderElection {
opts.LeaderElection = true
opts.LeaderElectionID = "argo-events-controller"
opts.LeaseDuration = lookupEnvDurationOr("LEADER_ELECTION_LEASE_DURATION", 15*time.Second)
opts.RenewDeadline = lookupEnvDurationOr("LEADER_ELECTION_RENEW_DEADLINE", 10*time.Second)
opts.RetryPeriod = lookupEnvDurationOr("LEADER_ELECTION_RETRY_PERIOD", 5*time.Second)
}
restConfig := ctrl.GetConfigOrDie()
mgr, err := ctrl.NewManager(restConfig, opts)
Expand Down