From 26cb3cd12da9dfe5252020dd114d964e5f2cf1bf Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Tue, 22 Jan 2019 16:43:32 -0600 Subject: [PATCH] Use DesiredState to determine whether to stop sending task events --- client/allochealth/tracker.go | 2 +- client/allocrunner/alloc_runner_hooks.go | 4 ++-- nomad/structs/structs.go | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/client/allochealth/tracker.go b/client/allochealth/tracker.go index ad87d6f5d..47e62cf92 100644 --- a/client/allochealth/tracker.go +++ b/client/allochealth/tracker.go @@ -146,7 +146,7 @@ func (t *Tracker) TaskEvents() map[string]*structs.TaskEvent { defer t.l.Unlock() // Nothing to do since the failure wasn't task related - if t.allocFailed || t.alloc.TerminalStatus() { + if t.allocFailed { return nil } diff --git a/client/allocrunner/alloc_runner_hooks.go b/client/allocrunner/alloc_runner_hooks.go index 8dc3a46af..1090d37cc 100644 --- a/client/allocrunner/alloc_runner_hooks.go +++ b/client/allocrunner/alloc_runner_hooks.go @@ -46,11 +46,11 @@ func (a *allocHealthSetter) SetHealth(healthy, isDeploy bool, trackerTaskEvents a.ar.stateLock.Lock() a.ar.state.SetDeploymentStatus(time.Now(), healthy) a.ar.persistDeploymentStatus(a.ar.state.DeploymentStatus) - isTerminal := a.ar.alloc.TerminalStatus() + terminalDesiredState := a.ar.alloc.ServerTerminalStatus() a.ar.stateLock.Unlock() // If deployment is unhealthy emit task events explaining why - if !healthy && isDeploy && !isTerminal { + if !healthy && isDeploy && !terminalDesiredState { for task, event := range trackerTaskEvents { if tr, ok := a.ar.tasks[task]; ok { // Append but don't emit event since the server diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index b735d6e37..775cf988f 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -7288,13 +7288,17 @@ func (a *Allocation) copyImpl(job bool) *Allocation { func (a *Allocation) TerminalStatus() bool { // First check the desired state and if that isn't terminal, check client // state. + return a.ServerTerminalStatus() || a.ClientTerminalStatus() +} + +// ServerTerminalStatus returns true if the desired state of the allocation is terminal +func (a *Allocation) ServerTerminalStatus() bool { switch a.DesiredStatus { case AllocDesiredStatusStop, AllocDesiredStatusEvict: return true default: + return false } - - return a.ClientTerminalStatus() } // ClientTerminalStatus returns if the client status is terminal and will no longer transition