From 0a32d289ed8464b6aad3949ada1a8b5e91ff0b1d Mon Sep 17 00:00:00 2001 From: jooho Date: Tue, 26 Sep 2023 22:58:44 -0400 Subject: [PATCH] fix: add clusterScope condition statement to service_controller supporting namespace-scoped mode properly Signed-off-by: jooho --- controllers/service_controller.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/controllers/service_controller.go b/controllers/service_controller.go index 54e7be562..95e0bdb08 100644 --- a/controllers/service_controller.go +++ b/controllers/service_controller.go @@ -247,16 +247,23 @@ func (r *ServiceReconciler) reconcileService(ctx context.Context, mms *mmesh.MMS // - when the namespace does not have the annotation modelmesh-enabled // - when the namespace is under a Terminating state. n := &corev1.Namespace{} - if err := r.Client.Get(ctx, types.NamespacedName{Name: namespace}, n); err != nil { - return nil, err, false + if r.ClusterScope { + if err := r.Client.Get(ctx, types.NamespacedName{Name: namespace}, n); err != nil { + return nil, err, false + } + } else { + n = &corev1.Namespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: namespace, + }, + } } - if !modelMeshEnabled(n, r.ControllerDeployment.Namespace) { r.ModelEventStream.RemoveWatchedService(serviceName, namespace) r.Log.Info("Deleted Watched Service", "name", serviceName, "namespace", namespace) return nil, nil, false } - + var s *corev1.Service for i := range sl.Items { ss := &sl.Items[i]