From b9a258c77553858a98ddf519dec89d0f78765d4d Mon Sep 17 00:00:00 2001 From: Saad Zaher Date: Thu, 27 Mar 2025 23:45:08 +0000 Subject: [PATCH 1/5] only use the applicationsNamespace in openshift the codeflare operator checks for kuberay namespaces to apply network policies so it uses opendatahub DSCInitialization CRD which isn't available on vanilla k8s clusters so added a condition to check for DSCInitialization only when running on openshift This fixes the gatejobs running the codeflare-sdk repo as the e2e test jobs are failing because DSCInitialization isn't available on kind cluster that is being used for testing. --- pkg/controllers/raycluster_controller.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/controllers/raycluster_controller.go b/pkg/controllers/raycluster_controller.go index 02c1a307d..842f6694f 100644 --- a/pkg/controllers/raycluster_controller.go +++ b/pkg/controllers/raycluster_controller.go @@ -269,18 +269,21 @@ 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{"opendatahub", "redhat-ods-applications"} + + if r.IsOpenShift { + dsci := &dsciv1.DSCInitialization{} + err := r.Client.Get(ctx, client.ObjectKey{Name: "default-dsci"}, dsci) + 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") } From 4d1fd3a274004774494e1b7b278aad887b311f15 Mon Sep 17 00:00:00 2001 From: Saad Zaher Date: Fri, 28 Mar 2025 12:30:16 +0000 Subject: [PATCH 2/5] use fallback namespaces if dsci cluster isn't found Signed-off-by: Saad Zaher --- pkg/controllers/raycluster_controller.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/controllers/raycluster_controller.go b/pkg/controllers/raycluster_controller.go index 842f6694f..28acc0ef4 100644 --- a/pkg/controllers/raycluster_controller.go +++ b/pkg/controllers/raycluster_controller.go @@ -271,16 +271,19 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) // - Or fallback to the well-known defaults // add check if running on openshift or vanilla kubernetes var kubeRayNamespaces []string - kubeRayNamespaces = []string{"opendatahub", "redhat-ods-applications"} + kubeRayNamespaces = []string{cluster.Namespace} if r.IsOpenShift { dsci := &dsciv1.DSCInitialization{} + err := r.Client.Get(ctx, client.ObjectKey{Name: "default-dsci"}, dsci) - if err != nil { + 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{dsci.Spec.ApplicationsNamespace} + } _, err := r.kubeClient.NetworkingV1().NetworkPolicies(cluster.Namespace).Apply(ctx, desiredHeadNetworkPolicy(cluster, r.Config, kubeRayNamespaces), metav1.ApplyOptions{FieldManager: controllerName, Force: true}) From 11466377037978e66365c330417b856a9ad58df5 Mon Sep 17 00:00:00 2001 From: Saad Zaher Date: Fri, 28 Mar 2025 15:33:25 +0000 Subject: [PATCH 3/5] only use default-dsci namespace when available Signed-off-by: Saad Zaher --- pkg/controllers/raycluster_controller.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/controllers/raycluster_controller.go b/pkg/controllers/raycluster_controller.go index 28acc0ef4..00ecf21a7 100644 --- a/pkg/controllers/raycluster_controller.go +++ b/pkg/controllers/raycluster_controller.go @@ -281,8 +281,9 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) kubeRayNamespaces = []string{"opendatahub", "redhat-ods-applications"} } else if err != nil { return ctrl.Result{}, err + } else { + kubeRayNamespaces = []string{dsci.Spec.ApplicationsNamespace} } - kubeRayNamespaces = []string{dsci.Spec.ApplicationsNamespace} } From c583416a6aefcd2cc9edbed6363ac0049d88ee38 Mon Sep 17 00:00:00 2001 From: Saad Zaher Date: Tue, 1 Apr 2025 13:53:19 +0100 Subject: [PATCH 4/5] use ray-system as default ray namespace Signed-off-by: Saad Zaher --- pkg/controllers/constants.go | 9 +++++++++ pkg/controllers/raycluster_controller.go | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 pkg/controllers/constants.go diff --git a/pkg/controllers/constants.go b/pkg/controllers/constants.go new file mode 100644 index 000000000..afb031437 --- /dev/null +++ b/pkg/controllers/constants.go @@ -0,0 +1,9 @@ +package controllers + +const ( + kubeRayDefaultNamespace = "ray-system" + kubeRayOperatorNamespace = "kuberay-operator" + defaultDSCINamespace = "default-dsci" + odhNamespace = "opendatahub" + rhdsAppsNamespace = "redhat-ods-applications" +) diff --git a/pkg/controllers/raycluster_controller.go b/pkg/controllers/raycluster_controller.go index 00ecf21a7..f22d24d43 100644 --- a/pkg/controllers/raycluster_controller.go +++ b/pkg/controllers/raycluster_controller.go @@ -271,14 +271,14 @@ func (r *RayClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) // - Or fallback to the well-known defaults // add check if running on openshift or vanilla kubernetes var kubeRayNamespaces []string - kubeRayNamespaces = []string{cluster.Namespace} + kubeRayNamespaces = []string{kubeRayDefaultNamespace} if r.IsOpenShift { dsci := &dsciv1.DSCInitialization{} - err := r.Client.Get(ctx, client.ObjectKey{Name: "default-dsci"}, dsci) + err := r.Client.Get(ctx, client.ObjectKey{Name: defaultDSCINamespace}, dsci) if errors.IsNotFound(err) { - kubeRayNamespaces = []string{"opendatahub", "redhat-ods-applications"} + kubeRayNamespaces = []string{odhNamespace, rhdsAppsNamespace} } else if err != nil { return ctrl.Result{}, err } else { @@ -557,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). From 8db15e76b70a7913dde4615312be5d8ad99d8c37 Mon Sep 17 00:00:00 2001 From: Saad Zaher Date: Tue, 1 Apr 2025 13:54:37 +0100 Subject: [PATCH 5/5] update copyrights for constants.go Signed-off-by: Saad Zaher --- pkg/controllers/constants.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/controllers/constants.go b/pkg/controllers/constants.go index afb031437..c7089c48c 100644 --- a/pkg/controllers/constants.go +++ b/pkg/controllers/constants.go @@ -1,3 +1,19 @@ +/* +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 (