diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 169cdde4f..e9cf216bf 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -2199,17 +2199,19 @@ func (s *StateStore) updateDeploymentWithAlloc(index uint64, alloc, existing *st // If there was no existing allocation, this is a placement and we increment // the placement + existingHealthSet := existing.DeploymentStatus != nil && existing.DeploymentStatus.Healthy != nil + allocHealthSet := alloc.DeploymentStatus != nil && alloc.DeploymentStatus.Healthy != nil if existing == nil { placed++ - } else if existing.DeploymentHealth == nil && alloc.DeploymentHealth != nil { - if *alloc.DeploymentHealth { + } else if !existingHealthSet && allocHealthSet { + if *alloc.DeploymentStatus.Healthy { healthy++ } else { unhealthy++ } - } else if existing.DeploymentHealth != nil && alloc.DeploymentHealth != nil { + } else if existingHealthSet && allocHealthSet { // See if it has gone from healthy to unhealthy - if *existing.DeploymentHealth && !*alloc.DeploymentHealth { + if *existing.DeploymentStatus.Healthy && !*alloc.DeploymentStatus.Healthy { healthy-- unhealthy++ } diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 3bf68d530..228853e82 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -3642,10 +3642,9 @@ type Allocation struct { // particular deployment DeploymentID string - // DeploymentHealth marks whether the allocation has been marked healthy or - // unhealthy as part of a deployment. It can be unset if it has neither been - // marked healthy or unhealthy. - DeploymentHealth *bool + // DeploymentStatus captures the status of the allocation as part of the + // given deployment + DeploymentStatus *AllocDeploymentStatus // Canary marks this allocation as being a canary Canary bool @@ -3683,6 +3682,7 @@ func (a *Allocation) Copy() *Allocation { } na.Metrics = na.Metrics.Copy() + na.DeploymentStatus = na.DeploymentStatus.Copy() if a.TaskStates != nil { ts := make(map[string]*TaskState, len(na.TaskStates)) @@ -3925,6 +3925,30 @@ func (a *AllocMetric) ScoreNode(node *Node, name string, score float64) { a.Scores[key] = score } +// AllocDeploymentStatus captures the status of the allocation as part of the +// deployment. This can include things like if the allocation has been marked as +// heatlhy. +type AllocDeploymentStatus struct { + // Healthy marks whether the allocation has been marked healthy or unhealthy + // as part of a deployment. It can be unset if it has neither been marked + // healthy or unhealthy. + Healthy *bool +} + +func (a *AllocDeploymentStatus) Copy() *AllocDeploymentStatus { + if a == nil { + return nil + } + + c := new(AllocDeploymentStatus) + + if a.Healthy != nil { + c.Healthy = helper.BoolToPtr(*a.Healthy) + } + + return c +} + const ( EvalStatusBlocked = "blocked" EvalStatusPending = "pending"