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