Skip to content

Commit

Permalink
fix: run elector again after failure
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Oct 15, 2024
1 parent 83224cd commit 31e08e1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions leader/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ func Register(
time.Sleep(time.Second * 2)
})

go elector.Run(leaderContext)
go func() {
for {
// when a network failure occurs for a considerable amount of time (>30s)
// elector.Run terminates and never retries acquiring the lease.
//
// that's why it's run in a never ending loop
elector.Run(leaderContext)
}
}()
<-ctx.Done()

return nil
Expand All @@ -149,8 +157,6 @@ func updateLeaderLabel(ctx context.Context, app string) {
pods := lo.Map(podList.Items, func(p corev1.Pod, _ int) string { return p.Name })
pods = append(pods, hostname)

fmt.Println("Pods ", len(pods))

for _, podName := range pods {
var payload string
if podName == hostname {
Expand Down

0 comments on commit 31e08e1

Please sign in to comment.