@@ -1645,6 +1645,58 @@ func TestCalculateStatus(t *testing.T) {
1645
1645
assert .Nil (t , err )
1646
1646
assert .Equal (t , headNodeIP , newInstance .Status .Head .PodIP )
1647
1647
assert .Equal (t , headServiceIP , newInstance .Status .Head .ServiceIP )
1648
+ assert .NotNil (t , newInstance .Status .StateTransitionTimes , "Cluster state transition timestamp should be created" )
1649
+ assert .Equal (t , newInstance .Status .LastUpdateTime , newInstance .Status .StateTransitionTimes [rayv1 .Unhealthy ])
1650
+ }
1651
+
1652
+ func TestStateTransitionTimes_NoStateChange (t * testing.T ) {
1653
+ setupTest (t )
1654
+
1655
+ // Create a new scheme with CRDs, Pod, Service schemes.
1656
+ newScheme := runtime .NewScheme ()
1657
+ _ = rayv1 .AddToScheme (newScheme )
1658
+ _ = corev1 .AddToScheme (newScheme )
1659
+
1660
+ // Mock data
1661
+ headServiceIP := "aaa.bbb.ccc.ddd"
1662
+ headService , err := common .BuildServiceForHeadPod (context .Background (), * testRayCluster , nil , nil )
1663
+ assert .Nil (t , err , "Failed to build head service." )
1664
+ headService .Spec .ClusterIP = headServiceIP
1665
+ // headService.Spec.cont
1666
+ headPod := & corev1.Pod {
1667
+ ObjectMeta : metav1.ObjectMeta {
1668
+ Name : "headNode" ,
1669
+ Namespace : namespaceStr ,
1670
+ Labels : map [string ]string {
1671
+ utils .RayClusterLabelKey : instanceName ,
1672
+ utils .RayNodeTypeLabelKey : string (rayv1 .HeadNode ),
1673
+ },
1674
+ },
1675
+ Status : corev1.PodStatus {
1676
+ PodIP : headNodeIP ,
1677
+ },
1678
+ }
1679
+ runtimeObjects := []runtime.Object {headPod , headService }
1680
+
1681
+ // Initialize a fake client with newScheme and runtimeObjects.
1682
+ fakeClient := clientFake .NewClientBuilder ().WithScheme (newScheme ).WithRuntimeObjects (runtimeObjects ... ).Build ()
1683
+ ctx := context .Background ()
1684
+
1685
+ // Initialize a RayCluster reconciler.
1686
+ r := & RayClusterReconciler {
1687
+ Client : fakeClient ,
1688
+ Recorder : & record.FakeRecorder {},
1689
+ Scheme : scheme .Scheme ,
1690
+ }
1691
+
1692
+ // prevent unhealthy state status
1693
+ delete (testRayCluster .Spec .HeadGroupSpec .RayStartParams , "object-store-memory" )
1694
+ preUpdateTime := metav1 .Now ()
1695
+ testRayCluster .Status .State = rayv1 .Ready
1696
+ testRayCluster .Status .StateTransitionTimes = map [rayv1.ClusterState ]* metav1.Time {rayv1 .Ready : & preUpdateTime }
1697
+ newInstance , err := r .calculateStatus (ctx , testRayCluster )
1698
+ assert .Nil (t , err )
1699
+ assert .Equal (t , preUpdateTime , * newInstance .Status .StateTransitionTimes [rayv1 .Ready ], "Cluster state transition timestamp should not be updated" )
1648
1700
}
1649
1701
1650
1702
func Test_TerminatedWorkers_NoAutoscaler (t * testing.T ) {
0 commit comments