Skip to content

Commit 0719b3a

Browse files
[Refactor][RayCluster] Update based on PR comments
Resolves: ray-project#2235 Signed-off-by: Chi-Sheng Liu <[email protected]>
1 parent 867c0e8 commit 0719b3a

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

ray-operator/controllers/ray/raycluster_controller.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"reflect"
8+
"runtime"
89
"strconv"
910
"strings"
1011
"time"
@@ -32,7 +33,7 @@ import (
3233
networkingv1 "k8s.io/api/networking/v1"
3334
"k8s.io/apimachinery/pkg/api/errors"
3435
"k8s.io/apimachinery/pkg/api/resource"
35-
"k8s.io/apimachinery/pkg/runtime"
36+
k8sruntime "k8s.io/apimachinery/pkg/runtime"
3637
ctrl "sigs.k8s.io/controller-runtime"
3738
"sigs.k8s.io/controller-runtime/pkg/builder"
3839
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -119,7 +120,7 @@ var _ reconcile.Reconciler = &RayClusterReconciler{}
119120
// RayClusterReconciler reconciles a RayCluster object
120121
type RayClusterReconciler struct {
121122
client.Client
122-
Scheme *runtime.Scheme
123+
Scheme *k8sruntime.Scheme
123124
Recorder record.EventRecorder
124125
BatchSchedulerMgr *batchscheduler.SchedulerManager
125126

@@ -306,26 +307,14 @@ func (r *RayClusterReconciler) rayClusterReconcile(ctx context.Context, request
306307
r.reconcileIngress,
307308
r.reconcileHeadService,
308309
r.reconcileHeadlessService,
309-
// reconcileServeService
310-
func(ctx context.Context, instance *rayv1.RayCluster) error {
311-
// Only reconcile the K8s service for Ray Serve when the "ray.io/enable-serve-service" annotation is set to true.
312-
if enableServeServiceValue, exist := instance.Annotations[utils.EnableServeServiceKey]; exist && enableServeServiceValue == utils.EnableServeServiceTrue {
313-
return r.reconcileServeService(ctx, instance)
314-
}
315-
return nil
316-
},
317-
// reconcilePods
318-
func(ctx context.Context, instance *rayv1.RayCluster) error {
319-
err := r.reconcilePods(ctx, instance)
320-
if err != nil {
321-
r.Recorder.Event(instance, corev1.EventTypeWarning, string(rayv1.PodReconciliationError), err.Error())
322-
}
323-
return err
324-
},
310+
r.reconcileServeService,
311+
r.reconcilePods,
325312
}
326313

327314
for _, fn := range reconcileFuncs {
328315
if reconcileErr = fn(ctx, instance); reconcileErr != nil {
316+
funcName := runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()
317+
logger.Error(reconcileErr, "Error reconcile resources", "function name", funcName)
329318
break
330319
}
331320
}
@@ -538,6 +527,11 @@ func (r *RayClusterReconciler) reconcileHeadService(ctx context.Context, instanc
538527

539528
// Return nil only when the serve service successfully created or already exists.
540529
func (r *RayClusterReconciler) reconcileServeService(ctx context.Context, instance *rayv1.RayCluster) error {
530+
// Only reconcile the K8s service for Ray Serve when the "ray.io/enable-serve-service" annotation is set to true.
531+
if enableServeServiceValue, exist := instance.Annotations[utils.EnableServeServiceKey]; !exist || enableServeServiceValue != utils.EnableServeServiceTrue {
532+
return nil
533+
}
534+
541535
// Retrieve the Service from the Kubernetes cluster with the name and namespace.
542536
svc := &corev1.Service{}
543537
err := r.Get(ctx, common.RayClusterServeServiceNamespacedName(instance), svc)

0 commit comments

Comments
 (0)