mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 08:55:43 +03:00
job region defaults to client node region if 'global' or none provided (#6064)
This commit is contained in:
@@ -141,12 +141,16 @@ func (s *HTTPServer) jobPlan(resp http.ResponseWriter, req *http.Request,
|
||||
return nil, CodedError(400, "Job ID does not match")
|
||||
}
|
||||
|
||||
// Http region takes precedence over hcl region
|
||||
// Region in http request query param takes precedence over region in job hcl config
|
||||
if args.WriteRequest.Region != "" {
|
||||
args.Job.Region = helper.StringToPtr(args.WriteRequest.Region)
|
||||
}
|
||||
// If 'global' region is specified or if no region is given,
|
||||
// default to region of the node you're submitting to
|
||||
if args.Job.Region == nil || *args.Job.Region == "" || *args.Job.Region == api.GlobalRegion {
|
||||
args.Job.Region = &s.agent.config.Region
|
||||
}
|
||||
|
||||
// If no region given, region is canonicalized to 'global'
|
||||
sJob := ApiJobToStructJob(args.Job)
|
||||
|
||||
planReq := structs.JobPlanRequest{
|
||||
@@ -157,6 +161,8 @@ func (s *HTTPServer) jobPlan(resp http.ResponseWriter, req *http.Request,
|
||||
Region: sJob.Region,
|
||||
},
|
||||
}
|
||||
// parseWriteRequest overrides Namespace, Region and AuthToken
|
||||
// based on values from the original http request
|
||||
s.parseWriteRequest(req, &planReq.WriteRequest)
|
||||
planReq.Namespace = sJob.Namespace
|
||||
|
||||
@@ -384,12 +390,16 @@ func (s *HTTPServer) jobUpdate(resp http.ResponseWriter, req *http.Request,
|
||||
return nil, CodedError(400, "Job ID does not match name")
|
||||
}
|
||||
|
||||
// Http region takes precedence over hcl region
|
||||
// Region in http request query param takes precedence over region in job hcl config
|
||||
if args.WriteRequest.Region != "" {
|
||||
args.Job.Region = helper.StringToPtr(args.WriteRequest.Region)
|
||||
}
|
||||
// If 'global' region is specified or if no region is given,
|
||||
// default to region of the node you're submitting to
|
||||
if args.Job.Region == nil || *args.Job.Region == "" || *args.Job.Region == api.GlobalRegion {
|
||||
args.Job.Region = &s.agent.config.Region
|
||||
}
|
||||
|
||||
// If no region given, region is canonicalized to 'global'
|
||||
sJob := ApiJobToStructJob(args.Job)
|
||||
|
||||
regReq := structs.JobRegisterRequest{
|
||||
@@ -402,6 +412,8 @@ func (s *HTTPServer) jobUpdate(resp http.ResponseWriter, req *http.Request,
|
||||
AuthToken: args.WriteRequest.SecretID,
|
||||
},
|
||||
}
|
||||
// parseWriteRequest overrides Namespace, Region and AuthToken
|
||||
// based on values from the original http request
|
||||
s.parseWriteRequest(req, ®Req.WriteRequest)
|
||||
regReq.Namespace = sJob.Namespace
|
||||
|
||||
|
||||
@@ -493,11 +493,17 @@ func TestHTTP_JobUpdateRegion(t *testing.T) {
|
||||
ExpectedRegion: "north-america",
|
||||
},
|
||||
{
|
||||
Name: "falls back to default if no region is provided",
|
||||
Name: "defaults to node region global if no region is provided",
|
||||
ConfigRegion: "",
|
||||
APIRegion: "",
|
||||
ExpectedRegion: "global",
|
||||
},
|
||||
{
|
||||
Name: "defaults to node region not-global if no region is provided",
|
||||
ConfigRegion: "",
|
||||
APIRegion: "",
|
||||
ExpectedRegion: "not-global",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
||||
Reference in New Issue
Block a user