Skip to content

Conversation

@nader-ziada
Copy link
Contributor

@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 3 times, most recently from 88595fc to a227029 Compare October 28, 2025 16:44
@nader-ziada
Copy link
Contributor 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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for configuring leader election timing parameters through environment variables to allow operators to adjust leader election behavior for different cluster configurations without requiring code changes.

  • Add environment variable parsing for lease duration, renew deadline, and retry period
  • Implement validation to ensure leader election timing constraints are met
  • Add comprehensive test coverage for parsing and validation
  • Document the new configuration options

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pkg/util/env_resolver.go Adds ValidateLeaderElectionConfig function to validate timing parameter relationships
pkg/util/env_resolver_test.go Adds tests for leader election configuration validation with various valid and invalid scenarios
operator/main.go Integrates environment variable parsing and validation for leader election timing parameters
operator/main_test.go Adds integration tests for environment variable parsing
docs/operate.md Documents the new leader election timing configuration options
CHANGELOG.md Updates changelog with the new feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@snyk-io
Copy link

snyk-io bot commented Nov 18, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nader-ziada
Copy link
Contributor Author

@wozniakjan addressed review comments, but I don't think I have access to start tests, would you mind kicking off tests again?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nader-ziada nader-ziada force-pushed the leader-election-env-vars branch from 492e532 to 2874ae2 Compare November 19, 2025 01:28
nader-ziada and others added 5 commits November 27, 2025 10:59
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]>
- take into account partial setting of params and default values
- fix md file format
- fix linter issues

Signed-off-by: Nader Ziada <[email protected]>
@nader-ziada nader-ziada force-pushed the leader-election-env-vars branch from 2874ae2 to 81939a7 Compare November 27, 2025 15:59
@nader-ziada nader-ziada requested a review from Copilot November 27, 2025 16:11
Copilot finished reviewing on behalf of nader-ziada November 27, 2025 16:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@wozniakjan wozniakjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thank you!

@wozniakjan wozniakjan merged commit 142fb77 into kedacore:main Nov 28, 2025
23 of 24 checks passed
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

3 participants