@@ -218,9 +218,10 @@ func GetClusterSecret(ctx context.Context, kubeFactory kube.Factory, namespace s
218
218
219
219
func WaitForJob (ctx context.Context , f kube.Factory , ns , jobName string ) error {
220
220
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 ,
224
225
Resources : []kube.Resource {
225
226
{
226
227
Name : jobName ,
@@ -236,28 +237,30 @@ func WaitForJob(ctx context.Context, f kube.Factory, ns, jobName string) error {
236
237
return false , err
237
238
}
238
239
240
+ totalRetries := * j .Spec .BackoffLimit + 1
239
241
if j .Status .Failed > attempt {
240
242
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 )
242
244
printJobLogs (ctx , cs , j )
243
245
} else if j .Status .Succeeded == 1 {
244
246
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 )
246
248
printJobLogs (ctx , cs , j )
247
249
}
248
250
249
251
for _ , cond := range j .Status .Conditions {
250
252
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 )
252
254
break
253
255
}
254
256
}
255
257
256
- return j .Status .Succeeded == 1 || j .Status .Failed == * j . Spec . BackoffLimit , err
258
+ return j .Status .Succeeded == 1 || j .Status .Failed == totalRetries , jobErr
257
259
},
258
260
},
259
261
},
260
262
})
263
+ return jobErr
261
264
}
262
265
263
266
func printJobLogs (ctx context.Context , client kubernetes.Interface , job * batchv1.Job ) {
0 commit comments