Skip to content

Commit

Permalink
GetPodsForJob filter the pod list owned by job
Browse files Browse the repository at this point in the history
Signed-off-by: yowenter <[email protected]>
  • Loading branch information
yowenter committed Apr 26, 2023
1 parent 8a066f9 commit 7e72fef
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions pkg/common/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ func ConvertServiceList(list []corev1.Service) []*corev1.Service {
return ret
}

// ConvertPodList convert pod list to pod pointer list
func ConvertPodList(list []corev1.Pod) []*corev1.Pod {
// JobControlledPodList filter pod list owned by the job.
func JobControlledPodList(list []corev1.Pod, job metav1.Object) []*corev1.Pod {
if list == nil {
return nil
}
ret := make([]*corev1.Pod, 0, len(list))
for i := range list {
if !metav1.IsControlledBy(&list[i], job) {
continue
}
ret = append(ret, &list[i])
}
return ret
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller.v1/mxnet/mxjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (r *MXJobReconciler) GetPodsForJob(obj interface{}) ([]*corev1.Pod, error)
if err != nil {
return nil, err
}
return util.ConvertPodList(podlist.Items), nil
return util.JobControlledPodList(podlist.Items, job), nil
}

func (r *MXJobReconciler) GetServicesForJob(job interface{}) ([]*corev1.Service, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller.v1/paddlepaddle/paddlepaddle_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (r *PaddleJobReconciler) GetPodsForJob(obj interface{}) ([]*corev1.Pod, err
return nil, err
}

return util.ConvertPodList(podlist.Items), nil
return util.JobControlledPodList(podlist.Items, job), nil
}

func (r *PaddleJobReconciler) GetServicesForJob(obj interface{}) ([]*corev1.Service, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller.v1/pytorch/pytorchjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (r *PyTorchJobReconciler) GetPodsForJob(obj interface{}) ([]*corev1.Pod, er
return nil, err
}

return util.ConvertPodList(podlist.Items), nil
return util.JobControlledPodList(podlist.Items, job), nil
}

func (r *PyTorchJobReconciler) GetServicesForJob(obj interface{}) ([]*corev1.Service, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller.v1/tensorflow/tfjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (r *TFJobReconciler) GetPodsForJob(jobObject interface{}) ([]*corev1.Pod, e
return nil, err
}

pods := util.ConvertPodList(podlist.Items)
pods := util.JobControlledPodList(podlist.Items, job)

// If any adoptions are attempted, we should first recheck for deletion
// with an uncached quorum read sometime after listing Pods (see #42639).
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller.v1/xgboost/xgboostjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (r *XGBoostJobReconciler) GetPodsForJob(obj interface{}) ([]*corev1.Pod, er
return nil, err
}

return util.ConvertPodList(podlist.Items), nil
return util.JobControlledPodList(podlist.Items, job), nil
}

// GetServicesForJob returns the services managed by the job. This can be achieved by selecting services using label key "job-name"
Expand Down

0 comments on commit 7e72fef

Please sign in to comment.