@@ -42,7 +42,7 @@ func (cc *Controller) killJob(jobInfo *apis.JobInfo, nextState state.NextStateFn
42
42
defer glog .V (3 ).Infof ("Finished Job <%s/%s> killing" , jobInfo .Job .Namespace , jobInfo .Job .Name )
43
43
44
44
job := jobInfo .Job
45
- //Job version is bumped only when job is killed
45
+ // Job version is bumped only when job is killed
46
46
job .Status .Version = job .Status .Version + 1
47
47
glog .Infof ("Current Version is: %d of job: %s/%s" , job .Status .Version , job .Namespace , job .Name )
48
48
if job .DeletionTimestamp != nil {
@@ -88,7 +88,14 @@ func (cc *Controller) killJob(jobInfo *apis.JobInfo, nextState state.NextStateFn
88
88
}
89
89
terminating ++
90
90
case v1 .PodSucceeded :
91
- succeeded ++
91
+ err := cc .kubeClients .CoreV1 ().Pods (pod .Namespace ).Delete (pod .Name , nil )
92
+ if err != nil {
93
+ succeeded ++
94
+ glog .Errorf ("Failed to delete pod %s for Job %s, err %#v" ,
95
+ pod .Name , job .Name , err )
96
+ errs = append (errs , err )
97
+ continue
98
+ }
92
99
case v1 .PodFailed :
93
100
err := cc .kubeClients .CoreV1 ().Pods (pod .Namespace ).Delete (pod .Name , nil )
94
101
if err != nil {
@@ -240,7 +247,7 @@ func (cc *Controller) syncJob(jobInfo *apis.JobInfo, nextState state.NextStateFn
240
247
terminating ++
241
248
} else {
242
249
running ++
243
- } /**/
250
+ }
244
251
case v1 .PodSucceeded :
245
252
succeeded ++
246
253
case v1 .PodFailed :
@@ -382,11 +389,12 @@ func (cc *Controller) createServiceIfNotExist(job *vkv1.Job) error {
382
389
},
383
390
}
384
391
385
- if _ , e := cc .kubeClients .CoreV1 ().Services (job .Namespace ).Create (svc ); e != nil {
386
- glog .V (3 ).Infof ("Failed to create Service for Job <%s/%s>: %v" ,
387
- job .Namespace , job .Name , err )
388
-
389
- return e
392
+ if _ , err := cc .kubeClients .CoreV1 ().Services (job .Namespace ).Create (svc ); err != nil {
393
+ if ! apierrors .IsAlreadyExists (err ) {
394
+ glog .V (3 ).Infof ("Failed to create Service for Job <%s/%s>: %v" ,
395
+ job .Namespace , job .Name , err )
396
+ return err
397
+ }
390
398
}
391
399
}
392
400
@@ -419,10 +427,10 @@ func (cc *Controller) createJobIOIfNotExist(job *vkv1.Job) error {
419
427
420
428
glog .V (3 ).Infof ("Try to create input PVC: %v" , pvc )
421
429
422
- if _ , e := cc .kubeClients .CoreV1 ().PersistentVolumeClaims (job .Namespace ).Create (pvc ); e != nil {
430
+ if _ , err := cc .kubeClients .CoreV1 ().PersistentVolumeClaims (job .Namespace ).Create (pvc ); err != nil {
423
431
glog .V (3 ).Infof ("Failed to create input PVC for Job <%s/%s>: %v" ,
424
432
job .Namespace , job .Name , err )
425
- return e
433
+ return err
426
434
}
427
435
}
428
436
}
@@ -433,7 +441,7 @@ func (cc *Controller) createJobIOIfNotExist(job *vkv1.Job) error {
433
441
if ! apierrors .IsNotFound (err ) {
434
442
glog .V (3 ).Infof ("Failed to get output PVC for Job <%s/%s>: %v" ,
435
443
job .Namespace , job .Name , err )
436
- // return err
444
+ return err
437
445
}
438
446
439
447
pvc := & v1.PersistentVolumeClaim {
@@ -449,10 +457,12 @@ func (cc *Controller) createJobIOIfNotExist(job *vkv1.Job) error {
449
457
450
458
glog .V (3 ).Infof ("Try to create output PVC: %v" , pvc )
451
459
452
- if _ , e := cc .kubeClients .CoreV1 ().PersistentVolumeClaims (job .Namespace ).Create (pvc ); e != nil {
453
- glog .V (3 ).Infof ("Failed to create input PVC for Job <%s/%s>: %v" ,
454
- job .Namespace , job .Name , err )
455
- return e
460
+ if _ , err := cc .kubeClients .CoreV1 ().PersistentVolumeClaims (job .Namespace ).Create (pvc ); err != nil {
461
+ if ! apierrors .IsAlreadyExists (err ) {
462
+ glog .V (3 ).Infof ("Failed to create input PVC for Job <%s/%s>: %v" ,
463
+ job .Namespace , job .Name , err )
464
+ return err
465
+ }
456
466
}
457
467
}
458
468
}
@@ -482,11 +492,13 @@ func (cc *Controller) createPodGroupIfNotExist(job *vkv1.Job) error {
482
492
},
483
493
}
484
494
485
- if _ , e := cc .kbClients .SchedulingV1alpha1 ().PodGroups (job .Namespace ).Create (pg ); e != nil {
486
- glog .V (3 ).Infof ("Failed to create PodGroup for Job <%s/%s>: %v" ,
487
- job .Namespace , job .Name , err )
495
+ if _ , err := cc .kbClients .SchedulingV1alpha1 ().PodGroups (job .Namespace ).Create (pg ); err != nil {
496
+ if ! apierrors .IsAlreadyExists (err ) {
497
+ glog .V (3 ).Infof ("Failed to create PodGroup for Job <%s/%s>: %v" ,
498
+ job .Namespace , job .Name , err )
488
499
489
- return e
500
+ return err
501
+ }
490
502
}
491
503
}
492
504
0 commit comments