@@ -1864,6 +1864,73 @@ func TestCalculateStatusWithoutDesiredReplicas(t *testing.T) {
1864
1864
assert .Nil (t , newInstance .Status .StateTransitionTimes )
1865
1865
}
1866
1866
1867
+ // TestCalculateStatusWithSuspendedWorkerGroups tests that the cluster CR should be marked as Ready without workers
1868
+ // and all desired resources are not counted with suspended workers
1869
+ func TestCalculateStatusWithSuspendedWorkerGroups (t * testing.T ) {
1870
+ setupTest (t )
1871
+
1872
+ testRayCluster .Spec .WorkerGroupSpecs [0 ].Suspend = ptr.To [bool ](true )
1873
+ testRayCluster .Spec .WorkerGroupSpecs [0 ].MinReplicas = ptr.To [int32 ](100 )
1874
+ testRayCluster .Spec .WorkerGroupSpecs [0 ].MaxReplicas = ptr.To [int32 ](100 )
1875
+ testRayCluster .Spec .WorkerGroupSpecs [0 ].Template .Spec .Containers [0 ].Resources .Requests = corev1.ResourceList {
1876
+ corev1 .ResourceCPU : resource .MustParse ("100m" ),
1877
+ corev1 .ResourceMemory : resource .MustParse ("100Mi" ),
1878
+ }
1879
+
1880
+ // Create a new scheme with CRDs, Pod, Service schemes.
1881
+ newScheme := runtime .NewScheme ()
1882
+ _ = rayv1 .AddToScheme (newScheme )
1883
+ _ = corev1 .AddToScheme (newScheme )
1884
+
1885
+ // Mock data
1886
+ headServiceIP := "aaa.bbb.ccc.ddd"
1887
+ headService , err := common .BuildServiceForHeadPod (context .Background (), * testRayCluster , nil , nil )
1888
+ assert .Nil (t , err , "Failed to build head service." )
1889
+ headService .Spec .ClusterIP = headServiceIP
1890
+ headPod := & corev1.Pod {
1891
+ ObjectMeta : metav1.ObjectMeta {
1892
+ Name : "headNode" ,
1893
+ Namespace : namespaceStr ,
1894
+ Labels : map [string ]string {
1895
+ utils .RayClusterLabelKey : instanceName ,
1896
+ utils .RayNodeTypeLabelKey : string (rayv1 .HeadNode ),
1897
+ },
1898
+ },
1899
+ Status : corev1.PodStatus {
1900
+ PodIP : headNodeIP ,
1901
+ Phase : corev1 .PodRunning ,
1902
+ Conditions : []corev1.PodCondition {
1903
+ {
1904
+ Type : corev1 .PodReady ,
1905
+ Status : corev1 .ConditionTrue ,
1906
+ },
1907
+ },
1908
+ },
1909
+ }
1910
+ runtimeObjects := []runtime.Object {headPod , headService }
1911
+
1912
+ // Initialize a fake client with newScheme and runtimeObjects.
1913
+ fakeClient := clientFake .NewClientBuilder ().WithScheme (newScheme ).WithRuntimeObjects (runtimeObjects ... ).Build ()
1914
+ ctx := context .Background ()
1915
+
1916
+ // Initialize a RayCluster reconciler.
1917
+ r := & RayClusterReconciler {
1918
+ Client : fakeClient ,
1919
+ Recorder : & record.FakeRecorder {},
1920
+ Scheme : scheme .Scheme ,
1921
+ }
1922
+
1923
+ newInstance , err := r .calculateStatus (ctx , testRayCluster , nil )
1924
+ assert .Nil (t , err )
1925
+ assert .Equal (t , newInstance .Status .DesiredWorkerReplicas , int32 (0 ))
1926
+ assert .Equal (t , newInstance .Status .MinWorkerReplicas , int32 (0 ))
1927
+ assert .Equal (t , newInstance .Status .MaxWorkerReplicas , int32 (0 ))
1928
+ assert .Equal (t , newInstance .Status .DesiredCPU , resource.Quantity {})
1929
+ assert .Equal (t , newInstance .Status .DesiredMemory , resource.Quantity {})
1930
+ assert .Equal (t , newInstance .Status .State , rayv1 .Ready ) //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
1931
+ assert .NotNil (t , newInstance .Status .StateTransitionTimes )
1932
+ }
1933
+
1867
1934
// TestCalculateStatusWithReconcileErrorBackAndForth tests that the cluster CR should not be marked as Ready if reconcileErr != nil
1868
1935
// and the Ready state should not be removed after being Ready even if reconcileErr != nil
1869
1936
func TestCalculateStatusWithReconcileErrorBackAndForth (t * testing.T ) {
0 commit comments