Skip to content

Commit

Permalink
abort kube-ovn-controller on leader change
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Aug 12, 2022
1 parent e706406 commit e547dee
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/controller/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type leaderElectionConfig struct {
Client clientset.Interface

ElectionID string
WasLeader bool

OnStartedLeading func(chan struct{})
OnStoppedLeading func()
Expand All @@ -37,13 +38,22 @@ func (c *Controller) isLeader() bool {
}

func (c *Controller) leaderElection() {
elector := setupLeaderElection(&leaderElectionConfig{
config := &leaderElectionConfig{
Client: c.config.KubeClient,
ElectionID: "kube-ovn-controller",
PodName: c.config.PodName,
PodNamespace: c.config.PodNamespace,
})
c.elector = elector
}
config.OnStartedLeading = func(_ chan struct{}) {
config.WasLeader = true
}
config.OnNewLeader = func(identity string) {
if config.WasLeader && identity != config.PodName {
klog.Fatal("I am not leader anymore")
}
}

c.elector = setupLeaderElection(config)
for {
if c.isLeader() {
return
Expand Down

0 comments on commit e547dee

Please sign in to comment.