@@ -2881,7 +2881,7 @@ func TestSingleJobFailedCondition(t *testing.T) {
2881
2881
}
2882
2882
2883
2883
func TestJobControllerMissingJobSucceedEvent (t * testing.T ) {
2884
- t .Cleanup (setDurationDuringTest (& syncJobBatchPeriod , fastSyncJobBatchPeriod ))
2884
+ t .Cleanup (setDurationDuringTest (& SyncJobBatchPeriod , fastSyncJobBatchPeriod ))
2885
2885
logger , ctx := ktesting .NewTestContext (t )
2886
2886
job1 := newJob (1 , 1 , 6 , batch .NonIndexedCompletion )
2887
2887
job1 .Name = "job1"
@@ -2928,6 +2928,8 @@ func TestJobControllerMissingJobSucceedEvent(t *testing.T) {
2928
2928
t .Fatalf ("Unexpected error when syncing jobs %v" , err )
2929
2929
}
2930
2930
2931
+ // Verify that the job is updated as succeeded in the client set. However this status is not updated yet in the
2932
+ // informer is not started
2931
2933
jobList , err := clientSet .Tracker ().List (
2932
2934
schema.GroupVersionResource {Group : "batch" , Version : "v1" , Resource : "jobs" },
2933
2935
schema.GroupVersionKind {Group : "batch" , Version : "v1" , Kind : "Job" },
@@ -2940,7 +2942,8 @@ func TestJobControllerMissingJobSucceedEvent(t *testing.T) {
2940
2942
t .Fatalf ("job status is not succeeded: %v" , updatedJob )
2941
2943
}
2942
2944
2943
- // add the updated pod from the fake clientset memory to informer cache because informer is not started.
2945
+ // add the updated pod from the fake clientset memory to informer cache because informer is not started. This is to make
2946
+ // sure the job controller informer cache has the latest pod status.
2944
2947
podList , err = clientSet .Tracker ().List (
2945
2948
schema.GroupVersionResource {Version : "v1" , Resource : "pods" },
2946
2949
schema.GroupVersionKind {Version : "v1" , Kind : "Pod" },
@@ -2956,8 +2959,9 @@ func TestJobControllerMissingJobSucceedEvent(t *testing.T) {
2956
2959
t .Fatalf ("Unexpected error when adding pod to indexer %v" , err )
2957
2960
}
2958
2961
2959
- // removing the just created pod from fake clientset memory inorder for the sync job to succeed if creating a new pod because of bug
2960
- // but the pod will remain inside informer cache
2962
+ // removing the just created pod from fake clientset memory but the pod will remain inside informer cache
2963
+ // of the job controller. We are removing from the client set because in case of a bug if the job controller
2964
+ // is trying to create the pod again it can succeed because it creates using the same name again.
2961
2965
err = clientSet .Tracker ().Delete (
2962
2966
schema.GroupVersionResource {Version : "v1" , Resource : "pods" },
2963
2967
"default" , "" )
@@ -2978,7 +2982,7 @@ func TestJobControllerMissingJobSucceedEvent(t *testing.T) {
2978
2982
if err != nil {
2979
2983
t .Fatalf ("Unexpected error when syncing jobs %v" , err )
2980
2984
}
2981
- // no pod should be created
2985
+ // no pod should be created. Here it is 0 because we had deleted the pod from the client set.
2982
2986
if len (podList .(* v1.PodList ).Items ) != 0 {
2983
2987
t .Errorf ("expect no pods to be created but %v pods are created" , len (podList .(* v1.PodList ).Items ))
2984
2988
}
@@ -6338,7 +6342,7 @@ func TestGetPodsForJob(t *testing.T) {
6338
6342
}
6339
6343
6340
6344
func TestAddPod (t * testing.T ) {
6341
- t .Cleanup (setDurationDuringTest (& syncJobBatchPeriod , fastSyncJobBatchPeriod ))
6345
+ t .Cleanup (setDurationDuringTest (& SyncJobBatchPeriod , fastSyncJobBatchPeriod ))
6342
6346
_ , ctx := ktesting .NewTestContext (t )
6343
6347
logger := klog .FromContext (ctx )
6344
6348
@@ -6384,7 +6388,7 @@ func TestAddPod(t *testing.T) {
6384
6388
}
6385
6389
6386
6390
func TestAddPodOrphan (t * testing.T ) {
6387
- t .Cleanup (setDurationDuringTest (& syncJobBatchPeriod , fastSyncJobBatchPeriod ))
6391
+ t .Cleanup (setDurationDuringTest (& SyncJobBatchPeriod , fastSyncJobBatchPeriod ))
6388
6392
logger , ctx := ktesting .NewTestContext (t )
6389
6393
clientset := clientset .NewForConfigOrDie (& restclient.Config {Host : "" , ContentConfig : restclient.ContentConfig {GroupVersion : & schema.GroupVersion {Group : "" , Version : "v1" }}})
6390
6394
fakeClock := clocktesting .NewFakeClock (time .Now ())
@@ -6413,7 +6417,7 @@ func TestAddPodOrphan(t *testing.T) {
6413
6417
}
6414
6418
6415
6419
func TestUpdatePod (t * testing.T ) {
6416
- t .Cleanup (setDurationDuringTest (& syncJobBatchPeriod , fastSyncJobBatchPeriod ))
6420
+ t .Cleanup (setDurationDuringTest (& SyncJobBatchPeriod , fastSyncJobBatchPeriod ))
6417
6421
_ , ctx := ktesting .NewTestContext (t )
6418
6422
logger := klog .FromContext (ctx )
6419
6423
clientset := clientset .NewForConfigOrDie (& restclient.Config {Host : "" , ContentConfig : restclient.ContentConfig {GroupVersion : & schema.GroupVersion {Group : "" , Version : "v1" }}})
@@ -6462,7 +6466,7 @@ func TestUpdatePod(t *testing.T) {
6462
6466
}
6463
6467
6464
6468
func TestUpdatePodOrphanWithNewLabels (t * testing.T ) {
6465
- t .Cleanup (setDurationDuringTest (& syncJobBatchPeriod , fastSyncJobBatchPeriod ))
6469
+ t .Cleanup (setDurationDuringTest (& SyncJobBatchPeriod , fastSyncJobBatchPeriod ))
6466
6470
logger , ctx := ktesting .NewTestContext (t )
6467
6471
clientset := clientset .NewForConfigOrDie (& restclient.Config {Host : "" , ContentConfig : restclient.ContentConfig {GroupVersion : & schema.GroupVersion {Group : "" , Version : "v1" }}})
6468
6472
fakeClock := clocktesting .NewFakeClock (time .Now ())
@@ -6490,7 +6494,7 @@ func TestUpdatePodOrphanWithNewLabels(t *testing.T) {
6490
6494
}
6491
6495
6492
6496
func TestUpdatePodChangeControllerRef (t * testing.T ) {
6493
- t .Cleanup (setDurationDuringTest (& syncJobBatchPeriod , fastSyncJobBatchPeriod ))
6497
+ t .Cleanup (setDurationDuringTest (& SyncJobBatchPeriod , fastSyncJobBatchPeriod ))
6494
6498
_ , ctx := ktesting .NewTestContext (t )
6495
6499
logger := klog .FromContext (ctx )
6496
6500
clientset := clientset .NewForConfigOrDie (& restclient.Config {Host : "" , ContentConfig : restclient.ContentConfig {GroupVersion : & schema.GroupVersion {Group : "" , Version : "v1" }}})
@@ -6518,7 +6522,7 @@ func TestUpdatePodChangeControllerRef(t *testing.T) {
6518
6522
}
6519
6523
6520
6524
func TestUpdatePodRelease (t * testing.T ) {
6521
- t .Cleanup (setDurationDuringTest (& syncJobBatchPeriod , fastSyncJobBatchPeriod ))
6525
+ t .Cleanup (setDurationDuringTest (& SyncJobBatchPeriod , fastSyncJobBatchPeriod ))
6522
6526
_ , ctx := ktesting .NewTestContext (t )
6523
6527
logger := klog .FromContext (ctx )
6524
6528
clientset := clientset .NewForConfigOrDie (& restclient.Config {Host : "" , ContentConfig : restclient.ContentConfig {GroupVersion : & schema.GroupVersion {Group : "" , Version : "v1" }}})
@@ -6546,7 +6550,7 @@ func TestUpdatePodRelease(t *testing.T) {
6546
6550
}
6547
6551
6548
6552
func TestDeletePod (t * testing.T ) {
6549
- t .Cleanup (setDurationDuringTest (& syncJobBatchPeriod , fastSyncJobBatchPeriod ))
6553
+ t .Cleanup (setDurationDuringTest (& SyncJobBatchPeriod , fastSyncJobBatchPeriod ))
6550
6554
logger , ctx := ktesting .NewTestContext (t )
6551
6555
clientset := clientset .NewForConfigOrDie (& restclient.Config {Host : "" , ContentConfig : restclient.ContentConfig {GroupVersion : & schema.GroupVersion {Group : "" , Version : "v1" }}})
6552
6556
fakeClock := clocktesting .NewFakeClock (time .Now ())
@@ -6591,7 +6595,7 @@ func TestDeletePod(t *testing.T) {
6591
6595
6592
6596
func TestDeletePodOrphan (t * testing.T ) {
6593
6597
// Disable batching of pod updates to show it does not get requeued at all
6594
- t .Cleanup (setDurationDuringTest (& syncJobBatchPeriod , 0 ))
6598
+ t .Cleanup (setDurationDuringTest (& SyncJobBatchPeriod , 0 ))
6595
6599
logger , ctx := ktesting .NewTestContext (t )
6596
6600
clientset := clientset .NewForConfigOrDie (& restclient.Config {Host : "" , ContentConfig : restclient.ContentConfig {GroupVersion : & schema.GroupVersion {Group : "" , Version : "v1" }}})
6597
6601
jm , informer := newControllerFromClient (ctx , t , clientset , controller .NoResyncPeriodFunc )
@@ -7113,7 +7117,7 @@ func TestJobBackoff(t *testing.T) {
7113
7117
"failure with pod updates batching" : {
7114
7118
requeues : 0 ,
7115
7119
phase : v1 .PodFailed ,
7116
- wantBackoff : syncJobBatchPeriod ,
7120
+ wantBackoff : SyncJobBatchPeriod ,
7117
7121
},
7118
7122
}
7119
7123
0 commit comments