@@ -25,6 +25,7 @@ import (
2525 "github.com/ray-project/kuberay/ray-operator/controllers/ray/common"
2626 "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
2727 "github.com/ray-project/kuberay/ray-operator/pkg/client/clientset/versioned/scheme"
28+ "github.com/ray-project/kuberay/ray-operator/pkg/features"
2829
2930 . "github.com/onsi/ginkgo/v2"
3031 "github.com/stretchr/testify/assert"
@@ -33,6 +34,7 @@ import (
3334 corev1 "k8s.io/api/core/v1"
3435 rbacv1 "k8s.io/api/rbac/v1"
3536 k8serrors "k8s.io/apimachinery/pkg/api/errors"
37+ "k8s.io/apimachinery/pkg/api/meta"
3638 "k8s.io/apimachinery/pkg/api/resource"
3739 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3840 "k8s.io/apimachinery/pkg/labels"
@@ -1664,6 +1666,13 @@ func TestCalculateStatus(t *testing.T) {
16641666 Status : corev1.PodStatus {
16651667 PodIP : headNodeIP ,
16661668 Phase : corev1 .PodRunning ,
1669+ Conditions : []corev1.PodCondition {
1670+ // The head Pod is ready
1671+ {
1672+ Type : corev1 .PodReady ,
1673+ Status : corev1 .ConditionTrue ,
1674+ },
1675+ },
16671676 },
16681677 }
16691678 runtimeObjects := []runtime.Object {headPod , headService }
@@ -1687,6 +1696,47 @@ func TestCalculateStatus(t *testing.T) {
16871696 assert .Equal (t , headService .Name , newInstance .Status .Head .ServiceName )
16881697 assert .NotNil (t , newInstance .Status .StateTransitionTimes , "Cluster state transition timestamp should be created" )
16891698 assert .Equal (t , newInstance .Status .LastUpdateTime , newInstance .Status .StateTransitionTimes [rayv1 .Ready ])
1699+
1700+ // Test CheckRayHeadRunningAndReady with feature gate disabled
1701+ newInstance , _ = r .calculateStatus (ctx , testRayCluster , nil )
1702+ assert .Empty (t , newInstance .Status .Conditions )
1703+
1704+ // enable feature gate for the following tests
1705+ defer features .SetFeatureGateDuringTest (t , features .RayClusterStatusConditions , true )()
1706+
1707+ // Test CheckRayHeadRunningAndReady with head pod running and ready
1708+ newInstance , _ = r .calculateStatus (ctx , testRayCluster , nil )
1709+ assert .True (t , meta .IsStatusConditionPresentAndEqual (newInstance .Status .Conditions , string (rayv1 .HeadReady ), metav1 .ConditionTrue ))
1710+ condition := meta .FindStatusCondition (newInstance .Status .Conditions , string (rayv1 .HeadReady ))
1711+ assert .Equal (t , "HeadPodRunningAndReady" , condition .Reason )
1712+ assert .Equal (t , "Head pod is running and ready" , condition .Message )
1713+
1714+ // Test CheckRayHeadRunningAndReady with feature gate enabled and head pod not ready
1715+ headPod .Status .Conditions = []corev1.PodCondition {
1716+ {
1717+ Type : corev1 .PodReady ,
1718+ Status : corev1 .ConditionFalse ,
1719+ },
1720+ }
1721+ runtimeObjects = []runtime.Object {headPod , headService }
1722+ fakeClient = clientFake .NewClientBuilder ().WithScheme (newScheme ).WithRuntimeObjects (runtimeObjects ... ).Build ()
1723+ r .Client = fakeClient
1724+ newInstance , _ = r .calculateStatus (ctx , testRayCluster , nil )
1725+ assert .True (t , meta .IsStatusConditionPresentAndEqual (newInstance .Status .Conditions , string (rayv1 .HeadReady ), metav1 .ConditionFalse ))
1726+ condition = meta .FindStatusCondition (newInstance .Status .Conditions , string (rayv1 .HeadReady ))
1727+ assert .Equal (t , "HeadPodNotReady" , condition .Reason )
1728+ assert .Equal (t , "Head pod is not ready" , condition .Message )
1729+
1730+ // Test CheckRayHeadRunningAndReady with feature gate enabled and head pod not running
1731+ headPod .Status .Phase = corev1 .PodFailed
1732+ runtimeObjects = []runtime.Object {headPod , headService }
1733+ fakeClient = clientFake .NewClientBuilder ().WithScheme (newScheme ).WithRuntimeObjects (runtimeObjects ... ).Build ()
1734+ r .Client = fakeClient
1735+ newInstance , _ = r .calculateStatus (ctx , testRayCluster , nil )
1736+ assert .True (t , meta .IsStatusConditionPresentAndEqual (newInstance .Status .Conditions , string (rayv1 .HeadReady ), metav1 .ConditionFalse ))
1737+ condition = meta .FindStatusCondition (newInstance .Status .Conditions , string (rayv1 .HeadReady ))
1738+ assert .Equal (t , "HeadPodNotRunning" , condition .Reason )
1739+ assert .Equal (t , "Head pod is not running" , condition .Message )
16901740}
16911741
16921742func TestStateTransitionTimes_NoStateChange (t * testing.T ) {
0 commit comments