Skip to content

Commit 5231dbf

Browse files
authored
[Feature][RayCluster]: Deprecate the RayCluster .Status.State field (#2288)
1 parent 2ac9c44 commit 5231dbf

File tree

8 files changed

+24
-19
lines changed

8 files changed

+24
-19
lines changed

ray-operator/apis/ray/v1/raycluster_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ type RayClusterStatus struct {
121121
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
122122
// Important: Run "make" to regenerate code after modifying this file
123123
// Status reflects the status of the cluster
124+
//
125+
// Deprecated: the State field is replaced by the Conditions field.
124126
State ClusterState `json:"state,omitempty"`
125127
// DesiredCPU indicates total desired CPUs for the cluster
126128
DesiredCPU resource.Quantity `json:"desiredCPU,omitempty"`

ray-operator/apis/ray/v1alpha1/raycluster_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ type RayClusterStatus struct {
133133
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
134134
// Important: Run "make" to regenerate code after modifying this file
135135
// Status reflects the status of the cluster
136+
//
137+
// Deprecated: the State field is replaced by the Conditions field.
136138
State ClusterState `json:"state,omitempty"`
137139
// Reason provides more information about current State
138140
Reason string `json:"reason,omitempty"`

ray-operator/controllers/ray/raycluster_controller.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,11 @@ func (r *RayClusterReconciler) rayClusterReconcile(ctx context.Context, request
364364
// this field should be used to determine whether to update this CR or not.
365365
func (r *RayClusterReconciler) inconsistentRayClusterStatus(ctx context.Context, oldStatus rayv1.RayClusterStatus, newStatus rayv1.RayClusterStatus) bool {
366366
logger := ctrl.LoggerFrom(ctx)
367-
if oldStatus.State != newStatus.State || oldStatus.Reason != newStatus.Reason {
367+
368+
if oldStatus.State != newStatus.State || oldStatus.Reason != newStatus.Reason { //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
368369
logger.Info("inconsistentRayClusterStatus", "detect inconsistency", fmt.Sprintf(
369370
"old State: %s, new State: %s, old Reason: %s, new Reason: %s",
370-
oldStatus.State, newStatus.State, oldStatus.Reason, newStatus.Reason))
371+
oldStatus.State, newStatus.State, oldStatus.Reason, newStatus.Reason)) //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
371372
return true
372373
}
373374
if oldStatus.ReadyWorkerReplicas != newStatus.ReadyWorkerReplicas ||
@@ -1199,7 +1200,7 @@ func (r *RayClusterReconciler) calculateStatus(ctx context.Context, instance *ra
11991200
newInstance.Status.DesiredTPU = totalResources[corev1.ResourceName("google.com/tpu")]
12001201

12011202
if utils.CheckAllPodsRunning(ctx, runtimePods) {
1202-
newInstance.Status.State = rayv1.Ready
1203+
newInstance.Status.State = rayv1.Ready //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
12031204
}
12041205

12051206
// Check if the head node is running and ready by checking the head pod's status.
@@ -1244,7 +1245,7 @@ func (r *RayClusterReconciler) calculateStatus(ctx context.Context, instance *ra
12441245
}
12451246

12461247
if newInstance.Spec.Suspend != nil && *newInstance.Spec.Suspend && len(runtimePods.Items) == 0 {
1247-
newInstance.Status.State = rayv1.Suspended
1248+
newInstance.Status.State = rayv1.Suspended //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
12481249
}
12491250

12501251
if err := r.updateEndpoints(ctx, newInstance); err != nil {
@@ -1258,11 +1259,11 @@ func (r *RayClusterReconciler) calculateStatus(ctx context.Context, instance *ra
12581259
timeNow := metav1.Now()
12591260
newInstance.Status.LastUpdateTime = &timeNow
12601261

1261-
if instance.Status.State != newInstance.Status.State {
1262+
if instance.Status.State != newInstance.Status.State { //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
12621263
if newInstance.Status.StateTransitionTimes == nil {
12631264
newInstance.Status.StateTransitionTimes = make(map[rayv1.ClusterState]*metav1.Time)
12641265
}
1265-
newInstance.Status.StateTransitionTimes[newInstance.Status.State] = &timeNow
1266+
newInstance.Status.StateTransitionTimes[newInstance.Status.State] = &timeNow //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
12661267
}
12671268

12681269
return newInstance, nil

ray-operator/controllers/ray/raycluster_controller_unit_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ func TestReconcile_UpdateClusterState(t *testing.T) {
15521552
cluster := rayv1.RayCluster{}
15531553
err := fakeClient.Get(ctx, namespacedName, &cluster)
15541554
assert.Nil(t, err, "Fail to get RayCluster")
1555-
assert.Empty(t, cluster.Status.State, "Cluster state should be empty")
1555+
assert.Empty(t, cluster.Status.State, "Cluster state should be empty") //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
15561556

15571557
testRayClusterReconciler := &RayClusterReconciler{
15581558
Client: fakeClient,
@@ -1562,13 +1562,13 @@ func TestReconcile_UpdateClusterState(t *testing.T) {
15621562

15631563
state := rayv1.Ready
15641564
newTestRayCluster := testRayCluster.DeepCopy()
1565-
newTestRayCluster.Status.State = state
1565+
newTestRayCluster.Status.State = state //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
15661566
err = testRayClusterReconciler.updateRayClusterStatus(ctx, testRayCluster, newTestRayCluster)
15671567
assert.Nil(t, err, "Fail to update cluster state")
15681568

15691569
err = fakeClient.Get(ctx, namespacedName, &cluster)
15701570
assert.Nil(t, err, "Fail to get RayCluster after updating state")
1571-
assert.Equal(t, cluster.Status.State, state, "Cluster state should be updated")
1571+
assert.Equal(t, cluster.Status.State, state, "Cluster state should be updated") //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
15721572
}
15731573

15741574
func TestInconsistentRayClusterStatus(t *testing.T) {
@@ -1612,7 +1612,7 @@ func TestInconsistentRayClusterStatus(t *testing.T) {
16121612

16131613
// Case 1: `State` is different => return true
16141614
newStatus := oldStatus.DeepCopy()
1615-
newStatus.State = rayv1.Suspended
1615+
newStatus.State = rayv1.Suspended //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
16161616
assert.True(t, r.inconsistentRayClusterStatus(ctx, oldStatus, *newStatus))
16171617

16181618
// Case 2: `Reason` is different => return true
@@ -1905,7 +1905,7 @@ func TestStateTransitionTimes_NoStateChange(t *testing.T) {
19051905
}
19061906

19071907
preUpdateTime := metav1.Now()
1908-
testRayCluster.Status.State = rayv1.Ready
1908+
testRayCluster.Status.State = rayv1.Ready //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
19091909
testRayCluster.Status.StateTransitionTimes = map[rayv1.ClusterState]*metav1.Time{rayv1.Ready: &preUpdateTime}
19101910
newInstance, err := r.calculateStatus(ctx, testRayCluster, nil)
19111911
assert.Nil(t, err)

ray-operator/controllers/ray/rayjob_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ func (r *RayJobReconciler) Reconcile(ctx context.Context, request ctrl.Request)
165165

166166
// Check the current status of RayCluster before submitting.
167167
if clientURL := rayJobInstance.Status.DashboardURL; clientURL == "" {
168-
if rayClusterInstance.Status.State != rayv1.Ready {
169-
logger.Info("Wait for the RayCluster.Status.State to be ready before submitting the job.", "RayCluster", rayClusterInstance.Name, "State", rayClusterInstance.Status.State)
168+
if rayClusterInstance.Status.State != rayv1.Ready { //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
169+
logger.Info("Wait for the RayCluster.Status.State to be ready before submitting the job.", "RayCluster", rayClusterInstance.Name, "State", rayClusterInstance.Status.State) //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
170170
return ctrl.Result{RequeueAfter: RayJobDefaultRequeueDuration}, err
171171
}
172172

ray-operator/controllers/ray/rayjob_controller_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ var _ = Context("RayJob in K8sJobMode", func() {
239239

240240
It("Make RayCluster.Status.State to be rayv1.Ready", func() {
241241
// The RayCluster is not 'Ready' yet because Pods are not running and ready.
242-
Expect(rayCluster.Status.State).NotTo(Equal(rayv1.Ready))
242+
Expect(rayCluster.Status.State).NotTo(Equal(rayv1.Ready)) //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
243243

244244
updateHeadPodToRunningAndReady(ctx, rayJob.Status.RayClusterName, namespace)
245245
updateWorkerPodsToRunningAndReady(ctx, rayJob.Status.RayClusterName, namespace)
@@ -364,7 +364,7 @@ var _ = Context("RayJob in K8sJobMode", func() {
364364

365365
It("Make RayCluster.Status.State to be rayv1.Ready", func() {
366366
// The RayCluster is not 'Ready' yet because Pods are not running and ready.
367-
Expect(rayCluster.Status.State).NotTo(Equal(rayv1.Ready))
367+
Expect(rayCluster.Status.State).NotTo(Equal(rayv1.Ready)) //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
368368

369369
updateHeadPodToRunningAndReady(ctx, rayJob.Status.RayClusterName, namespace)
370370
updateWorkerPodsToRunningAndReady(ctx, rayJob.Status.RayClusterName, namespace)
@@ -526,7 +526,7 @@ var _ = Context("RayJob in K8sJobMode", func() {
526526

527527
It("Make RayCluster.Status.State to be rayv1.Ready", func() {
528528
// The RayCluster is not 'Ready' yet because Pods are not running and ready.
529-
Expect(rayCluster.Status.State).NotTo(Equal(rayv1.Ready))
529+
Expect(rayCluster.Status.State).NotTo(Equal(rayv1.Ready)) //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
530530

531531
updateHeadPodToRunningAndReady(ctx, rayJob.Status.RayClusterName, namespace)
532532
updateWorkerPodsToRunningAndReady(ctx, rayJob.Status.RayClusterName, namespace)
@@ -619,7 +619,7 @@ var _ = Context("RayJob in K8sJobMode", func() {
619619

620620
It("Make RayCluster.Status.State to be rayv1.Ready (attempt 2)", func() {
621621
// The RayCluster is not 'Ready' yet because Pods are not running and ready.
622-
Expect(rayCluster.Status.State).NotTo(Equal(rayv1.Ready))
622+
Expect(rayCluster.Status.State).NotTo(Equal(rayv1.Ready)) //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
623623

624624
updateHeadPodToRunningAndReady(ctx, rayJob.Status.RayClusterName, namespace)
625625
updateWorkerPodsToRunningAndReady(ctx, rayJob.Status.RayClusterName, namespace)

ray-operator/controllers/ray/suite_helpers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func getClusterState(ctx context.Context, namespace string, clusterName string)
4646
if err := k8sClient.Get(ctx, client.ObjectKey{Namespace: namespace, Name: clusterName}, &cluster); err != nil {
4747
log.Fatal(err)
4848
}
49-
return cluster.Status.State
49+
return cluster.Status.State //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
5050
}
5151
}
5252

ray-operator/test/support/ray.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func GetRayCluster(t Test, namespace, name string) *rayv1.RayCluster {
7575
}
7676

7777
func RayClusterState(cluster *rayv1.RayCluster) rayv1.ClusterState {
78-
return cluster.Status.State
78+
return cluster.Status.State //nolint:staticcheck // https://github.com/ray-project/kuberay/pull/2288
7979
}
8080

8181
func RayClusterDesiredWorkerReplicas(cluster *rayv1.RayCluster) int32 {

0 commit comments

Comments
 (0)