Skip to content

Commit

Permalink
[Refactor][RayCluster] Delete unused functions
Browse files Browse the repository at this point in the history
Resolves: ray-project#2235
Signed-off-by: Chi-Sheng Liu <[email protected]>
  • Loading branch information
MortalHappiness committed Jul 17, 2024
1 parent 05946f6 commit 867c0e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
34 changes: 10 additions & 24 deletions ray-operator/controllers/ray/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,11 @@ func (r *RayClusterReconciler) rayClusterReconcile(ctx context.Context, request

// Calculate the new status for the RayCluster. Note that the function will deep copy `instance` instead of mutating it.
newInstance, calculateErr := r.calculateStatus(ctx, instance, reconcileErr)
var updateErr error
if calculateErr != nil {
logger.Info("Got error when calculating new status", "cluster name", request.Name, "error", calculateErr)
}

// Check if the status needs to be updated.
var updateErr error
if calculateErr == nil && r.inconsistentRayClusterStatus(ctx, originalRayClusterInstance.Status, newInstance.Status) {
logger.Info("rayClusterReconcile", "Update CR status", request.Name, "status", newInstance.Status)
updateErr = r.Status().Update(ctx, newInstance)
if updateErr != nil {
logger.Info("Got error when updating status", "cluster name", request.Name, "error", updateErr, "RayCluster", newInstance)
}
} else {
updateErr = r.updateRayClusterStatus(ctx, originalRayClusterInstance, newInstance)
}

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

func (r *RayClusterReconciler) updateClusterState(ctx context.Context, instance *rayv1.RayCluster, clusterState rayv1.ClusterState) error {
func (r *RayClusterReconciler) updateRayClusterStatus(ctx context.Context, originalRayClusterInstance, newInstance *rayv1.RayCluster) error {
logger := ctrl.LoggerFrom(ctx)
if instance.Status.State == clusterState {
if !r.inconsistentRayClusterStatus(ctx, originalRayClusterInstance.Status, newInstance.Status) {
return nil
}
instance.Status.State = clusterState
logger.Info("updateClusterState", "Update CR Status.State", clusterState)
return r.Status().Update(ctx, instance)
}

func (r *RayClusterReconciler) updateClusterReason(ctx context.Context, instance *rayv1.RayCluster, clusterReason string) error {
logger := ctrl.LoggerFrom(ctx)
if instance.Status.Reason == clusterReason {
return nil
logger.Info("updateRayClusterStatus", "name", originalRayClusterInstance.Name, "old status", originalRayClusterInstance.Status, "new status", newInstance.Status)
err := r.Status().Update(ctx, newInstance)
if err != nil {
logger.Info("Error updating status", "name", originalRayClusterInstance.Name, "error", err, "RayCluster", newInstance)
}
instance.Status.Reason = clusterReason
logger.Info("updateClusterReason", "Update CR Status.Reason", clusterReason)
return r.Status().Update(ctx, instance)
return err
}

// sumGPUs sums the GPUs in the given resource list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,9 @@ func TestReconcile_UpdateClusterReason(t *testing.T) {
}
reason := "test reason"

err = testRayClusterReconciler.updateClusterReason(ctx, testRayCluster, reason)
newTestRayCluster := testRayCluster.DeepCopy()
newTestRayCluster.Status.Reason = reason
err = testRayClusterReconciler.updateRayClusterStatus(ctx, testRayCluster, newTestRayCluster)
assert.Nil(t, err, "Fail to update cluster reason")

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

state := rayv1.Ready
err = testRayClusterReconciler.updateClusterState(ctx, testRayCluster, state)
newTestRayCluster := testRayCluster.DeepCopy()
newTestRayCluster.Status.State = state
err = testRayClusterReconciler.updateRayClusterStatus(ctx, testRayCluster, newTestRayCluster)
assert.Nil(t, err, "Fail to update cluster state")

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

0 comments on commit 867c0e8

Please sign in to comment.