-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Making the API default missing values #2300
Conversation
67dd49f
to
47f7e2e
Compare
api/jobs.go
Outdated
if p.Spec != nil { | ||
p.SpecType = helper.StringToPtr(PeriodicSpecCron) | ||
} | ||
if p.ProhibitOverlap == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpecType?
j.Periodic.Canonicalize() | ||
} | ||
|
||
for _, tg := range j.TaskGroups { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Break these up into different functions
api/jobs.go
Outdated
} | ||
} else { | ||
if task.LogConfig.MaxFiles == nil { | ||
task.LogConfig.MaxFiles = helper.IntToPtr(10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fields should be handled separately
api/jobs.go
Outdated
if task.Vault != nil { | ||
if task.Vault.Env == nil { | ||
task.Vault.Env = helper.BoolToPtr(true) | ||
task.Vault.ChangeMode = helper.StringToPtr("restart") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be handled separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle changemode being signal but signal not being set?
api/jobs_test.go
Outdated
_, err := jobs.Validate(job, nil) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a failure case
var out structs.JobValidateResponse | ||
if err := s.agent.RPC("Job.Validate", &args, &out); err != nil { | ||
|
||
// Fall back to do local validation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set that the driver configs were not validated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default is false, so don't need it.
command/agent/job_endpoint.go
Outdated
@@ -111,6 +114,40 @@ func (s *HTTPServer) jobPlan(resp http.ResponseWriter, req *http.Request, | |||
return out, nil | |||
} | |||
|
|||
func (s *HTTPServer) ValidateJobRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { | |||
var validateRequest api.JobValidateRequest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that the request is PUT/POST
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be PUT
, we should check for POST
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well looks like client.Write
sets the method to PUT
.
command/agent/job_endpoint.go
Outdated
@@ -310,3 +347,86 @@ func (s *HTTPServer) jobDispatchRequest(resp http.ResponseWriter, req *http.Requ | |||
setIndex(resp, out.Index) | |||
return out, nil | |||
} | |||
|
|||
func (s *HTTPServer) apiJobToStructJob(job *api.Job) *structs.Job { | |||
if job.Priority == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not api.Canonicalize() and then just setting each field. It is probably also worth adding apiJobToStructJob which calls apiTaskGroupsToStructTaskGroups and so on.
command/plan.go
Outdated
@@ -129,12 +112,18 @@ func (c *PlanCommand) Run(args []string) int { | |||
} | |||
|
|||
// Force the region to be that of the job. | |||
if r := job.Region; r != "" { | |||
if r := *job.Region; r != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a nil pointer dereference since the API job has not been canonicalized
nomad/structs/structs.go
Outdated
|
||
// JobValidateResponse is the response from validate request | ||
type JobValidateResponse struct { | ||
DriverConfigValidated bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comments
api/jobs.go
Outdated
@@ -371,6 +487,11 @@ func (j *Job) AddPeriodicConfig(cfg *PeriodicConfig) *Job { | |||
return j | |||
} | |||
|
|||
// JobValidateRequest is used to validate a job | |||
type JobValidateRequest struct { | |||
Job *Job |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WriteRequest?
jobspec/parse.go
Outdated
Name: t.Name, | ||
Count: 1, | ||
EphemeralDisk: structs.DefaultEphemeralDisk(), | ||
Tasks: []*structs.Task{t}, | ||
EphemeralDisk: &api.EphemeralDisk{SizeMB: 300}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those should be pointers ^ (we decided on all of them being pointers)
jobspec/parse.go
Outdated
@@ -317,7 +324,7 @@ func parseGroups(result *structs.Job, list *ast.ObjectList) error { | |||
} | |||
|
|||
// Parse ephemeral disk | |||
g.EphemeralDisk = structs.DefaultEphemeralDisk() | |||
g.EphemeralDisk = &api.EphemeralDisk{SizeMB: 300} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointer ^
jobspec/parse.go
Outdated
} | ||
|
||
// Combine the parsed resources with a default resource block. | ||
min := structs.DefaultResources() | ||
min := &api.Resources{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a min resources for API
7ee7cad
to
57b5fdf
Compare
if j.JobModifyIndex == nil { | ||
j.JobModifyIndex = helper.Uint64ToPtr(0) | ||
} | ||
if j.Periodic != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar block for update strategy and parameterized?
} | ||
if tmpl.Perms == nil { | ||
tmpl.Perms = helper.StringToPtr("0644") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a case for if *tmpl.ChangeMode == "signal" && tmpl.ChangeSignal == nil { tmpl.ChangeSignal = helper.StringToPtr("SIGHUP") }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is set upper case the signal
api/tasks.go
Outdated
v.ChangeMode = helper.StringToPtr("restart") | ||
} | ||
if v.ChangeSignal == nil { | ||
v.ChangeSignal = helper.StringToPtr("sighup") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalize the signal both in that helper and put an else if it is set and upper case it
r.Networks = other.Networks | ||
} | ||
} | ||
|
||
type Port struct { | ||
Label string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make these pointers and give a default value to the mbits (10 seems fine)
command/agent/job_endpoint.go
Outdated
|
||
j.Constraints = make([]*structs.Constraint, len(job.Constraints)) | ||
for i, c := range job.Constraints { | ||
j.Constraints[i] = &structs.Constraint{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a method so it can be reused
api/tasks.go
Outdated
if g.RestartPolicy == nil { | ||
switch jobType { | ||
case "service", "system": | ||
g.RestartPolicy = &RestartPolicy{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make these pointers and add a merge method. Get the default and the user submitted one and merge them
command/validate.go
Outdated
|
||
// Check that the job is valid | ||
if err := job.Validate(); err != nil { | ||
if _, _, err := client.Jobs().Validate(job, nil); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a warning message in orange if the drivers were not validated
@@ -285,6 +285,25 @@ func (j *Job) Summary(args *structs.JobSummaryRequest, | |||
return j.srv.blockingRPC(&opts) | |||
} | |||
|
|||
// Validate validates a job | |||
func (j *Job) Validate(args *structs.JobValidateRequest, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTTP documentation
08ae0a4
to
e66827b
Compare
s.parseRegion(req, &args.Region) | ||
|
||
var out structs.JobValidateResponse | ||
if err := s.agent.RPC("Job.Validate", &args, &out); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do something with this err
even if no other errs happen?
Update: no need!
command/agent/job_endpoint.go
Outdated
} | ||
} | ||
} else { | ||
out.ValidationErrors = append(out.ValidationErrors, vErr.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't vErr nil here?
command/agent/job_endpoint.go
Outdated
// Fall back to do local validation | ||
args.Job.Canonicalize() | ||
if vErr := args.Job.Validate(); vErr != nil { | ||
if merr, ok := err.(*multierror.Error); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean vErr here?
jobspec/parse.go
Outdated
MaxFiles: helper.IntToPtr(10), | ||
MaxFileSizeMB: helper.IntToPtr(10), | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use api.DefaultLogConfig()
?
e66827b
to
5575e54
Compare
bd7dbc7
to
14052ed
Compare
fd28fad
to
a2d7651
Compare
91dc597
to
6debb3e
Compare
Hi folks! It seems this PR changes If all this is accurate, I think we should call this out in the "Backwards Incompatibilities" section of the changelog. |
@phinze Hey this was not suppose to happen! It was an oversight and 0.5.5 RC2 will restore the original behavior. |
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
No description provided.