Skip to content

Commit 867c0e8

Browse files
[Refactor][RayCluster] Delete unused functions
Resolves: ray-project#2235 Signed-off-by: Chi-Sheng Liu <[email protected]>
1 parent 05946f6 commit 867c0e8

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

ray-operator/controllers/ray/raycluster_controller.go

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,11 @@ func (r *RayClusterReconciler) rayClusterReconcile(ctx context.Context, request
332332

333333
// Calculate the new status for the RayCluster. Note that the function will deep copy `instance` instead of mutating it.
334334
newInstance, calculateErr := r.calculateStatus(ctx, instance, reconcileErr)
335+
var updateErr error
335336
if calculateErr != nil {
336337
logger.Info("Got error when calculating new status", "cluster name", request.Name, "error", calculateErr)
337-
}
338-
339-
// Check if the status needs to be updated.
340-
var updateErr error
341-
if calculateErr == nil && r.inconsistentRayClusterStatus(ctx, originalRayClusterInstance.Status, newInstance.Status) {
342-
logger.Info("rayClusterReconcile", "Update CR status", request.Name, "status", newInstance.Status)
343-
updateErr = r.Status().Update(ctx, newInstance)
344-
if updateErr != nil {
345-
logger.Info("Got error when updating status", "cluster name", request.Name, "error", updateErr, "RayCluster", newInstance)
346-
}
338+
} else {
339+
updateErr = r.updateRayClusterStatus(ctx, originalRayClusterInstance, newInstance)
347340
}
348341

349342
// Return error based on order.
@@ -1451,24 +1444,17 @@ func (r *RayClusterReconciler) reconcileAutoscalerRoleBinding(ctx context.Contex
14511444
return nil
14521445
}
14531446

1454-
func (r *RayClusterReconciler) updateClusterState(ctx context.Context, instance *rayv1.RayCluster, clusterState rayv1.ClusterState) error {
1447+
func (r *RayClusterReconciler) updateRayClusterStatus(ctx context.Context, originalRayClusterInstance, newInstance *rayv1.RayCluster) error {
14551448
logger := ctrl.LoggerFrom(ctx)
1456-
if instance.Status.State == clusterState {
1449+
if !r.inconsistentRayClusterStatus(ctx, originalRayClusterInstance.Status, newInstance.Status) {
14571450
return nil
14581451
}
1459-
instance.Status.State = clusterState
1460-
logger.Info("updateClusterState", "Update CR Status.State", clusterState)
1461-
return r.Status().Update(ctx, instance)
1462-
}
1463-
1464-
func (r *RayClusterReconciler) updateClusterReason(ctx context.Context, instance *rayv1.RayCluster, clusterReason string) error {
1465-
logger := ctrl.LoggerFrom(ctx)
1466-
if instance.Status.Reason == clusterReason {
1467-
return nil
1452+
logger.Info("updateRayClusterStatus", "name", originalRayClusterInstance.Name, "old status", originalRayClusterInstance.Status, "new status", newInstance.Status)
1453+
err := r.Status().Update(ctx, newInstance)
1454+
if err != nil {
1455+
logger.Info("Error updating status", "name", originalRayClusterInstance.Name, "error", err, "RayCluster", newInstance)
14681456
}
1469-
instance.Status.Reason = clusterReason
1470-
logger.Info("updateClusterReason", "Update CR Status.Reason", clusterReason)
1471-
return r.Status().Update(ctx, instance)
1457+
return err
14721458
}
14731459

14741460
// sumGPUs sums the GPUs in the given resource list.

ray-operator/controllers/ray/raycluster_controller_unit_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,9 @@ func TestReconcile_UpdateClusterReason(t *testing.T) {
12571257
}
12581258
reason := "test reason"
12591259

1260-
err = testRayClusterReconciler.updateClusterReason(ctx, testRayCluster, reason)
1260+
newTestRayCluster := testRayCluster.DeepCopy()
1261+
newTestRayCluster.Status.Reason = reason
1262+
err = testRayClusterReconciler.updateRayClusterStatus(ctx, testRayCluster, newTestRayCluster)
12611263
assert.Nil(t, err, "Fail to update cluster reason")
12621264

12631265
err = fakeClient.Get(ctx, namespacedName, &cluster)
@@ -1532,7 +1534,9 @@ func TestReconcile_UpdateClusterState(t *testing.T) {
15321534
}
15331535

15341536
state := rayv1.Ready
1535-
err = testRayClusterReconciler.updateClusterState(ctx, testRayCluster, state)
1537+
newTestRayCluster := testRayCluster.DeepCopy()
1538+
newTestRayCluster.Status.State = state
1539+
err = testRayClusterReconciler.updateRayClusterStatus(ctx, testRayCluster, newTestRayCluster)
15361540
assert.Nil(t, err, "Fail to update cluster state")
15371541

15381542
err = fakeClient.Get(ctx, namespacedName, &cluster)

0 commit comments

Comments
 (0)