Skip to content

Commit 4e76a50

Browse files
committed
RHOAIENG-22373: Fix incorrect default of RHOAI/ODH installation
1 parent c03f1b5 commit 4e76a50

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

pkg/controllers/raycluster_controller.go

+25-11
Original file line numberDiff line numberDiff line change
@@ -266,21 +266,35 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
266266
}
267267
}
268268

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
272269
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+
}
279283
} 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+
}
281295
}
282296

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})
284298
if err != nil {
285299
logger.Error(err, "Failed to update NetworkPolicy")
286300
}

0 commit comments

Comments
 (0)