update maintenance check to passing before removing

Without this update service using `consul watch` to monitor check
changes will never see maintenance mode being disabled.

Resolves: https://github.com/hashicorp/consul/issues/11330

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2021-10-15 17:26:31 +02:00 committed by Siddarth Kumar
parent 00d74abc4a
commit c113fd6b6f
No known key found for this signature in database
GPG Key ID: 599D10112BF518DB
2 changed files with 11 additions and 0 deletions

3
.changelog/11332.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
agent: update maintenance check to passing before removing
```

View File

@ -4109,6 +4109,10 @@ func (a *Agent) DisableServiceMaintenance(serviceID structs.ServiceID) error {
return nil return nil
} }
// Update check to trigger an event for watchers
a.State.UpdateCheck(checkID, api.HealthPassing, "")
// Make sure state change is propagated
a.State.SyncChanges()
// Deregister the maintenance check // Deregister the maintenance check
a.RemoveCheck(checkID, true) a.RemoveCheck(checkID, true)
a.logger.Info("Service left maintenance mode", "service", serviceID.String()) a.logger.Info("Service left maintenance mode", "service", serviceID.String())
@ -4146,6 +4150,10 @@ func (a *Agent) DisableNodeMaintenance() {
if a.State.Check(structs.NodeMaintCheckID) == nil { if a.State.Check(structs.NodeMaintCheckID) == nil {
return return
} }
// Update check to trigger an event for watchers
a.State.UpdateCheck(structs.NodeMaintCheckID, api.HealthPassing, "")
// Make sure state change is propagated
a.State.SyncChanges()
a.RemoveCheck(structs.NodeMaintCheckID, true) a.RemoveCheck(structs.NodeMaintCheckID, true)
a.logger.Info("Node left maintenance mode") a.logger.Info("Node left maintenance mode")
} }