@@ -56,7 +56,6 @@ import (
56
56
_ "k8s.io/kubernetes/pkg/apis/core/install"
57
57
"k8s.io/kubernetes/pkg/controller"
58
58
"k8s.io/kubernetes/pkg/controller/job/metrics"
59
- "k8s.io/kubernetes/pkg/controller/job/util"
60
59
"k8s.io/kubernetes/pkg/controller/testutil"
61
60
"k8s.io/kubernetes/pkg/features"
62
61
"k8s.io/utils/clock"
@@ -2880,114 +2879,6 @@ func TestSingleJobFailedCondition(t *testing.T) {
2880
2879
2881
2880
}
2882
2881
2883
- func TestJobControllerMissingJobSucceedEvent (t * testing.T ) {
2884
- t .Cleanup (setDurationDuringTest (& SyncJobBatchPeriod , fastSyncJobBatchPeriod ))
2885
- logger , ctx := ktesting .NewTestContext (t )
2886
- job1 := newJob (1 , 1 , 6 , batch .NonIndexedCompletion )
2887
- job1 .Name = "job1"
2888
- clientSet := fake .NewSimpleClientset (job1 )
2889
- fakeClock := clocktesting .NewFakeClock (time .Now ())
2890
- jm , informer := newControllerFromClientWithClock (ctx , t , clientSet , controller .NoResyncPeriodFunc , fakeClock )
2891
- jm .podControl = & controller.RealPodControl {
2892
- KubeClient : clientSet ,
2893
- Recorder : testutil .NewFakeRecorder (),
2894
- }
2895
- jm .podStoreSynced = alwaysReady
2896
- jm .jobStoreSynced = alwaysReady
2897
-
2898
- err := informer .Batch ().V1 ().Jobs ().Informer ().GetIndexer ().Add (job1 )
2899
- if err != nil {
2900
- t .Fatalf ("Unexpected error when adding job to indexer %v" , err )
2901
- }
2902
- // 1st reconcile should create a new pod
2903
- err = jm .syncJob (ctx , testutil .GetKey (job1 , t ))
2904
- if err != nil {
2905
- t .Fatalf ("Unexpected error when syncing jobs %v" , err )
2906
- }
2907
-
2908
- podIndexer := informer .Core ().V1 ().Pods ().Informer ().GetIndexer ()
2909
- podList , err := clientSet .Tracker ().List (
2910
- schema.GroupVersionResource {Version : "v1" , Resource : "pods" },
2911
- schema.GroupVersionKind {Version : "v1" , Kind : "Pod" },
2912
- "default" )
2913
- if err != nil {
2914
- t .Fatalf ("Unexpected error when fetching pods %v" , err )
2915
- }
2916
- // manually adding the just-created pod from fake clientset memory to informer cache because informer is not started.
2917
- // we are updating the pod status to succeeded which should update the job status to succeeded and remove the finalizer of the pod.
2918
- justCreatedPod := podList .(* v1.PodList ).Items [0 ]
2919
- t .Logf ("pod is %v\n " , podList .(* v1.PodList ).Items [0 ])
2920
- justCreatedPod .Status .Phase = v1 .PodSucceeded
2921
- err = podIndexer .Add (& justCreatedPod )
2922
- if err != nil {
2923
- t .Fatalf ("Unexpected error when adding pod to indexer %v" , err )
2924
- }
2925
- jm .addPod (logger , & justCreatedPod )
2926
- err = jm .syncJob (ctx , testutil .GetKey (job1 , t ))
2927
- if err != nil {
2928
- t .Fatalf ("Unexpected error when syncing jobs %v" , err )
2929
- }
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
2933
- jobList , err := clientSet .Tracker ().List (
2934
- schema.GroupVersionResource {Group : "batch" , Version : "v1" , Resource : "jobs" },
2935
- schema.GroupVersionKind {Group : "batch" , Version : "v1" , Kind : "Job" },
2936
- "default" )
2937
- if err != nil {
2938
- t .Fatalf ("Unexpected error when trying to get job from the store: %v" , err )
2939
- }
2940
- updatedJob := jobList .(* batch.JobList ).Items [0 ]
2941
- if ! util .IsJobSucceeded (& updatedJob ) {
2942
- t .Fatalf ("job status is not succeeded: %v" , updatedJob )
2943
- }
2944
-
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.
2947
- podList , err = clientSet .Tracker ().List (
2948
- schema.GroupVersionResource {Version : "v1" , Resource : "pods" },
2949
- schema.GroupVersionKind {Version : "v1" , Kind : "Pod" },
2950
- "default" )
2951
- if err != nil {
2952
- t .Fatalf ("Unexpected error when fetching pods %v" , err )
2953
- }
2954
- t .Logf ("pod is %v\n " , podList .(* v1.PodList ).Items [0 ])
2955
- updatedPod := podList .(* v1.PodList ).Items [0 ]
2956
- updatedPod .Status .Phase = v1 .PodSucceeded
2957
- err = podIndexer .Add (& updatedPod )
2958
- if err != nil {
2959
- t .Fatalf ("Unexpected error when adding pod to indexer %v" , err )
2960
- }
2961
-
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.
2965
- err = clientSet .Tracker ().Delete (
2966
- schema.GroupVersionResource {Version : "v1" , Resource : "pods" },
2967
- "default" , "" )
2968
- if err != nil {
2969
- t .Fatalf ("Unexpected error when deleting pod to indexer %v" , err )
2970
- }
2971
-
2972
- err = jm .syncJob (ctx , testutil .GetKey (job1 , t ))
2973
- if err != nil {
2974
- t .Fatalf ("Unexpected error when syncing jobs %v" , err )
2975
- }
2976
- time .Sleep (100 * time .Millisecond )
2977
-
2978
- podList , err = clientSet .Tracker ().List (
2979
- schema.GroupVersionResource {Version : "v1" , Resource : "pods" },
2980
- schema.GroupVersionKind {Version : "v1" , Kind : "Pod" },
2981
- "default" )
2982
- if err != nil {
2983
- t .Fatalf ("Unexpected error when syncing jobs %v" , err )
2984
- }
2985
- // no pod should be created. Here it is 0 because we had deleted the pod from the client set.
2986
- if len (podList .(* v1.PodList ).Items ) != 0 {
2987
- t .Errorf ("expect no pods to be created but %v pods are created" , len (podList .(* v1.PodList ).Items ))
2988
- }
2989
- }
2990
-
2991
2882
func TestSyncJobComplete (t * testing.T ) {
2992
2883
_ , ctx := ktesting .NewTestContext (t )
2993
2884
clientset := clientset .NewForConfigOrDie (& restclient.Config {Host : "" , ContentConfig : restclient.ContentConfig {GroupVersion : & schema.GroupVersion {Group : "" , Version : "v1" }}})
0 commit comments