Skip to content

Commit

Permalink
Merge pull request #255 from lminzhw/job_status
Browse files Browse the repository at this point in the history
init job status to Pending
  • Loading branch information
volcano-sh-bot authored Jun 28, 2019
2 parents 9efa246 + 6d4a3f7 commit 2ee41aa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/batch/v1alpha1/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ const (
PodGroupError JobEvent = "PodGroupError"
//ExecuteAction action issued event for each action
ExecuteAction JobEvent = "ExecuteAction"
//JobStatusError is generated if update job status failed
JobStatusError JobEvent = "JobStatusError"
)

// Event represent the phase of Job, e.g. pod-failed.
Expand Down
28 changes: 28 additions & 0 deletions pkg/controllers/job/job_controller_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ func (cc *Controller) createJob(jobInfo *apis.JobInfo, updateStatus state.Update
job := jobInfo.Job.DeepCopy()
glog.Infof("Current Version is: %d of job: %s/%s", job.Status.Version, job.Namespace, job.Name)

if err := cc.initJobStatus(job); err != nil {
cc.recorder.Event(job, v1.EventTypeWarning, string(vkv1.JobStatusError),
fmt.Sprintf("Failed to initialize job status, err: %v", err))
return err
}

if err := cc.pluginOnJobAdd(job); err != nil {
cc.recorder.Event(job, v1.EventTypeWarning, string(vkv1.PluginError),
fmt.Sprintf("Execute plugin when job add failed, err: %v", err))
Expand Down Expand Up @@ -523,3 +529,25 @@ func (cc *Controller) calcPGMinResources(job *vkv1.Job) *v1.ResourceList {

return &minAvailableTasksRes
}

func (cc *Controller) initJobStatus(job *vkv1.Job) error {
if job.Status.State.Phase != "" {
return nil
}

job.Status.State.Phase = vkv1.Pending
job.Status.MinAvailable = int32(job.Spec.MinAvailable)
job, err := cc.vkClients.BatchV1alpha1().Jobs(job.Namespace).UpdateStatus(job)
if err != nil {
glog.Errorf("Failed to update status of Job %v/%v: %v",
job.Namespace, job.Name, err)
return err
}
if err := cc.cache.Update(job); err != nil {
glog.Errorf("CreateJob - Failed to update Job %v/%v in cache: %v",
job.Namespace, job.Name, err)
return err
}

return nil
}

0 comments on commit 2ee41aa

Please sign in to comment.