Skip to content

Commit 5b8e9c6

Browse files
authored
[RayService] Refactor createRayClusterInstance (#2874)
Signed-off-by: kaihsun <[email protected]>
1 parent 5a5534f commit 5b8e9c6

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed

ray-operator/controllers/ray/rayservice_controller.go

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -732,48 +732,21 @@ func (r *RayServiceReconciler) updateRayClusterInstance(ctx context.Context, ray
732732
return err
733733
}
734734

735-
// createRayClusterInstance deletes the old RayCluster instance if exists. Only when no existing RayCluster, create a new RayCluster instance.
736-
// One important part is that if this method deletes the old RayCluster, it will return instantly. It depends on the controller to call it again to generate the new RayCluster instance.
737735
func (r *RayServiceReconciler) createRayClusterInstance(ctx context.Context, rayServiceInstance *rayv1.RayService) (*rayv1.RayCluster, error) {
738736
logger := ctrl.LoggerFrom(ctx)
739737
rayClusterKey := common.RayServicePendingRayClusterNamespacedName(rayServiceInstance)
738+
logger.Info("createRayClusterInstance", "clusterName", rayClusterKey.Name)
740739

741-
logger.Info("createRayClusterInstance", "rayClusterInstanceName", rayClusterKey.Name)
742-
743-
rayClusterInstance := &rayv1.RayCluster{}
744-
745-
var err error
746-
// Loop until there is no pending RayCluster.
747-
err = r.Get(ctx, rayClusterKey, rayClusterInstance)
748-
749-
// If RayCluster exists, it means the config is updated. Delete the previous RayCluster first.
750-
if err == nil {
751-
logger.Info("Ray cluster already exists, config changes. Need to recreate. Delete the pending one now.", "key", rayClusterKey.String(), "rayClusterInstance.Spec", rayClusterInstance.Spec, "rayServiceInstance.Spec.RayClusterSpec", rayServiceInstance.Spec.RayClusterSpec)
752-
delErr := r.Delete(ctx, rayClusterInstance, client.PropagationPolicy(metav1.DeletePropagationBackground))
753-
if delErr == nil {
754-
r.Recorder.Eventf(rayServiceInstance, corev1.EventTypeNormal, string(utils.DeletedRayCluster), "Deleted the RayCluster %s/%s", rayClusterInstance.Namespace, rayClusterInstance.Name)
755-
// Go to next loop and check if the ray cluster is deleted.
756-
return nil, nil
757-
} else if !errors.IsNotFound(delErr) {
758-
r.Recorder.Eventf(rayServiceInstance, corev1.EventTypeWarning, string(utils.FailedToDeleteRayCluster), "Failed to delete the RayCluster %s/%s: %v", rayClusterInstance.Namespace, rayClusterInstance.Name, delErr)
759-
return nil, delErr
760-
}
761-
// if error is `not found`, then continue.
762-
} else if !errors.IsNotFound(err) {
763-
return nil, err
764-
// if error is `not found`, then continue.
765-
}
766-
767-
logger.Info("No pending RayCluster, creating RayCluster.")
768-
rayClusterInstance, err = constructRayClusterForRayService(rayServiceInstance, rayClusterKey.Name, r.Scheme)
740+
rayClusterInstance, err := constructRayClusterForRayService(rayServiceInstance, rayClusterKey.Name, r.Scheme)
769741
if err != nil {
770742
return nil, err
771743
}
772744
if err = r.Create(ctx, rayClusterInstance); err != nil {
745+
logger.Error(err, "Failed to create the RayCluster")
773746
r.Recorder.Eventf(rayServiceInstance, corev1.EventTypeWarning, string(utils.FailedToCreateRayCluster), "Failed to create the RayCluster %s/%s: %v", rayClusterInstance.Namespace, rayClusterInstance.Name, err)
774747
return nil, err
775748
}
776-
logger.Info("created rayCluster for rayService", "rayCluster", rayClusterInstance)
749+
logger.Info("Created RayCluster for RayService", "clusterName", rayClusterInstance.Name)
777750
r.Recorder.Eventf(rayServiceInstance, corev1.EventTypeNormal, string(utils.CreatedRayCluster), "Created the RayCluster %s/%s", rayClusterInstance.Namespace, rayClusterInstance.Name)
778751
return rayClusterInstance, nil
779752
}

0 commit comments

Comments
 (0)