Skip to content

Conversation

@nader-ziada
Copy link

@nader-ziada nader-ziada commented Oct 27, 2025

Add support for configuring leader election timing parameters through environment variables.

Changes:

  • Add environment variable parsing in operator/main.go for:
    • KEDA_HTTP_OPERATOR_LEADER_ELECTION_LEASE_DURATION
    • KEDA_HTTP_OPERATOR_LEADER_ELECTION_RENEW_DEADLINE
    • KEDA_HTTP_OPERATOR_LEADER_ELECTION_RETRY_PERIOD
  • Pass parsed durations to ctrl.NewManager Options
  • Add test in operator/main_test.go covering parsing, defaults and error handling
  • Add configuration docs

All three environment variables are optional. When not set, controller-runtime uses Kubernetes defaults (LeaseDuration: 15s, RenewDeadline: 10s, RetryPeriod: 2s). This allows operators to adjust leader election timing for different cluster configurations and network conditions without requiring code changes.

Fixes: #1331

Checklist

@Fedosin
Copy link

Fedosin commented Oct 28, 2025

Hey! Thank you for working on this. The PR looks good, but maybe we could also add some additional validation for these values? For instance, we should ensure that LeaseDuration > RenewDeadline, RenewDeadline > RetryPeriod, and all three values are greater than 0.

@nader-ziada nader-ziada force-pushed the leader-election-env-vars branch 2 times, most recently from d32e493 to 88595fc Compare October 28, 2025 16:40
Add support for configuring leader election timing parameters through
environment variables.

Changes:
- Add environment variable parsing in operator/main.go for:
  - KEDA_HTTP_OPERATOR_LEADER_ELECTION_LEASE_DURATION
  - KEDA_HTTP_OPERATOR_LEADER_ELECTION_RENEW_DEADLINE
  - KEDA_HTTP_OPERATOR_LEADER_ELECTION_RETRY_PERIOD
- Pass parsed durations to ctrl.NewManager Options
- Add test in operator/main_test.go covering parsing, defaults and error handling
- Add configuration docs

All three environment variables are optional. When not set, controller-runtime
uses Kubernetes defaults (LeaseDuration: 15s, RenewDeadline: 10s, RetryPeriod: 2s).
This allows operators to adjust leader election timing for different cluster
configurations and network conditions without requiring code changes.

Fixes: kedacore#1331

Signed-off-by: Nader Ziada <[email protected]>
Signed-off-by: Nader Ziada <[email protected]>
@nader-ziada nader-ziada force-pushed the leader-election-env-vars branch from 88595fc to a227029 Compare October 28, 2025 16:44
@nader-ziada
Copy link
Author

Hey! Thank you for working on this. The PR looks good, but maybe we could also add some additional validation for these values? For instance, we should ensure that LeaseDuration > RenewDeadline, RenewDeadline > RetryPeriod, and all three values are greater than 0.

thanks for the review @Fedosin, added the validation checks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Leader Election Lease Options

2 participants