#1486 : Fixed sealed and leader checks for consul backend

This commit is contained in:
Bill Monkman
2016-06-03 16:00:31 -07:00
parent 2fb34f6825
commit 64d72672ff
2 changed files with 8 additions and 9 deletions

View File

@@ -301,14 +301,14 @@ func (c *ServerCommand) Run(args []string) int {
sd, ok := coreConfig.HAPhysical.(physical.ServiceDiscovery) sd, ok := coreConfig.HAPhysical.(physical.ServiceDiscovery)
if ok { if ok {
activeFunc := func() bool { activeFunc := func() bool {
if isLeader, _, err := core.Leader(); err != nil { if isLeader, _, err := core.Leader(); err == nil {
return isLeader return isLeader
} }
return false return false
} }
sealedFunc := func() bool { sealedFunc := func() bool {
if sealed, err := core.Sealed(); err != nil { if sealed, err := core.Sealed(); err == nil {
return sealed return sealed
} }
return true return true

View File

@@ -463,12 +463,12 @@ shutdown:
// Abort if service discovery is disabled or a // Abort if service discovery is disabled or a
// reconcile handler is active // reconcile handler is active
if !c.disableRegistration && atomic.CompareAndSwapInt64(&checkLock, 0, 1) { if !c.disableRegistration && atomic.CompareAndSwapInt64(&checkLock, 0, 1) {
// Enter handler with serviceRegLock held // Enter handler with checkLock held
go func() { go func() {
defer atomic.CompareAndSwapInt64(&checkLock, 1, 0) defer atomic.CompareAndSwapInt64(&checkLock, 1, 0)
for !shutdown { for !shutdown {
unsealed := sealedFunc() sealed := sealedFunc()
if err := c.runCheck(unsealed); err != nil { if err := c.runCheck(sealed); err != nil {
c.logger.Printf("[WARN]: consul: check unable to talk with Consul backend: %v", err) c.logger.Printf("[WARN]: consul: check unable to talk with Consul backend: %v", err)
time.Sleep(consulRetryInterval) time.Sleep(consulRetryInterval)
continue continue
@@ -573,12 +573,11 @@ func (c *ConsulBackend) reconcileConsul(registeredServiceID string, activeFunc a
return serviceID, nil return serviceID, nil
} }
// runCheck immediately pushes a TTL check. Assumes c.serviceLock is held // runCheck immediately pushes a TTL check.
// exclusively. func (c *ConsulBackend) runCheck(sealed bool) error {
func (c *ConsulBackend) runCheck(unsealed bool) error {
// Run a TTL check // Run a TTL check
agent := c.client.Agent() agent := c.client.Agent()
if unsealed { if !sealed {
return agent.PassTTL(c.checkID(), "Vault Unsealed") return agent.PassTTL(c.checkID(), "Vault Unsealed")
} else { } else {
return agent.FailTTL(c.checkID(), "Vault Sealed") return agent.FailTTL(c.checkID(), "Vault Sealed")