Skip to content

Commit

Permalink
Adds comment to handleRollbackValidity method and other small test re…
Browse files Browse the repository at this point in the history
…adability fixes.
  • Loading branch information
preetapan committed Nov 3, 2017
1 parent f92e564 commit 04feeef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 9 additions & 6 deletions nomad/deploymentwatcher/deployment_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,20 @@ func (w *deploymentWatcher) SetAllocHealth(
w.setLatestEval(index)
return nil
}
func (w *deploymentWatcher) handleRollbackValidity(j *structs.Job, desc string) (*structs.Job, string) {

// handleRollbackValidity checks if the job being rolled back to has the same spec as the existing job
// Returns a modified description and job accordingly.
func (w *deploymentWatcher) handleRollbackValidity(rollbackJob *structs.Job, desc string) (*structs.Job, string) {
// Only rollback if job being changed has a different spec.
// This prevents an infinite revert cycle when a previously stable version of the job fails to start up during a rollback
// If the job we are trying to rollback to is identical to the current job, we stop because the rollback will not succeed.
if w.j.SpecChanged(j) {
desc = structs.DeploymentStatusDescriptionRollback(desc, j.Version)
if w.j.SpecChanged(rollbackJob) {
desc = structs.DeploymentStatusDescriptionRollback(desc, rollbackJob.Version)
} else {
desc = structs.DeploymentStatusDescriptionRollbackNoop(desc, j.Version)
j = nil
desc = structs.DeploymentStatusDescriptionRollbackNoop(desc, rollbackJob.Version)
rollbackJob = nil
}
return j, desc
return rollbackJob, desc
}

func (w *deploymentWatcher) PromoteDeployment(
Expand Down
4 changes: 1 addition & 3 deletions nomad/deploymentwatcher/deployments_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,7 @@ func TestDeploymentWatcher_RollbackFailed(t *testing.T) {

// verify that the job version hasn't changed after upsert
m.state.JobByID(nil, structs.DefaultNamespace, j.ID)
if j.Version != 0 {
t.Fatalf("Expected job version 0 but got %v", j.Version)
}
assert.Equal(uint64(0), j.Version, "Expected job version 0 but got ", j.Version)
}

// Test evaluations are batched between watchers
Expand Down

0 comments on commit 04feeef

Please sign in to comment.