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

cli: check deployment exists before monitoring #10757

Merged
merged 3 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 2 deletions command/deployment_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ UPDATE:
for {
deploy, meta, err := client.Deployments().Info(deployID, &q)
if err != nil {
d.Append(glint.Style(
d.Append(glint.Layout(glint.Style(
glint.Text(fmt.Sprintf("%s: Error fetching deployment", formatTime(time.Now()))),
glint.Color("red"),
))
)).MarginLeft(4))
d.RenderFrame()
return
}
Expand Down
26 changes: 14 additions & 12 deletions command/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,21 +285,23 @@ func (m *monitor) monitor(evalID string) int {
break
}

// Monitor the deployment
// Monitor the deployment if it exists
dID := m.state.deployment
m.ui.Info(fmt.Sprintf("%s: Monitoring deployment %q", formatTime(time.Now()), limit(dID, m.length)))
if len(dID) > 0 {
isabeldepapel marked this conversation as resolved.
Show resolved Hide resolved
m.ui.Info(fmt.Sprintf("%s: Monitoring deployment %q", formatTime(time.Now()), limit(dID, m.length)))

var verbose bool
if m.length == fullId {
verbose = true
} else {
verbose = false
}
var verbose bool
if m.length == fullId {
verbose = true
} else {
verbose = false
}

meta := new(Meta)
meta.Ui = m.ui
cmd := &DeploymentStatusCommand{Meta: *meta}
cmd.monitor(m.client, dID, 0, verbose)
meta := new(Meta)
meta.Ui = m.ui
cmd := &DeploymentStatusCommand{Meta: *meta}
cmd.monitor(m.client, dID, 0, verbose)
}

// Treat scheduling failures specially using a dedicated exit code.
// This makes it easier to detect failures from the CLI.
Expand Down
19 changes: 17 additions & 2 deletions website/content/docs/commands/job/run.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ downloaded and read from URL specified. Nomad downloads the job file using

By default, on successful job submission the run command will enter an
interactive monitor and display log information detailing the scheduling
decisions, placement information, and [deployment status] for the provided job.
The monitor will exit after scheduling and deployment have finished or failed.
decisions, placement information, and [deployment status] for the provided job
if applicable ([`batch`] and [`system`] jobs don't create deployments). The monitor will
exit after scheduling and deployment have finished or failed.

On successful job submission and scheduling, exit code 0 will be returned. If
there are job placement issues encountered (unsatisfiable constraints, resource
Expand Down Expand Up @@ -204,8 +205,22 @@ $ nomad job run failing.nomad
cache 1 0 0 0 N/A
```

Sample output when scheduling a system job, which doesn't create a deployment:

```shell-session
$ nomad job run example.nomad
==> 2021-06-14T09:25:08-07:00: Monitoring evaluation "88a91284"
2021-06-14T09:25:08-07:00: Evaluation triggered by job "example"
2021-06-14T09:25:08-07:00: Allocation "03501797" created: node "7849439f", group "cache"
==> 2021-06-14T09:25:09-07:00: Monitoring evaluation "88a91284"
2021-06-14T09:25:09-07:00: Evaluation status changed: "pending" -> "complete"
==> 2021-06-14T09:25:09-07:00: Evaluation "88a91284" finished with status "complete"
```

[`go-getter`]: https://github.com/hashicorp/go-getter
[deployment status]: /docs/commands/deployment#status
[`batch`]: /docs/schedulers#batch
[`system`]: /docs/schedulers#system
[`job plan` command]: /docs/commands/job/plan
[eval status]: /docs/commands/eval-status
[job specification]: /docs/job-specification
Expand Down