Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

internal/server: Ensure on-demand runner config exists before start job #3054

Merged
merged 3 commits into from
Mar 2, 2022
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/3054.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
core: Fix panic where on-demand runner config was nil before starting task
```
11 changes: 11 additions & 0 deletions internal/server/singleprocess/service_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ func (s *service) wrapJobWithRunner(
if err != nil {
return nil, err
}
if od == nil {
return nil, status.Errorf(codes.FailedPrecondition,
"the on-demand runner config for id %q and job %q was nil",
source.OndemandRunner.Id, source.Id)
}

// Generate our job to start the ODR
startJob, runnerId, err := s.onDemandRunnerStartJob(ctx, source, od)
Expand Down Expand Up @@ -274,6 +279,12 @@ func (s *service) onDemandRunnerStartJob(
) (*pb.Job, string, error) {
log := hclog.FromContext(ctx)

if od == nil {
return nil, "", status.Errorf(codes.FailedPrecondition,
"the on-demand runner config for id %q and job %q was nil",
source.OndemandRunner.Id, source.Id)
}

// Generate a unique ID for the runner
runnerId, err := server.Id()
if err != nil {
Expand Down
17 changes: 16 additions & 1 deletion internal/server/singleprocess/service_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,21 @@ func TestServiceQueueJob_odr(t *testing.T) {
// Simplify writing tests
type Req = pb.QueueJobRequest

// Create with no ODR should error
queueResp, err := client.QueueJob(ctx, &Req{
Job: serverptypes.TestJobNew(t, &pb.Job{
Application: &pb.Ref_Application{
Application: "app",
Project: "proj",
},
OndemandRunner: &pb.Ref_OnDemandRunnerConfig{
Name: "fake",
},
}),
})
require.Error(err)
require.Empty(queueResp)

// Create an ODR profile
odr := serverptypes.TestOnDemandRunnerConfig(t, &pb.OnDemandRunnerConfig{
PluginType: "magic-carpet",
Expand All @@ -502,7 +517,7 @@ func TestServiceQueueJob_odr(t *testing.T) {
require.NoError(err)

// Create, should get an ID back
queueResp, err := client.QueueJob(ctx, &Req{
queueResp, err = client.QueueJob(ctx, &Req{
Job: serverptypes.TestJobNew(t, &pb.Job{
Application: &pb.Ref_Application{
Application: "app",
Expand Down