@@ -41,6 +41,8 @@ import (
4141 routev1 "github.com/openshift/api/route/v1"
4242 routeapply "github.com/openshift/client-go/route/applyconfigurations/route/v1"
4343 routev1client "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
44+
45+ "github.com/project-codeflare/codeflare-operator/pkg/config"
4446)
4547
4648// RayClusterReconciler reconciles a RayCluster object
@@ -50,15 +52,17 @@ type RayClusterReconciler struct {
5052 routeClient * routev1client.RouteV1Client
5153 Scheme * runtime.Scheme
5254 CookieSalt string
55+ Config * config.CodeFlareOperatorConfiguration
5356}
5457
5558const (
56- requeueTime = 10
57- controllerName = "codeflare-raycluster-controller"
58- oAuthFinalizer = "ray.openshift.ai/oauth-finalizer"
59- oAuthServicePort = 443
60- oAuthServicePortName = "oauth-proxy"
61- logRequeueing = "requeueing"
59+ requeueTime = 10
60+ controllerName = "codeflare-raycluster-controller"
61+ oAuthFinalizer = "ray.openshift.ai/oauth-finalizer"
62+ oAuthServicePort = 443
63+ oAuthServicePortName = "oauth-proxy"
64+ ingressServicePortName = "dashboard"
65+ logRequeueing = "requeueing"
6266)
6367
6468var (
@@ -97,6 +101,10 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
97101 return ctrl.Result {}, client .IgnoreNotFound (err )
98102 }
99103
104+ isLocalInteractive := annotationBoolVal (ctx , & cluster , "sdk.codeflare.dev/local_interactive" , false )
105+ ingressDomain := "" // FIX - CFO will retrieve it.
106+ isOpenShift , ingressHost := getClusterType (ctx , r .kubeClient , & cluster , ingressDomain )
107+
100108 if cluster .ObjectMeta .DeletionTimestamp .IsZero () {
101109 if ! controllerutil .ContainsFinalizer (& cluster , oAuthFinalizer ) {
102110 logger .Info ("Add a finalizer" , "finalizer" , oAuthFinalizer )
@@ -130,29 +138,63 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
130138 return ctrl.Result {}, nil
131139 }
132140
133- _ , err := r .routeClient .Routes (cluster .Namespace ).Apply (ctx , desiredClusterRoute (& cluster ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
134- if err != nil {
135- logger .Error (err , "Failed to update OAuth Route" )
136- }
141+ if cluster .Status .State != "suspended" && r .isRayDashboardOAuthEnabled () && isOpenShift {
142+ logger .Info ("Creating OAuth Objects" )
143+ _ , err := r .routeClient .Routes (cluster .Namespace ).Apply (ctx , desiredClusterRoute (& cluster ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
144+ if err != nil {
145+ logger .Error (err , "Failed to update OAuth Route" )
146+ return ctrl.Result {RequeueAfter : requeueTime }, err
147+ }
137148
138- _ , err = r .kubeClient .CoreV1 ().Secrets (cluster .Namespace ).Apply (ctx , desiredOAuthSecret (& cluster , r ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
139- if err != nil {
140- logger .Error (err , "Failed to create OAuth Secret" )
141- }
149+ _ , err = r .kubeClient .CoreV1 ().Secrets (cluster .Namespace ).Apply (ctx , desiredOAuthSecret (& cluster , r ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
150+ if err != nil {
151+ logger .Error (err , "Failed to create OAuth Secret" )
152+ return ctrl.Result {RequeueAfter : requeueTime }, err
153+ }
142154
143- _ , err = r .kubeClient .CoreV1 ().Services (cluster .Namespace ).Apply (ctx , desiredOAuthService (& cluster ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
144- if err != nil {
145- logger .Error (err , "Failed to update OAuth Service" )
146- }
155+ _ , err = r .kubeClient .CoreV1 ().Services (cluster .Namespace ).Apply (ctx , desiredOAuthService (& cluster ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
156+ if err != nil {
157+ logger .Error (err , "Failed to update OAuth Service" )
158+ return ctrl.Result {RequeueAfter : requeueTime }, err
159+ }
147160
148- _ , err = r .kubeClient .CoreV1 ().ServiceAccounts (cluster .Namespace ).Apply (ctx , desiredServiceAccount (& cluster ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
149- if err != nil {
150- logger .Error (err , "Failed to update OAuth ServiceAccount" )
151- }
161+ _ , err = r .kubeClient .CoreV1 ().ServiceAccounts (cluster .Namespace ).Apply (ctx , desiredServiceAccount (& cluster ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
162+ if err != nil {
163+ logger .Error (err , "Failed to update OAuth ServiceAccount" )
164+ return ctrl.Result {RequeueAfter : requeueTime }, err
165+ }
152166
153- _ , err = r .kubeClient .RbacV1 ().ClusterRoleBindings ().Apply (ctx , desiredOAuthClusterRoleBinding (& cluster ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
154- if err != nil {
155- logger .Error (err , "Failed to update OAuth ClusterRoleBinding" )
167+ _ , err = r .kubeClient .RbacV1 ().ClusterRoleBindings ().Apply (ctx , desiredOAuthClusterRoleBinding (& cluster ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
168+ if err != nil {
169+ logger .Error (err , "Failed to update OAuth ClusterRoleBinding" )
170+ return ctrl.Result {RequeueAfter : requeueTime }, err
171+ }
172+
173+ if isLocalInteractive {
174+ logger .Info ("Creating RayClient Route" )
175+ _ , err := r .routeClient .Routes (cluster .Namespace ).Apply (ctx , desiredRayClientRoute (& cluster ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
176+ if err != nil {
177+ logger .Error (err , "Failed to update RayClient Route" )
178+ return ctrl.Result {RequeueAfter : requeueTime }, err
179+ }
180+ }
181+
182+ } else if cluster .Status .State != "suspended" && ! r .isRayDashboardOAuthEnabled () && ! isOpenShift {
183+ logger .Info ("Creating Dashboard Ingress" )
184+ _ , err := r .kubeClient .NetworkingV1 ().Ingresses (cluster .Namespace ).Apply (ctx , desiredClusterIngress (& cluster , ingressHost ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
185+ if err != nil {
186+ // This log is info level since errors are not fatal and are expected
187+ logger .Info ("WARN: Failed to update Dashboard Ingress" , "error" , err .Error (), logRequeueing , true )
188+ return ctrl.Result {RequeueAfter : requeueTime }, err
189+ }
190+ if isLocalInteractive && ingressDomain != "" {
191+ logger .Info ("Creating RayClient Ingress" )
192+ _ , err := r .kubeClient .NetworkingV1 ().Ingresses (cluster .Namespace ).Apply (ctx , desiredRayClientIngress (& cluster , ingressDomain ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
193+ if err != nil {
194+ logger .Error (err , "Failed to update RayClient Ingress" )
195+ return ctrl.Result {RequeueAfter : requeueTime }, err
196+ }
197+ }
156198 }
157199
158200 return ctrl.Result {}, nil
@@ -193,19 +235,23 @@ func desiredServiceAccount(cluster *rayv1.RayCluster) *coreapply.ServiceAccountA
193235 WithAnnotations (map [string ]string {
194236 "serviceaccounts.openshift.io/oauth-redirectreference.first" : "" +
195237 `{"kind":"OAuthRedirectReference","apiVersion":"v1",` +
196- `"reference":{"kind":"Route","name":"` + routeNameFromCluster (cluster ) + `"}}` ,
238+ `"reference":{"kind":"Route","name":"` + dashboardNameFromCluster (cluster ) + `"}}` ,
197239 }).
198240 WithOwnerReferences (
199241 v1 .OwnerReference ().WithUID (cluster .UID ).WithName (cluster .Name ).WithKind (cluster .Kind ).WithAPIVersion (cluster .APIVersion ),
200242 )
201243}
202244
203- func routeNameFromCluster (cluster * rayv1.RayCluster ) string {
245+ func dashboardNameFromCluster (cluster * rayv1.RayCluster ) string {
204246 return "ray-dashboard-" + cluster .Name
205247}
206248
249+ func rayClientNameFromCluster (cluster * rayv1.RayCluster ) string {
250+ return "rayclient-" + cluster .Name
251+ }
252+
207253func desiredClusterRoute (cluster * rayv1.RayCluster ) * routeapply.RouteApplyConfiguration {
208- return routeapply .Route (routeNameFromCluster (cluster ), cluster .Namespace ).
254+ return routeapply .Route (dashboardNameFromCluster (cluster ), cluster .Namespace ).
209255 WithLabels (map [string ]string {"ray.io/cluster-name" : cluster .Name }).
210256 WithSpec (routeapply .RouteSpec ().
211257 WithTo (routeapply .RouteTargetReference ().WithKind ("Service" ).WithName (oauthServiceNameFromCluster (cluster ))).
0 commit comments