Fixes auto revert to check if the job's spec has changed before reverting. This prevents infinite reverting when reverting to a job version that was previously stable, but not so after attempting a revert.

This commit is contained in:
Preetha Appan 2017-11-02 15:00:54 -05:00
parent 9942ec205a
commit 5505391663
2 changed files with 13 additions and 1 deletions

View File

@ -371,7 +371,13 @@ func (w *deploymentWatcher) watch() {
// Description should include that the job is being rolled back to
// version N
if j != nil {
desc = structs.DeploymentStatusDescriptionRollback(desc, j.Version)
// only revert if job being changed has a different spec
if w.j.SpecChanged(j) {
desc = structs.DeploymentStatusDescriptionRollback(desc, j.Version)
} else {
desc = structs.DeploymentStatusDescriptionRollbackFailed(desc, j.Version, w.j.Version)
j = nil
}
} else {
desc = structs.DeploymentStatusDescriptionNoRollbackTarget(desc)
}

View File

@ -4322,6 +4322,12 @@ func DeploymentStatusDescriptionRollback(baseDescription string, jobVersion uint
return fmt.Sprintf("%s - rolling back to job version %d", baseDescription, jobVersion)
}
// DeploymentStatusDescriptionRollbackFailed is used to get the status description of
// a deployment when rolling back to an older job is not possible because it has the same specification
func DeploymentStatusDescriptionRollbackFailed(baseDescription string, jobVersion uint64, jobVersionOld uint64) string {
return fmt.Sprintf("%s - rolling back to job version %d failed because it had the same specification as job version %d ", baseDescription, jobVersion, jobVersionOld)
}
// DeploymentStatusDescriptionNoRollbackTarget is used to get the status description of
// a deployment when there is no target to rollback to but autorevet is desired.
func DeploymentStatusDescriptionNoRollbackTarget(baseDescription string) string {