Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: output the modify index after planning #507

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions internal/runner/job/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Loading