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

Abstract a common pod delete func #89

Merged
merged 1 commit into from
Apr 18, 2019
Merged
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
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
}