@@ -41,6 +41,8 @@ import (
41
41
routev1 "github.com/openshift/api/route/v1"
42
42
routeapply "github.com/openshift/client-go/route/applyconfigurations/route/v1"
43
43
routev1client "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
44
+
45
+ "github.com/project-codeflare/codeflare-operator/pkg/config"
44
46
)
45
47
46
48
// RayClusterReconciler reconciles a RayCluster object
@@ -50,15 +52,17 @@ type RayClusterReconciler struct {
50
52
routeClient * routev1client.RouteV1Client
51
53
Scheme * runtime.Scheme
52
54
CookieSalt string
55
+ Config * config.CodeFlareOperatorConfiguration
53
56
}
54
57
55
58
const (
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"
62
66
)
63
67
64
68
var (
@@ -97,6 +101,10 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
97
101
return ctrl.Result {}, client .IgnoreNotFound (err )
98
102
}
99
103
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
+
100
108
if cluster .ObjectMeta .DeletionTimestamp .IsZero () {
101
109
if ! controllerutil .ContainsFinalizer (& cluster , oAuthFinalizer ) {
102
110
logger .Info ("Add a finalizer" , "finalizer" , oAuthFinalizer )
@@ -130,29 +138,63 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
130
138
return ctrl.Result {}, nil
131
139
}
132
140
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
+ }
137
148
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
+ }
142
154
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
+ }
147
160
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
+ }
152
166
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
+ }
156
198
}
157
199
158
200
return ctrl.Result {}, nil
@@ -193,19 +235,23 @@ func desiredServiceAccount(cluster *rayv1.RayCluster) *coreapply.ServiceAccountA
193
235
WithAnnotations (map [string ]string {
194
236
"serviceaccounts.openshift.io/oauth-redirectreference.first" : "" +
195
237
`{"kind":"OAuthRedirectReference","apiVersion":"v1",` +
196
- `"reference":{"kind":"Route","name":"` + routeNameFromCluster (cluster ) + `"}}` ,
238
+ `"reference":{"kind":"Route","name":"` + dashboardNameFromCluster (cluster ) + `"}}` ,
197
239
}).
198
240
WithOwnerReferences (
199
241
v1 .OwnerReference ().WithUID (cluster .UID ).WithName (cluster .Name ).WithKind (cluster .Kind ).WithAPIVersion (cluster .APIVersion ),
200
242
)
201
243
}
202
244
203
- func routeNameFromCluster (cluster * rayv1.RayCluster ) string {
245
+ func dashboardNameFromCluster (cluster * rayv1.RayCluster ) string {
204
246
return "ray-dashboard-" + cluster .Name
205
247
}
206
248
249
+ func rayClientNameFromCluster (cluster * rayv1.RayCluster ) string {
250
+ return "rayclient-" + cluster .Name
251
+ }
252
+
207
253
func desiredClusterRoute (cluster * rayv1.RayCluster ) * routeapply.RouteApplyConfiguration {
208
- return routeapply .Route (routeNameFromCluster (cluster ), cluster .Namespace ).
254
+ return routeapply .Route (dashboardNameFromCluster (cluster ), cluster .Namespace ).
209
255
WithLabels (map [string ]string {"ray.io/cluster-name" : cluster .Name }).
210
256
WithSpec (routeapply .RouteSpec ().
211
257
WithTo (routeapply .RouteTargetReference ().WithKind ("Service" ).WithName (oauthServiceNameFromCluster (cluster ))).
0 commit comments