Skip to content
Merged
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions pkg/controllers/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright 2025.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers

const (
kubeRayDefaultNamespace = "ray-system"
kubeRayOperatorNamespace = "kuberay-operator"
defaultDSCINamespace = "default-dsci"
odhNamespace = "opendatahub"
rhdsAppsNamespace = "redhat-ods-applications"
)
27 changes: 17 additions & 10 deletions pkg/controllers/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,25 @@ 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
// add check if running on openshift or vanilla kubernetes
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
} else {
kubeRayNamespaces = []string{dsci.Spec.ApplicationsNamespace}
kubeRayNamespaces = []string{kubeRayDefaultNamespace}

if r.IsOpenShift {
dsci := &dsciv1.DSCInitialization{}

err := r.Client.Get(ctx, client.ObjectKey{Name: defaultDSCINamespace}, dsci)
if errors.IsNotFound(err) {
kubeRayNamespaces = []string{odhNamespace, rhdsAppsNamespace}
} else if err != nil {
return ctrl.Result{}, err
} else {
kubeRayNamespaces = []string{dsci.Spec.ApplicationsNamespace}
}

}

_, 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 Expand Up @@ -550,7 +557,7 @@ func desiredHeadNetworkPolicy(cluster *rayv1.RayCluster, cfg *config.KubeRayConf
networkingv1ac.NetworkPolicyIngressRule().
WithFrom(
networkingv1ac.NetworkPolicyPeer().WithPodSelector(metav1ac.LabelSelector().
WithMatchLabels(map[string]string{"app.kubernetes.io/component": "kuberay-operator"})).
WithMatchLabels(map[string]string{"app.kubernetes.io/component": kubeRayOperatorNamespace})).
WithNamespaceSelector(metav1ac.LabelSelector().
WithMatchExpressions(metav1ac.LabelSelectorRequirement().
WithKey(corev1.LabelMetadataName).
Expand Down
Loading