@@ -66,38 +66,20 @@ func (cc *Controller) killJob(jobInfo *apis.JobInfo, nextState state.NextStateFn
66
66
continue
67
67
}
68
68
69
- switch pod .Status .Phase {
70
- case v1 .PodRunning :
71
- err := cc .deleteJobPod (job .Name , pod )
72
- if err != nil {
73
- running ++
74
- errs = append (errs , err )
75
- continue
76
- }
69
+ if err := cc .deleteJobPod (job .Name , pod ); err == nil {
77
70
terminating ++
78
- case v1 .PodPending :
79
- err := cc .deleteJobPod (job .Name , pod )
80
- if err != nil {
71
+ } else {
72
+ errs = append (errs , err )
73
+ switch pod .Status .Phase {
74
+ case v1 .PodRunning :
75
+ running ++
76
+ case v1 .PodPending :
81
77
pending ++
82
- errs = append (errs , err )
83
- continue
84
- }
85
- terminating ++
86
- case v1 .PodSucceeded :
87
- err := cc .deleteJobPod (job .Name , pod )
88
- if err != nil {
78
+ case v1 .PodSucceeded :
89
79
succeeded ++
90
- errs = append (errs , err )
91
- continue
92
- }
93
- case v1 .PodFailed :
94
- err := cc .deleteJobPod (job .Name , pod )
95
- if err != nil {
80
+ case v1 .PodFailed :
96
81
failed ++
97
- errs = append (errs , err )
98
- continue
99
82
}
100
- terminating ++
101
83
}
102
84
}
103
85
}
@@ -220,32 +202,23 @@ func (cc *Controller) syncJob(jobInfo *apis.JobInfo, nextState state.NextStateFn
220
202
}
221
203
podToCreate = append (podToCreate , newPod )
222
204
} else {
205
+ delete (pods , podName )
223
206
if pod .DeletionTimestamp != nil {
224
207
glog .Infof ("Pod <%s/%s> is terminating" , pod .Namespace , pod .Name )
225
208
terminating ++
226
- delete (pods , podName )
227
209
continue
228
210
}
229
211
230
212
switch pod .Status .Phase {
231
213
case v1 .PodPending :
232
- if pod .DeletionTimestamp != nil {
233
- terminating ++
234
- } else {
235
- pending ++
236
- }
214
+ pending ++
237
215
case v1 .PodRunning :
238
- if pod .DeletionTimestamp != nil {
239
- terminating ++
240
- } else {
241
- running ++
242
- }
216
+ running ++
243
217
case v1 .PodSucceeded :
244
218
succeeded ++
245
219
case v1 .PodFailed :
246
220
failed ++
247
221
}
248
- delete (pods , podName )
249
222
}
250
223
}
251
224
@@ -260,7 +233,7 @@ func (cc *Controller) syncJob(jobInfo *apis.JobInfo, nextState state.NextStateFn
260
233
go func (pod * v1.Pod ) {
261
234
defer waitCreationGroup .Done ()
262
235
_ , err := cc .kubeClients .CoreV1 ().Pods (pod .Namespace ).Create (pod )
263
- if err != nil {
236
+ if err != nil && ! apierrors . IsAlreadyExists ( err ) {
264
237
// Failed to create Pod, waitCreationGroup a moment and then create it again
265
238
// This is to ensure all podsMap under the same Job created
266
239
// So gang-scheduling could schedule the Job successfully
@@ -280,6 +253,7 @@ func (cc *Controller) syncJob(jobInfo *apis.JobInfo, nextState state.NextStateFn
280
253
return fmt .Errorf ("failed to create %d pods of %d" , len (creationErrs ), len (podToCreate ))
281
254
}
282
255
256
+ // TODO: Can hardly imagine when this is necessary.
283
257
// Delete unnecessary pods.
284
258
waitDeletionGroup := sync.WaitGroup {}
285
259
waitDeletionGroup .Add (len (podToDelete ))
@@ -337,16 +311,6 @@ func (cc *Controller) syncJob(jobInfo *apis.JobInfo, nextState state.NextStateFn
337
311
return nil
338
312
}
339
313
340
- func (cc * Controller ) calculateVersion (current int32 , bumpVersion bool ) int32 {
341
- if current == 0 {
342
- current += 1
343
- }
344
- if bumpVersion {
345
- current += 1
346
- }
347
- return current
348
- }
349
-
350
314
func (cc * Controller ) createServiceIfNotExist (job * vkv1.Job ) error {
351
315
// If Service does not exist, create one for Job.
352
316
if _ , err := cc .svcLister .Services (job .Namespace ).Get (job .Name ); err != nil {
@@ -397,68 +361,66 @@ func (cc *Controller) createJobIOIfNotExist(job *vkv1.Job) error {
397
361
// If input/output PVC does not exist, create them for Job.
398
362
inputPVC := job .Annotations [admissioncontroller .PVCInputName ]
399
363
outputPVC := job .Annotations [admissioncontroller .PVCOutputName ]
400
- if job .Spec .Input != nil {
401
- if job .Spec .Input .VolumeClaim != nil {
402
- if _ , err := cc .pvcLister .PersistentVolumeClaims (job .Namespace ).Get (inputPVC ); err != nil {
403
- if ! apierrors .IsNotFound (err ) {
404
- glog .V (3 ).Infof ("Failed to get input PVC for Job <%s/%s>: %v" ,
405
- job .Namespace , job .Name , err )
406
- return err
407
- }
364
+ if job .Spec .Input != nil && job .Spec .Input .VolumeClaim != nil {
365
+ if _ , err := cc .pvcLister .PersistentVolumeClaims (job .Namespace ).Get (inputPVC ); err != nil {
366
+ if ! apierrors .IsNotFound (err ) {
367
+ glog .V (3 ).Infof ("Failed to get input PVC for Job <%s/%s>: %v" ,
368
+ job .Namespace , job .Name , err )
369
+ return err
370
+ }
408
371
409
- pvc := & v1.PersistentVolumeClaim {
410
- ObjectMeta : metav1.ObjectMeta {
411
- Namespace : job .Namespace ,
412
- Name : inputPVC ,
413
- OwnerReferences : []metav1.OwnerReference {
414
- * metav1 .NewControllerRef (job , helpers .JobKind ),
415
- },
372
+ pvc := & v1.PersistentVolumeClaim {
373
+ ObjectMeta : metav1.ObjectMeta {
374
+ Namespace : job .Namespace ,
375
+ Name : inputPVC ,
376
+ OwnerReferences : []metav1.OwnerReference {
377
+ * metav1 .NewControllerRef (job , helpers .JobKind ),
416
378
},
417
- Spec : * job .Spec .Input .VolumeClaim ,
418
- }
379
+ },
380
+ Spec : * job .Spec .Input .VolumeClaim ,
381
+ }
419
382
420
- glog .V (3 ).Infof ("Try to create input PVC: %v" , pvc )
383
+ glog .V (3 ).Infof ("Try to create input PVC: %v" , pvc )
421
384
422
- if _ , err := cc .kubeClients .CoreV1 ().PersistentVolumeClaims (job .Namespace ).Create (pvc ); err != nil {
423
- glog .V (3 ).Infof ("Failed to create input PVC for Job <%s/%s>: %v" ,
424
- job .Namespace , job .Name , err )
425
- return err
426
- }
385
+ if _ , err := cc .kubeClients .CoreV1 ().PersistentVolumeClaims (job .Namespace ).Create (pvc ); err != nil {
386
+ glog .V (3 ).Infof ("Failed to create input PVC for Job <%s/%s>: %v" ,
387
+ job .Namespace , job .Name , err )
388
+ return err
427
389
}
428
390
}
429
391
}
430
- if job .Spec .Output != nil {
431
- if job .Spec .Output .VolumeClaim != nil {
432
- if _ , err := cc .pvcLister .PersistentVolumeClaims (job .Namespace ).Get (outputPVC ); err != nil {
433
- if ! apierrors .IsNotFound (err ) {
434
- glog .V (3 ).Infof ("Failed to get output PVC for Job <%s/%s>: %v" ,
435
- job .Namespace , job .Name , err )
436
- return err
437
- }
438
392
439
- pvc := & v1.PersistentVolumeClaim {
440
- ObjectMeta : metav1.ObjectMeta {
441
- Namespace : job .Namespace ,
442
- Name : outputPVC ,
443
- OwnerReferences : []metav1.OwnerReference {
444
- * metav1 .NewControllerRef (job , helpers .JobKind ),
445
- },
393
+ if job .Spec .Output != nil && job .Spec .Output .VolumeClaim != nil {
394
+ if _ , err := cc .pvcLister .PersistentVolumeClaims (job .Namespace ).Get (outputPVC ); err != nil {
395
+ if ! apierrors .IsNotFound (err ) {
396
+ glog .V (3 ).Infof ("Failed to get output PVC for Job <%s/%s>: %v" ,
397
+ job .Namespace , job .Name , err )
398
+ return err
399
+ }
400
+
401
+ pvc := & v1.PersistentVolumeClaim {
402
+ ObjectMeta : metav1.ObjectMeta {
403
+ Namespace : job .Namespace ,
404
+ Name : outputPVC ,
405
+ OwnerReferences : []metav1.OwnerReference {
406
+ * metav1 .NewControllerRef (job , helpers .JobKind ),
446
407
},
447
- Spec : * job .Spec .Output .VolumeClaim ,
448
- }
408
+ },
409
+ Spec : * job .Spec .Output .VolumeClaim ,
410
+ }
449
411
450
- glog .V (3 ).Infof ("Try to create output PVC: %v" , pvc )
412
+ glog .V (3 ).Infof ("Try to create output PVC: %v" , pvc )
451
413
452
- if _ , err := cc .kubeClients .CoreV1 ().PersistentVolumeClaims (job .Namespace ).Create (pvc ); err != nil {
453
- if ! apierrors .IsAlreadyExists (err ) {
454
- glog .V (3 ).Infof ("Failed to create input PVC for Job <%s/%s>: %v" ,
455
- job .Namespace , job .Name , err )
456
- return err
457
- }
414
+ if _ , err := cc .kubeClients .CoreV1 ().PersistentVolumeClaims (job .Namespace ).Create (pvc ); err != nil {
415
+ if ! apierrors .IsAlreadyExists (err ) {
416
+ glog .V (3 ).Infof ("Failed to create input PVC for Job <%s/%s>: %v" ,
417
+ job .Namespace , job .Name , err )
418
+ return err
458
419
}
459
420
}
460
421
}
461
422
}
423
+
462
424
return nil
463
425
}
464
426
0 commit comments