@@ -266,21 +266,35 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
266
266
}
267
267
}
268
268
269
- // Locate the KubeRay operator deployment:
270
- // - First try to get the ODH / RHOAI application namespace from the DSCInitialization
271
- // - Or fallback to the well-known defaults
272
269
var kubeRayNamespaces []string
273
- dsci := & dsciv1.DSCInitialization {}
274
- err := r .Client .Get (ctx , client.ObjectKey {Name : "default-dsci" }, dsci )
275
- if errors .IsNotFound (err ) {
276
- kubeRayNamespaces = []string {"opendatahub" , "redhat-ods-applications" }
277
- } else if err != nil {
278
- return ctrl.Result {}, err
270
+ if r .IsOpenShift {
271
+ // Locate the KubeRay operator deployment:
272
+ // - First try to get the ODH / RHOAI application namespace from the DSCInitialization
273
+ // - Or fallback to the well-known defaults
274
+ dsci := & dsciv1.DSCInitialization {}
275
+
276
+ // TODO it wont find the dsci if it is named something else (which is entirely possible) - find it some other way
277
+ err := r .Client .Get (ctx , client.ObjectKey {Name : "default-dsci" }, dsci )
278
+ if err != nil {
279
+ return ctrl.Result {}, err
280
+ } else {
281
+ kubeRayNamespaces = []string {dsci .Spec .ApplicationsNamespace }
282
+ }
279
283
} else {
280
- kubeRayNamespaces = []string {dsci .Spec .ApplicationsNamespace }
284
+ var pods corev1.PodList
285
+ err := r .Client .List (ctx , & pods ,
286
+ client.MatchingLabels {"app.kubernetes.io/name" : "kuberay" },
287
+ )
288
+ if err != nil {
289
+ return ctrl.Result {}, err
290
+ }
291
+
292
+ for _ , pod := range pods .Items {
293
+ kubeRayNamespaces = []string {pod .Namespace }
294
+ }
281
295
}
282
296
283
- _ , err = r .kubeClient .NetworkingV1 ().NetworkPolicies (cluster .Namespace ).Apply (ctx , desiredHeadNetworkPolicy (cluster , r .Config , kubeRayNamespaces ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
297
+ _ , err : = r .kubeClient .NetworkingV1 ().NetworkPolicies (cluster .Namespace ).Apply (ctx , desiredHeadNetworkPolicy (cluster , r .Config , kubeRayNamespaces ), metav1.ApplyOptions {FieldManager : controllerName , Force : true })
284
298
if err != nil {
285
299
logger .Error (err , "Failed to update NetworkPolicy" )
286
300
}
0 commit comments