@@ -218,9 +218,10 @@ func GetClusterSecret(ctx context.Context, kubeFactory kube.Factory, namespace s
218218
219219func WaitForJob (ctx context.Context , f kube.Factory , ns , jobName string ) error {
220220 var attempt int32
221- return f .Wait (ctx , & kube.WaitOptions {
222- Interval : time .Second * 10 ,
223- Timeout : time .Minute * 11 , // BackOffLimit of 6 is a total of 630s, or 10m30s
221+ var jobErr error
222+ _ = f .Wait (ctx , & kube.WaitOptions {
223+ Interval : time .Second * 5 ,
224+ Timeout : time .Minute ,
224225 Resources : []kube.Resource {
225226 {
226227 Name : jobName ,
@@ -236,28 +237,30 @@ func WaitForJob(ctx context.Context, f kube.Factory, ns, jobName string) error {
236237 return false , err
237238 }
238239
240+ totalRetries := * j .Spec .BackoffLimit + 1
239241 if j .Status .Failed > attempt {
240242 attempt = j .Status .Failed
241- log .G (ctx ).Warnf ("Attempt #%d/%d failed:" , attempt , * j . Spec . BackoffLimit )
243+ log .G (ctx ).Warnf ("Attempt #%d/%d failed:" , attempt , totalRetries )
242244 printJobLogs (ctx , cs , j )
243245 } else if j .Status .Succeeded == 1 {
244246 attempt += 1
245- log .G (ctx ).Infof ("Attempt #%d/%d succeeded:" , attempt , * j . Spec . BackoffLimit )
247+ log .G (ctx ).Infof ("Attempt #%d/%d succeeded:" , attempt , totalRetries )
246248 printJobLogs (ctx , cs , j )
247249 }
248250
249251 for _ , cond := range j .Status .Conditions {
250252 if cond .Type == batchv1 .JobFailed {
251- err = fmt .Errorf ("add-cluster-job failed after %d attempts " , j .Status .Failed )
253+ jobErr = fmt .Errorf ("add-cluster-job failed after %d attempt(s) " , j .Status .Failed )
252254 break
253255 }
254256 }
255257
256- return j .Status .Succeeded == 1 || j .Status .Failed == * j . Spec . BackoffLimit , err
258+ return j .Status .Succeeded == 1 || j .Status .Failed == totalRetries , jobErr
257259 },
258260 },
259261 },
260262 })
263+ return jobErr
261264}
262265
263266func printJobLogs (ctx context.Context , client kubernetes.Interface , job * batchv1.Job ) {
0 commit comments