diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cd88d62..4af1008f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ BUG FIXES: * runner: updated to hashicorp/nomad@1.7.2 to support `action` blocks [[GH-476](https://github.com/hashicorp/nomad-pack/pull/476)] +IMPROVEMENTS: + +* cli: output the modify index after planning [[GH-507](https://github.com/hashicorp/nomad-pack/pull/507)] + ## 0.1.0 (October 31, 2023) * **Generate Variable Override Files for Packs** - With diff --git a/internal/runner/job/plan.go b/internal/runner/job/plan.go index 30129187..2f75b637 100644 --- a/internal/runner/job/plan.go +++ b/internal/runner/job/plan.go @@ -13,6 +13,17 @@ import ( "github.com/hashicorp/nomad-pack/terminal" ) +const ( + jobModifyIndexHelp = `To submit the job with version verification run: + +nomad-pack run %s --check-index=%d [options] + +When running the job with the check-index flag, the job will only be run if the +job modify index given matches the server-side version. If the index has +changed, another user has modified the job and the plan's results are +potentially invalid.` +) + // PlanDeployment satisfies the PlanDeployment function of the runner.Runner // interface. func (r *Runner) PlanDeployment(ui terminal.UI, errCtx *errors.UIErrorContext) (int, []*errors.WrappedUIContext) { @@ -58,6 +69,7 @@ func (r *Runner) PlanDeployment(ui terminal.UI, errCtx *errors.UIErrorContext) ( } exitCode = runner.HigherPlanCode(exitCode, r.outputPlannedJob(ui, parsedJob.Job(), planResponse)) + r.formatJobModifyIndex(planResponse.JobModifyIndex, ui) } if outputErrors != nil || len(outputErrors) > 0 { @@ -138,6 +150,12 @@ func (r *Runner) outputPlannedJob(ui terminal.UI, job *api.Job, resp *api.JobPla return getExitCode(resp) } +// formatJobModifyIndex produces a help string that displays the job modify +// index and how to submit a job with it. +func (r *Runner) formatJobModifyIndex(jobModifyIndex uint64, ui terminal.UI) { + ui.AppendToRow(jobModifyIndexHelp, r.runnerCfg.PackName, jobModifyIndex, terminal.WithStyle(terminal.BoldStyle)) +} + func getExitCode(resp *api.JobPlanResponse) int { for _, d := range resp.Annotations.DesiredTGUpdates { if d.Stop+d.Place+d.Migrate+d.DestructiveUpdate+d.Canary > 0 {