Skip to content

Commit 970afa3

Browse files
committed
Add check if the backoff limit is finished
1 parent 11c82c1 commit 970afa3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

controller.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func NewController(
111111
if newJob.CreationTimestamp.Sub(serverStartTime).Seconds() < 0 {
112112
return
113113
}
114+
114115
if notifiedJobs[newJob.Name] == true {
115116
return
116117
}
@@ -159,7 +160,8 @@ func NewController(
159160
}
160161
}
161162
klog.V(4).Infof("Job succeeded log: %v", jobLogStr)
162-
notifiedJobs[newJob.Name] = true
163+
notifiedJobs[newJob.Name] = isComplatedJob(kubeclientset, newJob)
164+
163165
} else if newJob.Status.Failed == intTrue {
164166
klog.Infof("Job failed: %v", newJob.Status)
165167
jobPod, err := getPodFromControllerUID(kubeclientset, newJob)
@@ -201,7 +203,8 @@ func NewController(
201203
klog.Errorf("Fail event subscribe.: %v", err)
202204
}
203205
}
204-
notifiedJobs[newJob.Name] = true
206+
notifiedJobs[newJob.Name] = isComplatedJob(kubeclientset, newJob)
207+
205208
}
206209

207210
}, DeleteFunc: func(obj interface{}) {
@@ -231,6 +234,22 @@ func (c *Controller) Run(threadiness int, stopCh <-chan struct{}) error {
231234
return nil
232235
}
233236

237+
func isComplatedJob(kubeclientset kubernetes.Interface, job *batchv1.Job) bool {
238+
labelSelector := metav1.LabelSelector{MatchLabels: map[string]string{searchLabel: string(job.UID)}}
239+
jobPodList, err := kubeclientset.CoreV1().Pods(job.Namespace).List(context.TODO(), metav1.ListOptions{
240+
LabelSelector: labels.Set(labelSelector.MatchLabels).String(),
241+
Limit: int64(*job.Spec.BackoffLimit),
242+
})
243+
244+
if err != nil {
245+
return true
246+
}
247+
if jobPodList.Size() != int(*job.Spec.BackoffLimit) {
248+
return false
249+
}
250+
return true
251+
}
252+
234253
func getPodFromControllerUID(kubeclientset kubernetes.Interface, job *batchv1.Job) (corev1.Pod, error) {
235254
labelSelector := metav1.LabelSelector{MatchLabels: map[string]string{searchLabel: string(job.UID)}}
236255
jobPodList, err := kubeclientset.CoreV1().Pods(job.Namespace).List(context.TODO(), metav1.ListOptions{

0 commit comments

Comments
 (0)