mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
Job.Scale should not result in job update or eval create if args.Count == nil
plus tests
This commit is contained in:
@@ -1595,18 +1595,20 @@ func TestJobs_ScaleAction(t *testing.T) {
|
||||
require.Contains(err.Error(), "not found")
|
||||
|
||||
// Register the job
|
||||
_, wm, err := jobs.Register(job, nil)
|
||||
regResp, wm, err := jobs.Register(job, nil)
|
||||
require.NoError(err)
|
||||
assertWriteMeta(t, wm)
|
||||
|
||||
// Perform scaling action
|
||||
newCount := groupCount + 1
|
||||
resp1, wm, err := jobs.Scale(id, groupName,
|
||||
scalingResp, wm, err := jobs.Scale(id, groupName,
|
||||
intToPtr(newCount), stringToPtr("need more instances"), nil, nil, nil)
|
||||
|
||||
require.NoError(err)
|
||||
require.NotNil(resp1)
|
||||
require.NotEmpty(resp1.EvalID)
|
||||
require.NotNil(scalingResp)
|
||||
require.NotEmpty(scalingResp.EvalID)
|
||||
require.NotEmpty(scalingResp.EvalCreateIndex)
|
||||
require.Greater(scalingResp.JobModifyIndex, regResp.JobModifyIndex)
|
||||
assertWriteMeta(t, wm)
|
||||
|
||||
// Query the job again
|
||||
@@ -1614,7 +1616,47 @@ func TestJobs_ScaleAction(t *testing.T) {
|
||||
require.NoError(err)
|
||||
require.Equal(*resp.TaskGroups[0].Count, newCount)
|
||||
|
||||
// TODO: check if reason is stored
|
||||
// TODO: check that scaling event was persisted
|
||||
}
|
||||
|
||||
func TestJobs_ScaleAction_Noop(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
|
||||
c, s := makeClient(t, nil, nil)
|
||||
defer s.Stop()
|
||||
jobs := c.Jobs()
|
||||
|
||||
id := "job-id/with\\troublesome:characters\n?&字\000"
|
||||
job := testJobWithScalingPolicy()
|
||||
job.ID = &id
|
||||
groupName := *job.TaskGroups[0].Name
|
||||
prevCount := *job.TaskGroups[0].Count
|
||||
|
||||
// Register the job
|
||||
regResp, wm, err := jobs.Register(job, nil)
|
||||
require.NoError(err)
|
||||
assertWriteMeta(t, wm)
|
||||
|
||||
// Perform scaling action
|
||||
scaleResp, wm, err := jobs.Scale(id, groupName,
|
||||
nil, stringToPtr("no count, just informative"), nil, nil, nil)
|
||||
|
||||
require.NoError(err)
|
||||
require.NotNil(scaleResp)
|
||||
require.Empty(scaleResp.EvalID)
|
||||
require.Empty(scaleResp.EvalCreateIndex)
|
||||
assertWriteMeta(t, wm)
|
||||
|
||||
// Query the job again
|
||||
resp, _, err := jobs.Info(*job.ID, nil)
|
||||
require.NoError(err)
|
||||
require.Equal(*resp.TaskGroups[0].Count, prevCount)
|
||||
require.Equal(regResp.JobModifyIndex, scaleResp.JobModifyIndex)
|
||||
require.Empty(scaleResp.EvalCreateIndex)
|
||||
require.Empty(scaleResp.EvalID)
|
||||
|
||||
// TODO: check that scaling event was persisted
|
||||
}
|
||||
|
||||
// TestJobs_ScaleStatus tests the /scale status endpoint for task group count
|
||||
|
||||
@@ -894,7 +894,7 @@ func (j *Job) Scale(args *structs.JobScaleRequest, reply *structs.JobRegisterRes
|
||||
return structs.NewErrRPCCoded(404, fmt.Sprintf("job %q not found", args.JobID))
|
||||
}
|
||||
|
||||
index := job.ModifyIndex
|
||||
jobModifyIndex := job.ModifyIndex
|
||||
if args.Count != nil {
|
||||
found := false
|
||||
for _, tg := range job.TaskGroups {
|
||||
@@ -917,22 +917,22 @@ func (j *Job) Scale(args *structs.JobScaleRequest, reply *structs.JobRegisterRes
|
||||
}
|
||||
|
||||
// Commit this update via Raft
|
||||
_, index, err = j.srv.raftApply(structs.JobRegisterRequestType, registerReq)
|
||||
_, jobModifyIndex, err = j.srv.raftApply(structs.JobRegisterRequestType, registerReq)
|
||||
if err != nil {
|
||||
j.logger.Error("job register for scale failed", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Populate the reply with job information
|
||||
reply.JobModifyIndex = index
|
||||
reply.JobModifyIndex = job.ModifyIndex
|
||||
reply.Index = job.ModifyIndex
|
||||
|
||||
// FINISH:
|
||||
// register the scaling event to the scaling_event table, once that exists
|
||||
|
||||
// If the job is periodic or parameterized, we don't create an eval.
|
||||
if job != nil && (job.IsPeriodic() || job.IsParameterized()) {
|
||||
if job != nil && (job.IsPeriodic() || job.IsParameterized()) || args.Count == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -946,7 +946,7 @@ func (j *Job) Scale(args *structs.JobScaleRequest, reply *structs.JobRegisterRes
|
||||
Type: structs.JobTypeService,
|
||||
TriggeredBy: structs.EvalTriggerScaling,
|
||||
JobID: args.JobID,
|
||||
JobModifyIndex: index,
|
||||
JobModifyIndex: jobModifyIndex,
|
||||
Status: structs.EvalStatusPending,
|
||||
CreateTime: now,
|
||||
ModifyTime: now,
|
||||
@@ -966,7 +966,7 @@ func (j *Job) Scale(args *structs.JobScaleRequest, reply *structs.JobRegisterRes
|
||||
// Populate the reply with eval information
|
||||
reply.EvalID = eval.ID
|
||||
reply.EvalCreateIndex = evalIndex
|
||||
reply.Index = evalIndex
|
||||
reply.Index = reply.EvalCreateIndex
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user