Skip to content

Commit 7cdd394

Browse files
[v0.18.x] leader: get most recent lock owner when attempting a claim (#3164)
Co-authored-by: Michael Grosser <[email protected]>
1 parent d576b2e commit 7cdd394

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
entries:
2+
- description: fix leader election of follower showing that an old leader will be evicted when the current leader is healthy
3+
kind: bugfix
4+
breaking: false

pkg/leader/leader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ func Become(ctx context.Context, lockName string) error {
108108
log.Info("Became the leader.")
109109
return nil
110110
case apierrors.IsAlreadyExists(err):
111+
// refresh the lock so we use current leader
112+
key := crclient.ObjectKey{Namespace: ns, Name: lockName}
113+
if err := client.Get(ctx, key, existing); err != nil {
114+
log.Info("Leader lock configmap not found.")
115+
continue // configmap got lost ... just wait a bit
116+
}
117+
111118
existingOwners := existing.GetOwnerReferences()
112119
switch {
113120
case len(existingOwners) != 1:

0 commit comments

Comments
 (0)