Skip to content

Commit

Permalink
fix: add clusterScope condition statement to service_controller suppo…
Browse files Browse the repository at this point in the history
…rting namespace-scoped mode properly

Signed-off-by: jooho <jlee@redhat.com>
  • Loading branch information
Jooho authored and ckadner committed Sep 28, 2023
1 parent 1773d7d commit e6eb949
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions controllers/service_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,25 +238,27 @@ func (r *ServiceReconciler) reconcileService(ctx context.Context, mms *mmesh.MMS
return nil, errors.New("unexpected state - MMService uninitialized"), false
}

sl := &corev1.ServiceList{}
if err := r.List(ctx, sl, client.HasLabels{"modelmesh-service"}, client.InNamespace(namespace)); err != nil {
return nil, err, false
if r.ClusterScope {
namespaceObj := &corev1.Namespace{}
// Get the namespace object to check label and state of the namespace
if err := r.Client.Get(ctx, types.NamespacedName{Name: namespace}, namespaceObj); err != nil {
return nil, err, false
}
// This will remove the goroutine when modelmesh is not enabled for a namespace.
// - when the namespace does not have the annotation modelmesh-enabled
// - when the namespace is under a Terminating state.
if !modelMeshEnabled(namespaceObj, r.ControllerDeployment.Namespace) {
r.ModelEventStream.RemoveWatchedService(serviceName, namespace)
r.Log.V(1).Info("Deleted Watched Service", "name", serviceName, "namespace", namespace)
return nil, nil, false
}
}

//This will remove the goroutine when modelmesh is not enabled for a namespace.
// - 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 {
sl := &corev1.ServiceList{}
if err := r.List(ctx, sl, client.HasLabels{"modelmesh-service"}, client.InNamespace(namespace)); err != nil {
return nil, err, false
}

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]
Expand Down

0 comments on commit e6eb949

Please sign in to comment.