cluster: configurable session TTL for the leader elector

This commit is contained in:
Andras Banki-Horvath
2022-03-16 20:09:55 +01:00
parent 57840bba36
commit 8eca46f142
4 changed files with 24 additions and 10 deletions

View File

@@ -15,9 +15,9 @@ import (
func makeEtcdElector(ctx context.Context, args ...interface{}) (LeaderElector,
error) {
if len(args) != 3 {
if len(args) != 4 {
return nil, fmt.Errorf("invalid number of arguments to "+
"cluster.makeEtcdElector(): expected 3, got %v",
"cluster.makeEtcdElector(): expected 4, got %v",
len(args))
}
@@ -33,13 +33,21 @@ func makeEtcdElector(ctx context.Context, args ...interface{}) (LeaderElector,
"cluster.makeEtcdElector(), expected: string")
}
etcdCfg, ok := args[2].(*etcd.Config)
leaderSessionTTL, ok := args[2].(int)
if !ok {
return nil, fmt.Errorf("invalid argument (2) to " +
"cluster.makeEtcdElector(), expected: int")
}
etcdCfg, ok := args[3].(*etcd.Config)
if !ok {
return nil, fmt.Errorf("invalid argument (3) to " +
"cluster.makeEtcdElector(), expected: *etcd.Config")
}
return newEtcdLeaderElector(ctx, id, electionPrefix, etcdCfg)
return newEtcdLeaderElector(
ctx, id, electionPrefix, leaderSessionTTL, etcdCfg,
)
}
func init() {