From 114881c2aae76eac5bab19361bdaee9149a0147a Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Mon, 6 Jul 2020 11:31:33 -0400 Subject: [PATCH] reconcile should not overwrite unblocking state (#8349) Pre-0.12.0 beta, a deployment was considered "complete" if it was successful. But with MRD we have "blocked" and "unblocking" states as well. We did not consider the case where a concurrent alloc health status update triggers a `Compute` call on a deployment that's moved from "blocked" to "unblocking" (it's a small window), which caused an extra pass thru the `nextRegion` logic in `deploymentwatcher` and triggered an error when later transitioning to "successful". This changeset makes sure we don't overwrite that status. --- scheduler/reconcile.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/scheduler/reconcile.go b/scheduler/reconcile.go index 602b14848..1625090e6 100644 --- a/scheduler/reconcile.go +++ b/scheduler/reconcile.go @@ -218,23 +218,24 @@ func (a *allocReconciler) Compute() *reconcileResults { // Mark the deployment as complete if possible if a.deployment != nil && complete { - - var status string - var desc string - if a.job.IsMultiregion() { - status = structs.DeploymentStatusBlocked - desc = structs.DeploymentStatusDescriptionBlocked + // the unblocking/successful states come after blocked, so we + // need to make sure we don't revert those states + if a.deployment.Status != structs.DeploymentStatusUnblocking && + a.deployment.Status != structs.DeploymentStatusSuccessful { + a.result.deploymentUpdates = append(a.result.deploymentUpdates, &structs.DeploymentStatusUpdate{ + DeploymentID: a.deployment.ID, + Status: structs.DeploymentStatusBlocked, + StatusDescription: structs.DeploymentStatusDescriptionBlocked, + }) + } } else { - status = structs.DeploymentStatusSuccessful - desc = structs.DeploymentStatusDescriptionSuccessful + a.result.deploymentUpdates = append(a.result.deploymentUpdates, &structs.DeploymentStatusUpdate{ + DeploymentID: a.deployment.ID, + Status: structs.DeploymentStatusSuccessful, + StatusDescription: structs.DeploymentStatusDescriptionSuccessful, + }) } - - a.result.deploymentUpdates = append(a.result.deploymentUpdates, &structs.DeploymentStatusUpdate{ - DeploymentID: a.deployment.ID, - Status: status, - StatusDescription: desc, - }) } // Set the description of a created deployment