Skip to content

Commit

Permalink
Fix k8s service registration case where Vault fails to unlabel itself…
Browse files Browse the repository at this point in the history
… as a leader (#21642)
  • Loading branch information
tomhjp authored Jul 17, 2023
1 parent e1a9d85 commit 5d97159
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
3 changes: 3 additions & 0 deletions changelog/21642.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
serviceregistration: Fix bug where multiple nodes in a secondary cluster could be labelled active after updating the cluster's primary
```
20 changes: 8 additions & 12 deletions vault/ha.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,13 @@ func (c *Core) waitForLeadership(newLeaderCh chan func(), manualStepDownCh, stop
c.heldHALock = nil
}

// Advertise ourselves as a standby.
if c.serviceRegistration != nil {
if err := c.serviceRegistration.NotifyActiveStateChange(false); err != nil {
c.logger.Warn("failed to notify standby status", "error", err)
}
}

// If we are stopped return, otherwise unlock the statelock
if stopped {
return
Expand Down Expand Up @@ -1133,18 +1140,7 @@ func (c *Core) cleanLeaderPrefix(ctx context.Context, uuid string, leaderLostCh
// clearLeader is used to clear our leadership entry
func (c *Core) clearLeader(uuid string) error {
key := coreLeaderPrefix + uuid
err := c.barrier.Delete(context.Background(), key)

// Advertise ourselves as a standby
if c.serviceRegistration != nil {
if err := c.serviceRegistration.NotifyActiveStateChange(false); err != nil {
if c.logger.IsWarn() {
c.logger.Warn("failed to notify standby status", "error", err)
}
}
}

return err
return c.barrier.Delete(context.Background(), key)
}

func (c *Core) SetNeverBecomeActive(on bool) {
Expand Down

0 comments on commit 5d97159

Please sign in to comment.