@@ -25,6 +25,7 @@ import (
25
25
"github.com/ray-project/kuberay/ray-operator/controllers/ray/common"
26
26
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
27
27
"github.com/ray-project/kuberay/ray-operator/pkg/client/clientset/versioned/scheme"
28
+ "github.com/ray-project/kuberay/ray-operator/pkg/features"
28
29
29
30
. "github.com/onsi/ginkgo/v2"
30
31
"github.com/stretchr/testify/assert"
@@ -33,6 +34,7 @@ import (
33
34
corev1 "k8s.io/api/core/v1"
34
35
rbacv1 "k8s.io/api/rbac/v1"
35
36
k8serrors "k8s.io/apimachinery/pkg/api/errors"
37
+ "k8s.io/apimachinery/pkg/api/meta"
36
38
"k8s.io/apimachinery/pkg/api/resource"
37
39
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
38
40
"k8s.io/apimachinery/pkg/labels"
@@ -946,7 +948,7 @@ func TestReconcile_PodEvicted_DiffLess0_OK(t *testing.T) {
946
948
// The head Pod with the status `Failed` will be deleted, and the function will return an
947
949
// error to requeue the request with a short delay. If the function returns nil, the controller
948
950
// will requeue the request after RAYCLUSTER_DEFAULT_REQUEUE_SECONDS_ENV (default: 300) seconds.
949
- assert .NotNil (t , err )
951
+ assert .ErrorIs (t , err , reconcilePodsErr )
950
952
951
953
// Filter head pod
952
954
err = fakeClient .List (ctx , & podList , & client.ListOptions {
@@ -1637,6 +1639,11 @@ func TestInconsistentRayClusterStatus(t *testing.T) {
1637
1639
newStatus = oldStatus .DeepCopy ()
1638
1640
newStatus .ObservedGeneration = oldStatus .ObservedGeneration + 1
1639
1641
assert .False (t , r .inconsistentRayClusterStatus (ctx , oldStatus , * newStatus ))
1642
+
1643
+ // Case 12: `Conditions` is different => return true
1644
+ newStatus = oldStatus .DeepCopy ()
1645
+ meta .SetStatusCondition (& newStatus .Conditions , metav1.Condition {Type : string (rayv1 .RayClusterReplicaFailure ), Status : metav1 .ConditionTrue })
1646
+ assert .True (t , r .inconsistentRayClusterStatus (ctx , oldStatus , * newStatus ))
1640
1647
}
1641
1648
1642
1649
func TestCalculateStatus (t * testing.T ) {
@@ -1687,6 +1694,17 @@ func TestCalculateStatus(t *testing.T) {
1687
1694
assert .Equal (t , headService .Name , newInstance .Status .Head .ServiceName )
1688
1695
assert .NotNil (t , newInstance .Status .StateTransitionTimes , "Cluster state transition timestamp should be created" )
1689
1696
assert .Equal (t , newInstance .Status .LastUpdateTime , newInstance .Status .StateTransitionTimes [rayv1 .Ready ])
1697
+
1698
+ // Test reconcilePodsErr with the feature gate disabled
1699
+ newInstance , err = r .calculateStatus (ctx , testRayCluster , reconcilePodsErr )
1700
+ assert .Nil (t , err )
1701
+ assert .Empty (t , newInstance .Status .Conditions )
1702
+
1703
+ // Test reconcilePodsErr with the feature gate enabled
1704
+ defer features .SetFeatureGateDuringTest (t , features .RayClusterStatusConditions , true )()
1705
+ newInstance , err = r .calculateStatus (ctx , testRayCluster , reconcilePodsErr )
1706
+ assert .Nil (t , err )
1707
+ assert .True (t , meta .IsStatusConditionPresentAndEqual (newInstance .Status .Conditions , string (rayv1 .RayClusterReplicaFailure ), metav1 .ConditionTrue ))
1690
1708
}
1691
1709
1692
1710
func TestStateTransitionTimes_NoStateChange (t * testing.T ) {
@@ -1808,7 +1826,7 @@ func Test_TerminatedWorkers_NoAutoscaler(t *testing.T) {
1808
1826
// Pods to be deleted, the controller won't create new worker Pods during the same reconcile loop. As a result, the number of worker
1809
1827
// Pods will be (expectedNumWorkerPods - 1) after the reconcile loop.
1810
1828
err = testRayClusterReconciler .reconcilePods (ctx , testRayCluster )
1811
- assert .NotNil (t , err )
1829
+ assert .ErrorIs (t , err , reconcilePodsErr )
1812
1830
err = fakeClient .List (ctx , & podList , & client.ListOptions {
1813
1831
LabelSelector : workerSelector ,
1814
1832
Namespace : namespaceStr ,
@@ -1848,7 +1866,7 @@ func Test_TerminatedWorkers_NoAutoscaler(t *testing.T) {
1848
1866
// Pods to be deleted, the controller won't create new worker Pods during the same reconcile loop. As a result, the number of worker
1849
1867
// Pods will be (expectedNumWorkerPods - 1) after the reconcile loop.
1850
1868
err = testRayClusterReconciler .reconcilePods (ctx , testRayCluster )
1851
- assert .NotNil (t , err )
1869
+ assert .ErrorIs (t , err , reconcilePodsErr )
1852
1870
err = fakeClient .List (ctx , & podList , & client.ListOptions {
1853
1871
LabelSelector : workerSelector ,
1854
1872
Namespace : namespaceStr ,
@@ -1927,7 +1945,7 @@ func Test_TerminatedHead_RestartPolicy(t *testing.T) {
1927
1945
// The head Pod will be deleted and the controller will return an error
1928
1946
// instead of creating a new head Pod in the same reconcile loop.
1929
1947
err = testRayClusterReconciler .reconcilePods (ctx , cluster )
1930
- assert .NotNil (t , err )
1948
+ assert .ErrorIs (t , err , reconcilePodsErr )
1931
1949
err = fakeClient .List (ctx , & podList , client .InNamespace (namespaceStr ))
1932
1950
assert .Nil (t , err , "Fail to get pod list" )
1933
1951
assert .Equal (t , 0 , len (podList .Items ))
@@ -1995,7 +2013,7 @@ func Test_RunningPods_RayContainerTerminated(t *testing.T) {
1995
2013
// The head Pod will be deleted and the controller will return an error
1996
2014
// instead of creating a new head Pod in the same reconcile loop.
1997
2015
err = testRayClusterReconciler .reconcilePods (ctx , cluster )
1998
- assert .NotNil (t , err )
2016
+ assert .ErrorIs (t , err , reconcilePodsErr )
1999
2017
err = fakeClient .List (ctx , & podList , client .InNamespace (namespaceStr ))
2000
2018
assert .Nil (t , err , "Fail to get pod list" )
2001
2019
assert .Equal (t , 0 , len (podList .Items ))
0 commit comments