Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions pkg/controllers/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,21 +266,35 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}
}

// Locate the KubeRay operator deployment:
// - First try to get the ODH / RHOAI application namespace from the DSCInitialization
// - Or fallback to the well-known defaults
var kubeRayNamespaces []string
dsci := &dsciv1.DSCInitialization{}
err := r.Client.Get(ctx, client.ObjectKey{Name: "default-dsci"}, dsci)
if errors.IsNotFound(err) {
kubeRayNamespaces = []string{"opendatahub", "redhat-ods-applications"}
} else if err != nil {
return ctrl.Result{}, err
if r.IsOpenShift {
// Locate the KubeRay operator deployment:
// - First try to get the ODH / RHOAI application namespace from the DSCInitialization
// - Or fallback to the well-known defaults
dsci := &dsciv1.DSCInitialization{}

// TODO it wont find the dsci if it is named something else (which is entirely possible) - find it some other way
err := r.Client.Get(ctx, client.ObjectKey{Name: "default-dsci"}, dsci)
if err != nil {
return ctrl.Result{}, err
} else {
kubeRayNamespaces = []string{dsci.Spec.ApplicationsNamespace}
}
} else {
kubeRayNamespaces = []string{dsci.Spec.ApplicationsNamespace}
var pods corev1.PodList
err := r.Client.List(ctx, &pods,
client.MatchingLabels{"app.kubernetes.io/name": "kuberay"},
)
if err != nil {
return ctrl.Result{}, err
}

for _, pod := range pods.Items {
kubeRayNamespaces = []string{pod.Namespace}
}
}

_, err = r.kubeClient.NetworkingV1().NetworkPolicies(cluster.Namespace).Apply(ctx, desiredHeadNetworkPolicy(cluster, r.Config, kubeRayNamespaces), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
_, err := r.kubeClient.NetworkingV1().NetworkPolicies(cluster.Namespace).Apply(ctx, desiredHeadNetworkPolicy(cluster, r.Config, kubeRayNamespaces), metav1.ApplyOptions{FieldManager: controllerName, Force: true})
if err != nil {
logger.Error(err, "Failed to update NetworkPolicy")
}
Expand Down
Loading