Skip to content

Commit

Permalink
Adding config variables to leader election process
Browse files Browse the repository at this point in the history
  • Loading branch information
gizas committed Oct 18, 2023
1 parent defde80 commit efd7411
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@ type Config struct {
// Name of the leaderelection lease
LeaderLease string `config:"leader_lease"`

//Parameters to configure election process
LeaseDuration int `config:"leader_leaseduration"`
RenewDeadline int `config:"leader_renewdeadline"`
RetryPeriod int `config:"leader_retryperiod"`

KubeClientOptions kubernetes.KubeClientOptions `config:"kube_client_options"`
}

// InitDefaults initializes the default values for the config.
func (c *Config) InitDefaults() {
c.LeaderLease = "elastic-agent-cluster-leader"
c.LeaseDuration = 15
c.RenewDeadline = 10
c.RetryPeriod = 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func (p *contextProvider) Run(ctx context.Context, comm corecomp.ContextProvider
},
},
ReleaseOnCancel: true,
LeaseDuration: 15 * time.Second,
RenewDeadline: 10 * time.Second,
RetryPeriod: 2 * time.Second,
LeaseDuration: time.Duration(p.config.LeaseDuration) * time.Second,
RenewDeadline: time.Duration(p.config.RenewDeadline) * time.Second,
RetryPeriod: time.Duration(p.config.RetryPeriod) * time.Second,
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: func(ctx context.Context) {
p.logger.Debugf("leader election lock GAINED, id %v", id)
Expand Down

0 comments on commit efd7411

Please sign in to comment.