@@ -924,46 +924,61 @@ func TestReconcile_PodCrash_DiffLess0_OK(t *testing.T) {
924
924
func TestReconcile_PodEvicted_DiffLess0_OK (t * testing.T ) {
925
925
setupTest (t )
926
926
927
- fakeClient := clientFake .NewClientBuilder ().
928
- WithRuntimeObjects (testPods ... ).
929
- Build ()
930
- ctx := context .Background ()
927
+ tests := map [string ]struct {
928
+ restartPolicy corev1.RestartPolicy
929
+ }{
930
+ "Pod with RestartPolicyAlways" : {
931
+ restartPolicy : corev1 .RestartPolicyAlways ,
932
+ },
933
+ "Pod with RestartPolicyOnFailure" : {
934
+ restartPolicy : corev1 .RestartPolicyOnFailure ,
935
+ },
936
+ }
931
937
932
- podList := corev1.PodList {}
933
- err := fakeClient .List (ctx , & podList , client .InNamespace (namespaceStr ))
938
+ for name , tc := range tests {
939
+ t .Run (name , func (t * testing.T ) {
940
+ fakeClient := clientFake .NewClientBuilder ().
941
+ WithRuntimeObjects (testPods ... ).
942
+ Build ()
943
+ ctx := context .Background ()
934
944
935
- assert . Nil ( t , err , "Fail to get pod list" )
936
- assert . Equal ( t , len ( testPods ), len ( podList . Items ), "Init pod list len is wrong" )
945
+ podList := corev1. PodList {}
946
+ err := fakeClient . List ( ctx , & podList , client . InNamespace ( namespaceStr ) )
937
947
938
- // Simulate head pod get evicted.
939
- podList .Items [0 ].Spec .RestartPolicy = corev1 .RestartPolicyAlways
940
- err = fakeClient .Update (ctx , & podList .Items [0 ])
941
- assert .Nil (t , err , "Fail to update head Pod restart policy" )
942
- podList .Items [0 ].Status .Phase = corev1 .PodFailed
943
- err = fakeClient .Status ().Update (ctx , & podList .Items [0 ])
944
- assert .Nil (t , err , "Fail to update head Pod status" )
948
+ assert .Nil (t , err , "Fail to get pod list" )
949
+ assert .Equal (t , len (testPods ), len (podList .Items ), "Init pod list len is wrong" )
945
950
946
- testRayClusterReconciler := & RayClusterReconciler {
947
- Client : fakeClient ,
948
- Recorder : & record.FakeRecorder {},
949
- Scheme : scheme .Scheme ,
950
- }
951
+ // Simulate head pod get evicted.
952
+ podList .Items [0 ].Spec .RestartPolicy = tc .restartPolicy
953
+ err = fakeClient .Update (ctx , & podList .Items [0 ])
954
+ assert .Nil (t , err , "Fail to update head Pod restart policy" )
955
+ podList .Items [0 ].Status .Phase = corev1 .PodFailed
956
+ err = fakeClient .Status ().Update (ctx , & podList .Items [0 ])
957
+ assert .Nil (t , err , "Fail to update head Pod status" )
951
958
952
- err = testRayClusterReconciler . reconcilePods ( ctx , testRayCluster )
953
- // The head Pod with the status `Failed` will be deleted, and the function will return an
954
- // error to requeue the request with a short delay. If the function returns nil, the controller
955
- // will requeue the request after RAYCLUSTER_DEFAULT_REQUEUE_SECONDS_ENV (default: 300) seconds.
956
- assert . NotNil ( t , err )
959
+ testRayClusterReconciler := & RayClusterReconciler {
960
+ Client : fakeClient ,
961
+ Recorder : & record. FakeRecorder {},
962
+ Scheme : scheme . Scheme ,
963
+ }
957
964
958
- // Filter head pod
959
- err = fakeClient . List ( ctx , & podList , & client. ListOptions {
960
- LabelSelector : headSelector ,
961
- Namespace : namespaceStr ,
962
- } )
965
+ err = testRayClusterReconciler . reconcilePods ( ctx , testRayCluster )
966
+ // The head Pod with the status `Failed` will be deleted, and the function will return an
967
+ // error to requeue the request with a short delay. If the function returns nil, the controller
968
+ // will requeue the request after RAYCLUSTER_DEFAULT_REQUEUE_SECONDS_ENV (default: 300) seconds.
969
+ assert . NotNil ( t , err )
963
970
964
- assert .Nil (t , err , "Fail to get pod list after reconcile" )
965
- assert .Equal (t , 0 , len (podList .Items ),
966
- "Evicted head should be deleted after reconcile expect %d actual %d" , 0 , len (podList .Items ))
971
+ // Filter head pod
972
+ err = fakeClient .List (ctx , & podList , & client.ListOptions {
973
+ LabelSelector : headSelector ,
974
+ Namespace : namespaceStr ,
975
+ })
976
+
977
+ assert .Nil (t , err , "Fail to get pod list after reconcile" )
978
+ assert .Equal (t , 0 , len (podList .Items ),
979
+ "Evicted head should be deleted after reconcile expect %d actual %d" , 0 , len (podList .Items ))
980
+ })
981
+ }
967
982
}
968
983
969
984
func TestReconcileHeadService (t * testing.T ) {
0 commit comments