@@ -35,13 +35,16 @@ import (
3535 "k8s.io/client-go/tools/leaderelection/resourcelock"
3636
3737 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
38+ "github.com/arangodb/kube-arangodb/pkg/util/probe"
3839)
3940
4041// runLeaderElection performs a leader election on a lock with given name in
4142// the namespace that the operator is deployed in.
4243// When the leader election is won, the given callback is called.
4344// When the leader election is lost (even after it was won once), the process is killed.
44- func (o * Operator ) runLeaderElection (lockName string , onStart func (stop <- chan struct {})) {
45+ // The given ready probe is set, as soon as this process became the leader, or a new leader
46+ // is detected.
47+ func (o * Operator ) runLeaderElection (lockName string , onStart func (stop <- chan struct {}), readyProbe * probe.ReadyProbe ) {
4548 namespace := o .Config .Namespace
4649 kubecli := o .Dependencies .KubeCli
4750 log := o .log .With ().Str ("lock-name" , lockName ).Logger ()
@@ -71,13 +74,18 @@ func (o *Operator) runLeaderElection(lockName string, onStart func(stop <-chan s
7174 Callbacks : leaderelection.LeaderCallbacks {
7275 OnStartedLeading : func (stop <- chan struct {}) {
7376 recordEvent ("Leader Election Won" , fmt .Sprintf ("Pod %s is running as leader" , o .Config .PodName ))
77+ readyProbe .SetReady ()
7478 onStart (stop )
7579 },
7680 OnStoppedLeading : func () {
7781 recordEvent ("Stop Leading" , fmt .Sprintf ("Pod %s is stopping to run as leader" , o .Config .PodName ))
7882 log .Info ().Msg ("Stop leading. Terminating process" )
7983 os .Exit (1 )
8084 },
85+ OnNewLeader : func (identity string ) {
86+ log .Info ().Str ("identity" , identity ).Msg ("New leader detected" )
87+ readyProbe .SetReady ()
88+ },
8189 },
8290 })
8391}
0 commit comments