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

fix: OnAdd() panics when called for running job #12

Merged
merged 1 commit into from
Jan 31, 2024
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
5 changes: 1 addition & 4 deletions pkg/controller/job_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,12 @@ func (s *JobScheduler) isJobRunning(logger logr.Logger, jobID string, job *batch
return s.kubernetesMajorVersion, s.kubernetesMinorVersion
})

if running {
s.current[jobID].Running = true
}

return running
}

func (s *JobScheduler) handleInProgress(logger logr.Logger, jobID string, job *batchv1.Job) {
if s.isJobRunning(logger, jobID, job) {
s.current[jobID].Running = true
logger.Info("Job is running", "for", time.Since(job.Status.StartTime.Time))
return
}
Expand Down
27 changes: 26 additions & 1 deletion pkg/controller/job_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Test__JobScheduler(t *testing.T) {

require.NoError(t, err)

t.Run("job is loaded on startup", func(t *testing.T) {
t.Run("non-running job is loaded on startup", func(t *testing.T) {
clear(scheduler.current)
defer clear(scheduler.current)

Expand All @@ -62,6 +62,31 @@ func Test__JobScheduler(t *testing.T) {
require.True(t, scheduler.IsCurrentJob(jobID))
})

t.Run("running job is loaded on startup", func(t *testing.T) {
clear(scheduler.current)
defer clear(scheduler.current)

jobID := randJobID()
require.False(t, scheduler.IsCurrentJob(jobID))

ready := int32(1)
j := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
config.JobIDLabel: jobID,
config.AgentTypeLabel: agentType.AgentTypeName,
},
},
Status: batchv1.JobStatus{
Ready: &ready,
},
}

scheduler.OnAdd(j, false)
require.True(t, scheduler.IsCurrentJob(jobID))
require.True(t, scheduler.current[jobID].Running)
})

t.Run("job is created", func(t *testing.T) {
clear(scheduler.current)
defer clear(scheduler.current)
Expand Down