Skip to content

Commit

Permalink
plan: inform user if a deployment will be created
Browse files Browse the repository at this point in the history
Just a proof of concept because the plan output when deployments are
involved is a bit non-obvious. When updating a job with count=3, the
plan will only show the first step of the deployment (as determined by
update.max_parallel):

```
+/- Job: "sleeper"
+/- Task Group: "sleeper" (1 create/destroy update, 2 ignore)
  +/- Task: "sleeper" (forces create/destroy update)
      +/- Config {
```

This hack plumbs through whether a deployment was attached to the plan.
Obviously the output and field names need improving. For backward
compatibility we probably shouldn't output _anything_ if there isn't a
deployment, but this PoC includes a message for either case for ease of
testing/demonstration.
  • Loading branch information
schmichael committed Dec 10, 2024
1 parent 3bc2c07 commit bf85de6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,7 @@ type JobPlanResponse struct {
CreatedEvals []*Evaluation
Diff *JobDiff
Annotations *PlanAnnotations
CauseDeployment bool
FailedTGAllocs map[string]*AllocationMetric
NextPeriodicLaunch time.Time

Expand Down
6 changes: 6 additions & 0 deletions command/job_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ func (c *JobPlanCommand) outputPlannedJob(job *api.Job, resp *api.JobPlanRespons
c.Colorize().Color(strings.TrimSpace(formatJobDiff(resp.Diff, verbose)))))
}

if resp.CauseDeployment {
c.Ui.Output("deployment time!")
} else {
c.Ui.Output("no deployment")
}

// Print the scheduler dry-run output
c.Ui.Output(c.Colorize().Color("[bold]Scheduler dry-run:[reset]"))
c.Ui.Output(c.Colorize().Color(formatDryRun(resp, job)))
Expand Down
1 change: 1 addition & 0 deletions nomad/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,7 @@ func (j *Job) Plan(args *structs.JobPlanRequest, reply *structs.JobPlanResponse)
reply.FailedTGAllocs = updatedEval.FailedTGAllocs
reply.JobModifyIndex = index
reply.Annotations = annotations
reply.CauseDeployment = planner.Plans[0].Deployment != nil
reply.CreatedEvals = planner.CreateEvals
reply.Index = index
return nil
Expand Down
4 changes: 4 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,10 @@ type JobPlanResponse struct {
// causes an in-place update or create/destroy
Diff *JobDiff

// CauseDeployment is true if the plan causes a deployment to be created or
// modified.
CauseDeployment bool

// NextPeriodicLaunch is the time duration till the job would be launched if
// submitted.
NextPeriodicLaunch time.Time
Expand Down

0 comments on commit bf85de6

Please sign in to comment.