Skip to content

Commit

Permalink
Merge pull request #89 from hzxuzhonghu/common-delete
Browse files Browse the repository at this point in the history
Abstract a common pod delete func
  • Loading branch information
Klaus Ma authored Apr 18, 2019
2 parents ad821bf + fc6c2f4 commit dba21aa
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions pkg/controllers/job/job_controller_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,40 +68,32 @@ func (cc *Controller) killJob(jobInfo *apis.JobInfo, nextState state.NextStateFn

switch pod.Status.Phase {
case v1.PodRunning:
err := cc.kubeClients.CoreV1().Pods(pod.Namespace).Delete(pod.Name, nil)
err := cc.deleteJobPod(job.Name, pod)
if err != nil {
running++
glog.Errorf("Failed to delete pod %s for Job %s, err %#v",
pod.Name, job.Name, err)
errs = append(errs, err)
continue
}
terminating++
case v1.PodPending:
err := cc.kubeClients.CoreV1().Pods(pod.Namespace).Delete(pod.Name, nil)
err := cc.deleteJobPod(job.Name, pod)
if err != nil {
pending++
glog.Errorf("Failed to delete pod %s for Job %s, err %#v",
pod.Name, job.Name, err)
errs = append(errs, err)
continue
}
terminating++
case v1.PodSucceeded:
err := cc.kubeClients.CoreV1().Pods(pod.Namespace).Delete(pod.Name, nil)
err := cc.deleteJobPod(job.Name, pod)
if err != nil {
succeeded++
glog.Errorf("Failed to delete pod %s for Job %s, err %#v",
pod.Name, job.Name, err)
errs = append(errs, err)
continue
}
case v1.PodFailed:
err := cc.kubeClients.CoreV1().Pods(pod.Namespace).Delete(pod.Name, nil)
err := cc.deleteJobPod(job.Name, pod)
if err != nil {
failed++
glog.Errorf("Failed to delete pod %s for Job %s, err %#v",
pod.Name, job.Name, err)
errs = append(errs, err)
continue
}
Expand Down Expand Up @@ -294,9 +286,9 @@ func (cc *Controller) syncJob(jobInfo *apis.JobInfo, nextState state.NextStateFn
for _, pod := range podToDelete {
go func(pod *v1.Pod) {
defer waitDeletionGroup.Done()
err := cc.kubeClients.CoreV1().Pods(pod.Namespace).Delete(pod.Name, nil)
err := cc.deleteJobPod(job.Name, pod)
if err != nil {
// Failed to create Pod, waitCreationGroup a moment and then create it again
// Failed to delete Pod, waitCreationGroup a moment and then create it again
// This is to ensure all podsMap under the same Job created
// So gang-scheduling could schedule the Job successfully
glog.Errorf("Failed to delete pod %s for Job %s, err %#v",
Expand Down Expand Up @@ -504,3 +496,15 @@ func (cc *Controller) createPodGroupIfNotExist(job *vkv1.Job) error {

return nil
}

func (cc *Controller) deleteJobPod(jobName string, pod *v1.Pod) error {
err := cc.kubeClients.CoreV1().Pods(pod.Namespace).Delete(pod.Name, nil)
if err != nil && !apierrors.IsNotFound(err) {
glog.Errorf("Failed to delete pod %s/%s for Job %s, err %#v",
pod.Namespace, pod.Name, jobName, err)

return err
}

return nil
}

0 comments on commit dba21aa

Please sign in to comment.