Skip to content

Commit

Permalink
cli: forward request for job validation to nomad leader
Browse files Browse the repository at this point in the history
This PR changes the behavior of 'nomad job validate' to forward the
request to the nomad leader, rather than responding from any server.

This is because we need the leader when validating Vault tokens, since
the leader is the only server with an active vault client.
  • Loading branch information
shoenig committed Aug 9, 2022
1 parent 5833711 commit 1dc771f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/14065.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cli: Fixed a bug where job validation requeset was not sent to leader
```
14 changes: 9 additions & 5 deletions nomad/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,8 @@ func getSignalConstraint(signals []string) *structs.Constraint {
}
}

// Summary retrieves the summary of a job
func (j *Job) Summary(args *structs.JobSummaryRequest,
reply *structs.JobSummaryResponse) error {

// Summary retrieves the summary of a job.
func (j *Job) Summary(args *structs.JobSummaryRequest, reply *structs.JobSummaryResponse) error {
if done, err := j.srv.forward("Job.Summary", args, args, reply); done {
return err
}
Expand Down Expand Up @@ -511,8 +509,14 @@ func (j *Job) Summary(args *structs.JobSummaryRequest,
return j.srv.blockingRPC(&opts)
}

// Validate validates a job
// Validate validates a job.
//
// Must forward to the leader, because only the leader will have a live Vault
// client with which to validate vault tokens.
func (j *Job) Validate(args *structs.JobValidateRequest, reply *structs.JobValidateResponse) error {
if done, err := j.srv.forward("Job.Validate", args, args, reply); done {
return err
}
defer metrics.MeasureSince([]string{"nomad", "job", "validate"}, time.Now())

// defensive check; http layer and RPC requester should ensure namespaces are set consistently
Expand Down

0 comments on commit 1dc771f

Please sign in to comment.