Skip to content
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

scale: fixed a bug where evals could be created with wrong type. #17092

Merged
merged 2 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/17092.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
scale: Fixed a bug where evals could be created with the wrong type
```
2 changes: 1 addition & 1 deletion nomad/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ func (j *Job) Scale(args *structs.JobScaleRequest, reply *structs.JobRegisterRes
ID: uuid.Generate(),
Namespace: namespace,
Priority: job.Priority, // Safe as nil check performed above.
Type: structs.JobTypeService,
Type: job.Type,
TriggeredBy: structs.EvalTriggerScaling,
JobID: args.JobID,
JobModifyIndex: reply.JobModifyIndex,
Expand Down
38 changes: 38 additions & 0 deletions nomad/job_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7868,6 +7868,44 @@ func TestJobEndpoint_Scale_SystemJob(t *testing.T) {
`400,cannot scale jobs of type "system"`)
}

func TestJobEndpoint_Scale_BatchJob(t *testing.T) {
ci.Parallel(t)

testServer, testServerCleanup := TestServer(t, nil)
defer testServerCleanup()
codec := rpcClient(t, testServer)
testutil.WaitForLeader(t, testServer.RPC)
state := testServer.fsm.State()

mockBatchJob := mock.BatchJob()
must.NoError(t, state.UpsertJob(structs.MsgTypeTestSetup, 10, nil, mockBatchJob))

scaleReq := &structs.JobScaleRequest{
JobID: mockBatchJob.ID,
Target: map[string]string{
structs.ScalingTargetGroup: mockBatchJob.TaskGroups[0].Name,
},
Count: pointer.Of(int64(13)),
WriteRequest: structs.WriteRequest{
Region: DefaultRegion,
Namespace: mockBatchJob.Namespace,
},
}
var resp structs.JobRegisterResponse
must.NoError(t, msgpackrpc.CallWithCodec(codec, "Job.Scale", scaleReq, &resp))

// Pull the generated evaluation from state and ensure the detailed type
// matches the jobspec.
testFMSSnapshot, err := testServer.fsm.State().Snapshot()
must.NoError(t, err)

scaleEval, err := testFMSSnapshot.EvalByID(nil, resp.EvalID)
must.NoError(t, err)
must.Eq(t, resp.EvalID, scaleEval.ID)
must.Eq(t, mockBatchJob.ID, scaleEval.JobID)
must.Eq(t, mockBatchJob.Type, scaleEval.Type)
}

func TestJobEndpoint_InvalidCount(t *testing.T) {
ci.Parallel(t)
require := require.New(t)
Expand Down