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

Add Leader Election Lease Options #3430

Merged
merged 8 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ To learn more about our roadmap, we recommend reading [this document](ROADMAP.md

## Unreleased

- **General:** Add settings for configuring leader election ([#2836]https://github.com/kedacore/keda/issues/2836))
wsugarman marked this conversation as resolved.
Show resolved Hide resolved

### New

- **General:** Add support to customize HPA name ([3057](https://github.com/kedacore/keda/issues/3057))
- **General:** Add support to customize HPA name ([#3057](https://github.com/kedacore/keda/issues/3057))
- **General:** Basic setup for migrating e2e tests to Go. ([#2737](https://github.com/kedacore/keda/issues/2737))
- **General:** Introduce new AWS DynamoDB Streams Scaler ([#3124](https://github.com/kedacore/keda/issues/3124))
- **General:** Make propagation policy for ScaledJob rollout configurable ([#2910](https://github.com/kedacore/keda/issues/2910))
Expand Down
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,34 @@ func main() {
os.Exit(1)
}

leaseDuration, err := kedautil.ResolveOsEnvDuration("KEDA_LEADER_ELECTION_LEASE_DURATION", time.Duration(15)*time.Second)
wsugarman marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
setupLog.Error(err, "Invalid KEDA_LEADER_ELECTION_LEASE_DURATION")
os.Exit(1)
}

renewDeadline, err := kedautil.ResolveOsEnvDuration("KEDA_LEADER_ELECTION_RENEW_DEADLINE", time.Duration(10)*time.Second)
if err != nil {
setupLog.Error(err, "Invalid KEDA_LEADER_ELECTION_RENEW_DEADLINE")
os.Exit(1)
}

retryPeriod, err := kedautil.ResolveOsEnvDuration("KEDA_LEADER_ELECTION_RETRY_PERIOD", time.Duration(2)*time.Second)
if err != nil {
setupLog.Error(err, "Invalid KEDA_LEADER_ELECTION_RETRY_PERIOD")
os.Exit(1)
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "operator.keda.sh",
LeaseDuration: &leaseDuration,
RenewDeadline: &renewDeadline,
RetryPeriod: &retryPeriod,
Namespace: namespace,
})
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions pkg/util/env_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package util
import (
"os"
"strconv"
"time"
)

func ResolveOsEnvInt(envName string, defaultValue int) (int, error) {
Expand All @@ -14,3 +15,13 @@ func ResolveOsEnvInt(envName string, defaultValue int) (int, error) {

return defaultValue, nil
}

func ResolveOsEnvDuration(envName string, defaultValue time.Duration) (time.Duration, error) {
valueStr, found := os.LookupEnv(envName)

if found && valueStr != "" {
return time.ParseDuration(valueStr)
}

return defaultValue, nil
}